]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdmon.c
mapfile: if we putting the mapfile in a custom location via ALT_RUN, allow
[thirdparty/mdadm.git] / mdmon.c
diff --git a/mdmon.c b/mdmon.c
index ef1872acec85565f8b4b7395116387447c240a83..69c320e66da27e683759307bb8a0047afce2da38 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -120,7 +120,7 @@ static int make_pidfile(char *devname)
        int fd;
        int n;
 
-       if (mkdir(pid_dir, 0600) < 0 &&
+       if (mkdir(pid_dir, 0700) < 0 &&
            errno != EEXIST)
                return -errno;
        sprintf(path, "%s/%s.pid", pid_dir, devname);
@@ -445,26 +445,23 @@ static int mdmon(char *devname, int devnum, int must_fork, int takeover)
        act.sa_handler = SIG_IGN;
        sigaction(SIGPIPE, &act, NULL);
 
-       if (takeover) {
-               pid_dir = VAR_RUN;
+       pid_dir = VAR_RUN;
+       victim = mdmon_pid(container->devnum);
+       if (victim < 0) {
+               pid_dir = ALT_RUN;
                victim = mdmon_pid(container->devnum);
-               if (victim < 0) {
-                       pid_dir = ALT_RUN;
-                       victim = mdmon_pid(container->devnum);
-               }
-               if (victim >= 0)
-                       victim_sock = connect_monitor(container->devname);
        }
+       if (victim >= 0)
+               victim_sock = connect_monitor(container->devname);
 
        ignore = chdir("/");
-       if (victim < 0) {
-               if (ping_monitor(container->devname) == 0) {
+       if (!takeover && victim > 0 && victim_sock >= 0) {
+               if (fping_monitor(victim_sock) == 0) {
                        fprintf(stderr, "mdmon: %s already managed\n",
                                container->devname);
                        exit(3);
                }
-               /* if there is a pid file, kill whoever is there just in case */
-               victim = mdmon_pid(container->devnum);
+               close(victim_sock);
        }
        if (container->ss->load_super(container, mdfd, devname)) {
                fprintf(stderr, "mdmon: Cannot load metadata for %s\n",