diff options
Diffstat (limited to 'contrib/fuse-lib/mount.c')
| -rw-r--r-- | contrib/fuse-lib/mount.c | 94 |
1 files changed, 69 insertions, 25 deletions
diff --git a/contrib/fuse-lib/mount.c b/contrib/fuse-lib/mount.c index 1dfd2a71c05..06ff191f542 100644 --- a/contrib/fuse-lib/mount.c +++ b/contrib/fuse-lib/mount.c @@ -52,12 +52,16 @@ gf_fuse_unmount (const char *mountpoint, int fd) if (geteuid () == 0) { fuse_mnt_umount ("fuse", mountpoint, mountpoint, 1); return; + } else { + GFFUSE_LOGERR ("fuse: Effective-uid: %d", geteuid()); } res = umount2 (mountpoint, 2); if (res == 0) return; + GFFUSE_LOGERR ("fuse: failed to unmount %s: %s", + mountpoint, strerror (errno)); pid = fork (); if (pid == -1) return; @@ -67,6 +71,8 @@ gf_fuse_unmount (const char *mountpoint, int fd) "--", mountpoint, NULL }; execvp (FUSERMOUNT_PROG, (char **)argv); + GFFUSE_LOGERR ("fuse: failed to execute fuserumount: %s", + strerror (errno)); _exit (1); } waitpid (pid, NULL, 0); @@ -75,6 +81,54 @@ gf_fuse_unmount (const char *mountpoint, int fd) /* gluster-specific routines */ +/* Unmounting in a daemon that lurks 'till main process exits */ +int +gf_fuse_unmount_daemon (const char *mountpoint, int fd) +{ + int ret = -1; + pid_t pid = -1; + + if (fd == -1) + return -1; + + int ump[2] = {0,}; + + ret = pipe(ump); + if (ret == -1) { + close (fd); + return -1; + } + + pid = fork (); + switch (pid) { + case 0: + { + char c = 0; + sigset_t sigset; + + close_fds_except (ump, 1); + + setsid(); + (void)chdir("/"); + sigfillset(&sigset); + sigprocmask(SIG_BLOCK, &sigset, NULL); + + read (ump[0], &c, 1); + + gf_fuse_unmount (mountpoint, fd); + exit (0); + } + case -1: + close (fd); + fd = -1; + ret = -1; + close (ump[1]); + } + close (ump[0]); + + return ret; +} + static char * escape (char *s) { @@ -252,38 +306,30 @@ static int mount_param_to_flag (char *mnt_param, mount_flag_t *mntflags, char **mnt_param_new) { - int i = 0; - int j = 0; - char *p = NULL; gf_boolean_t found = _gf_false; struct mount_flags *flag = NULL; + char *param_tok = NULL; + token_iter_t tit = {0,}; + gf_boolean_t iter_end = _gf_false; /* Allocate a buffer that will hold the mount parameters remaining * after the ones corresponding to mount flags are processed and * removed.The length of the original params are a good upper bound * of the size needed. */ - *mnt_param_new = CALLOC (1, strlen (mnt_param) + 1); + *mnt_param_new = strdup (mnt_param); if (!*mnt_param_new) return -1; - p = *mnt_param_new; - - while (mnt_param[j]) { - if (j > 0) - i = j+1; - j = i; - /* Seek the delimiters. */ - while (mnt_param[j] != ',' && mnt_param[j] != '\0') - j++; + for (param_tok = token_iter_init (*mnt_param_new, ',', &tit) ;;) { + iter_end = next_token (¶m_tok, &tit); found = _gf_false; for (flag = mount_flags; flag->opt; flag++) { /* Compare the mount flag name to the param - * name at hand (from i to j in mnt_param). + * name at hand. */ - if (strlen (flag->opt) == j - i && - memcmp (flag->opt, mnt_param + i, j - i) == 0) { + if (strcmp (flag->opt, param_tok) == 0) { /* If there is a match, adjust mntflags * accordingly and break. */ @@ -296,15 +342,12 @@ mount_param_to_flag (char *mnt_param, mount_flag_t *mntflags, break; } } - /* If the param did't match any flag name, retain it (ie. copy - * over to the new param buffer). - */ - if (!found) { - if (p != *mnt_param_new) - *p++ = ','; - memcpy (p, mnt_param + i, j - i); - p += j - i; - } + /* Exclude flag names from new parameter list. */ + if (found) + drop_token (param_tok, &tit); + + if (iter_end) + break; } return 0; @@ -347,6 +390,7 @@ fuse_mount_sys (const char *mountpoint, char *fsname, build_iovec (&iov, &iovlen, "from", "/dev/fuse", -1); build_iovec (&iov, &iovlen, "volname", source, -1); build_iovec (&iov, &iovlen, "fd", fdstr, -1); + build_iovec (&iov, &iovlen, "allow_other", NULL, -1); ret = nmount (iov, iovlen, mountflags); #else ret = mount (source, mountpoint, fstype, mountflags, |
