diff options
author | Csaba Henk <csaba@gluster.com> | 2010-04-28 01:37:39 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-04-29 23:10:15 -0700 |
commit | b03a5683680b7be5ff7c88083276811a381aac68 (patch) | |
tree | c2176a4beccf41daadd3715c5e9944ca410d5bf0 | |
parent | 07744014e26e6c3edb14e624ef2f68c56694375a (diff) |
fusermount: bring in updates from upstream
* Fix checking for symlinks in umount from /tmp. Reported by Al
Viro
* Fix umounting if /tmp is a symlink. Reported by Franco Broi
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 657 (Metabug for tracking fuse upstream)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=657
-rw-r--r-- | contrib/fuse-util/fusermount.c | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/contrib/fuse-util/fusermount.c b/contrib/fuse-util/fusermount.c index 6123c66e30b..ae779d3fb21 100644 --- a/contrib/fuse-util/fusermount.c +++ b/contrib/fuse-util/fusermount.c @@ -41,8 +41,8 @@ #ifndef MS_REC #define MS_REC 16384 #endif -#ifndef MS_SLAVE -#define MS_SLAVE (1<<19) +#ifndef MS_PRIVATE +#define MS_PRIVATE (1<<18) #endif static const char *progname; @@ -200,15 +200,16 @@ static int may_unmount(const char *mnt, int quiet) * killed for any reason, mounts are automatically cleaned up. * * First make sure nothing is propagated back into the parent - * namespace by marking all mounts "slave". + * namespace by marking all mounts "private". * * Then bind mount parent onto a stable base where the user can't move - * it around. Use "/tmp", since it will almost certainly exist, but - * anything similar would do as well. + * it around. * * Finally check /proc/mounts for an entry matching the requested * mountpoint. If it's found then we are OK, and the user can't move - * it around within the parent directory as rename() will return EBUSY. + * it around within the parent directory as rename() will return + * EBUSY. Be careful to ignore any mounts that existed before the + * bind. */ static int check_is_mount_child(void *p) { @@ -220,21 +221,27 @@ static int check_is_mount_child(void *p) int found; FILE *fp; struct mntent *entp; + int count; - res = mount("", "/", "", MS_SLAVE | MS_REC, NULL); + res = mount("", "/", "", MS_PRIVATE | MS_REC, NULL); if (res == -1) { - fprintf(stderr, "%s: failed to mark mounts slave: %s\n", + fprintf(stderr, "%s: failed to mark mounts private: %s\n", progname, strerror(errno)); return 1; } - res = mount(".", "/tmp", "", MS_BIND | MS_REC, NULL); - if (res == -1) { - fprintf(stderr, "%s: failed to bind parent to /tmp: %s\n", - progname, strerror(errno)); + fp = setmntent(procmounts, "r"); + if (fp == NULL) { + fprintf(stderr, "%s: failed to open %s: %s\n", progname, + procmounts, strerror(errno)); return 1; } + count = 0; + while ((entp = getmntent(fp)) != NULL) + count++; + endmntent(fp); + fp = setmntent(procmounts, "r"); if (fp == NULL) { fprintf(stderr, "%s: failed to open %s: %s\n", progname, @@ -242,10 +249,21 @@ static int check_is_mount_child(void *p) return 1; } + res = mount(".", "/", "", MS_BIND | MS_REC, NULL); + if (res == -1) { + fprintf(stderr, "%s: failed to bind parent to /: %s\n", + progname, strerror(errno)); + return 1; + } + found = 0; while ((entp = getmntent(fp)) != NULL) { - if (strncmp(entp->mnt_dir, "/tmp/", 5) == 0 && - strcmp(entp->mnt_dir + 5, last) == 0) { + if (count > 0) { + count--; + continue; + } + if (entp->mnt_dir[0] == '/' && + strcmp(entp->mnt_dir + 1, last) == 0) { found = 1; break; } |