]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdmon.c
Change way of printing name of a process
[thirdparty/mdadm.git] / mdmon.c
diff --git a/mdmon.c b/mdmon.c
index 36c25d3ca851e9e2ffbab66528a7d19aa6c8da12..ee12b7c788ac0fc969499204343db8f39b124843 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -67,6 +67,8 @@
 #include       "mdadm.h"
 #include       "mdmon.h"
 
+char const Name[] = "mdmon";
+
 struct active_array *discard_this;
 struct active_array *pending_discard;
 
@@ -200,7 +202,7 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock)
        fcntl(sock, F_SETFL, fl);
        n = read(sock, buf, 100);
        /* Ignore result, it is just the wait that
-        * matters 
+        * matters
         */
 }
 
@@ -232,6 +234,7 @@ static int make_control_sock(char *devname)
 
        addr.sun_family = PF_LOCAL;
        strcpy(addr.sun_path, path);
+       umask(077); /* ensure no world write access */
        if (bind(sfd, &addr, sizeof(addr)) < 0) {
                close(sfd);
                return -1;
@@ -298,10 +301,14 @@ int main(int argc, char *argv[])
                {NULL, 0, NULL, 0}
        };
 
-       /*
-        * Always change process name to @dmon to avoid systemd killing it
-        */
-       argv[0][0] = '@';
+       if (in_initrd()) {
+               /*
+                * set first char of argv[0] to @. This is used by
+                * systemd to signal that the task was launched from
+                * initrd/initramfs and should be preserved during shutdown
+                */
+               argv[0][0] = '@';
+       }
 
        while ((opt = getopt_long(argc, argv, "thaF", options, NULL)) != -1) {
                switch (opt) {
@@ -316,7 +323,7 @@ int main(int argc, char *argv[])
                        dofork = 0;
                        break;
                case OffRootOpt:
-                       /* silently ignore old option */
+                       argv[0][0] = '@';
                        break;
                case 'h':
                default:
@@ -425,6 +432,7 @@ static int mdmon(char *devnm, int must_fork, int takeover)
                                wait(&status);
                                status = WEXITSTATUS(status);
                        }
+                       close(pfd[0]);
                        return status;
                }
        } else
@@ -512,10 +520,12 @@ static int mdmon(char *devnm, int must_fork, int takeover)
        container->sock = make_control_sock(devnm);
 
        status = 0;
-       if (write(pfd[1], &status, sizeof(status)) < 0)
-               pr_err("failed to notify our parent: %d\n",
-                       getppid());
-       close(pfd[1]);
+       if (pfd[1] >= 0) {
+               if (write(pfd[1], &status, sizeof(status)) < 0)
+                       pr_err("failed to notify our parent: %d\n",
+                              getppid());
+               close(pfd[1]);
+       }
 
        mlockall(MCL_CURRENT | MCL_FUTURE);
 
@@ -583,3 +593,10 @@ int save_stripes(int *source, unsigned long long *offsets,
 {
        return 0;
 }
+
+struct superswitch super0 = {
+       .name = "0.90",
+};
+struct superswitch super1 = {
+       .name = "1.x",
+};