summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnna Sztukowska <anna.sztukowska@intel.com>2024-09-03 13:01:04 +0200
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-09-27 11:09:11 +0200
commit344690313ae4e66f760b14afafda663ec750dfe0 (patch)
tree550fe5257c6981a706f880a5e136c1374411bb81
parentsysfs: add function for writing to sysfs fd (diff)
downloadmdadm-344690313ae4e66f760b14afafda663ec750dfe0.tar.xz
mdadm-344690313ae4e66f760b14afafda663ec750dfe0.zip
Mdmonitor: Fix startup with missing directory
Commit 0a07dea8d3b78 ("Mdmonitor: Refactor check_one_sharer() for better error handling") introduced an issue, if directory /run/mdadm is missing, monitor fails to start. Move the directory creation earlier to ensure it is always created. Signed-off-by: Anna Sztukowska <anna.sztukowska@intel.com>
-rw-r--r--Monitor.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/Monitor.c b/Monitor.c
index cf14fbb3..d260b0f1 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -225,6 +225,11 @@ int Monitor(struct mddev_dev *devlist,
return 1;
}
+ if (mkdir(MDMON_DIR, 0700) < 0 && errno != EEXIST) {
+ pr_err("Failed to create directory " MDMON_DIR ": %s\n", strerror(errno));
+ return 1;
+ }
+
if (share){
if (check_one_sharer(c->scan) == 2)
return 1;
@@ -432,12 +437,12 @@ static int make_daemon(char *pidfile)
}
/*
- * check_one_sharer() - Checks for other mdmon processes running.
+ * check_one_sharer() - Checks for other mdmonitor processes running.
*
* Return:
* 0 - no other processes running,
* 1 - warning,
- * 2 - error, or when scan mode is enabled, and one mdmon process already exists
+ * 2 - error, or when scan mode is enabled, and one mdmonitor process already exists
*/
static int check_one_sharer(int scan)
{
@@ -513,11 +518,6 @@ static int write_autorebuild_pid(void)
FILE *fp;
int fd;
- if (mkdir(MDMON_DIR, 0700) < 0 && errno != EEXIST) {
- pr_err("%s: %s\n", strerror(errno), MDMON_DIR);
- return 1;
- }
-
if (!is_directory(MDMON_DIR)) {
pr_err("%s is not a regular directory.\n", MDMON_DIR);
return 1;