Block SIGCHLD when executing mount and umount
authorMiklos Szeredi <miklos@szeredi.hu>
Fri, 8 Feb 2008 10:45:06 +0000 (10:45 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Fri, 8 Feb 2008 10:45:06 +0000 (10:45 +0000)
ChangeLog
lib/mount_util.c

index bb93b44daf3aadc3a9f4f6e44f187c8f63be50d8..2acf5b3cf42c63d9df7e2b168d1a23bc0d9d6ed4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-02-08  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Block SIGCHLD when executing mount and umount
+
 2008-02-03  Csaba Henk <csaba.henk@creo.hu>
 
        * lib/mount_bsd.c:
index 39a1e6f070cf1b61bb10cdb90a15e659f3b02f6e..fc5625570f66facce9e96e7e048c601659a08e66 100644 (file)
@@ -39,19 +39,30 @@ int fuse_mnt_add_mount(const char *progname, const char *fsname,
 {
        int res;
        int status;
+       sigset_t blockmask;
+       sigset_t oldmask;
 
        if (!mtab_needs_update(mnt))
                return 0;
 
+       sigemptyset(&blockmask);
+       sigaddset(&blockmask, SIGCHLD);
+       res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
+       if (res == -1) {
+               fprintf(stderr, "%s: sigprocmask: %s\n", progname, strerror(errno));
+               return -1;
+       }
+
        res = fork();
        if (res == -1) {
                fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
-               return -1;
+               goto out_restore;
        }
        if (res == 0) {
                char templ[] = "/tmp/fusermountXXXXXX";
                char *tmp;
 
+               sigprocmask(SIG_SETMASK, &oldmask, NULL);
                setuid(geteuid());
 
                /*
@@ -78,20 +89,23 @@ int fuse_mnt_add_mount(const char *progname, const char *fsname,
                exit(1);
        }
        res = waitpid(res, &status, 0);
-       if (res == -1) {
+       if (res == -1)
                fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
-               return -1;
-       }
+
        if (status != 0)
-               return -1;
+               res = -1;
 
-       return 0;
+ out_restore:
+       sigprocmask(SIG_SETMASK, &oldmask, NULL);
+       return res;
 }
 
 int fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
 {
        int res;
        int status;
+       sigset_t blockmask;
+       sigset_t oldmask;
 
        if (!mtab_needs_update(mnt)) {
                res = umount2(mnt, lazy ? 2 : 0);
@@ -101,12 +115,21 @@ int fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
                return res;
        }
 
+       sigemptyset(&blockmask);
+       sigaddset(&blockmask, SIGCHLD);
+       res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
+       if (res == -1) {
+               fprintf(stderr, "%s: sigprocmask: %s\n", progname, strerror(errno));
+               return -1;
+       }
+
        res = fork();
        if (res == -1) {
                fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
-               return -1;
+               goto out_restore;
        }
        if (res == 0) {
+               sigprocmask(SIG_SETMASK, &oldmask, NULL);
                setuid(geteuid());
                execl("/bin/umount", "/bin/umount", "-i", mnt,
                      lazy ? "-l" : NULL, NULL);
@@ -115,14 +138,15 @@ int fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
                exit(1);
        }
        res = waitpid(res, &status, 0);
-       if (res == -1) {
+       if (res == -1)
                fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
-               return -1;
-       }
+
        if (status != 0)
-               return -1;
+               res = -1;
 
-       return 0;
+ out_restore:
+       sigprocmask(SIG_SETMASK, &oldmask, NULL);
+       return res;
 }
 
 char *fuse_mnt_resolve_path(const char *progname, const char *orig)