From 667567764f53ab79fc17d4e9c87aac12d69ac277 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Fri, 8 Feb 2008 10:45:06 +0000 Subject: [PATCH] Block SIGCHLD when executing mount and umount --- ChangeLog | 4 ++++ lib/mount_util.c | 48 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb93b44..2acf5b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-02-08 Miklos Szeredi + + * Block SIGCHLD when executing mount and umount + 2008-02-03 Csaba Henk * lib/mount_bsd.c: diff --git a/lib/mount_util.c b/lib/mount_util.c index 39a1e6f..fc56255 100644 --- a/lib/mount_util.c +++ b/lib/mount_util.c @@ -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) -- 2.30.2