aboutsummaryrefslogtreecommitdiff
path: root/lib/mount_util.c
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2008-02-08 10:45:06 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2008-02-08 10:45:06 +0000
commit667567764f53ab79fc17d4e9c87aac12d69ac277 (patch)
tree5baf8b40d2a421f5358e5ee99510190e2b075018 /lib/mount_util.c
parent6889e443c5f08fe5972b0eb0fe58a269a5da922b (diff)
Block SIGCHLD when executing mount and umount
Diffstat (limited to 'lib/mount_util.c')
-rw-r--r--lib/mount_util.c48
1 files changed, 36 insertions, 12 deletions
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)