From 0042f8cc82e98b51defcf28b8e84f47f443cb55a Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Wed, 8 Aug 2007 18:22:01 +0000 Subject: fixes --- lib/helper.c | 14 +++++++++++++- lib/mount_util.c | 15 ++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/helper.c b/lib/helper.c index d7cc9b7..b282da9 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -190,7 +190,19 @@ static struct fuse_chan *fuse_mount_common(const char *mountpoint, struct fuse_args *args) { struct fuse_chan *ch; - int fd = fuse_mount_compat25(mountpoint, args); + int fd; + + /* + * Make sure file descriptors 0, 1 and 2 are open, otherwise chaos + * would ensue. + */ + do { + fd = open("/dev/null", O_RDWR); + if (fd > 2) + close(fd); + } while (fd >= 0 && fd <= 2); + + fd = fuse_mount_compat25(mountpoint, args); if (fd == -1) return NULL; diff --git a/lib/mount_util.c b/lib/mount_util.c index 55b5f4e..781a16a 100644 --- a/lib/mount_util.c +++ b/lib/mount_util.c @@ -18,14 +18,19 @@ #include #include -static int mtab_is_symlink(void) +static int mtab_needs_update(const char *mnt) { struct stat stbuf; + /* If mtab is within new mount, don't touch it */ + if (strncmp(mnt, _PATH_MOUNTED, strlen(mnt)) == 0 && + _PATH_MOUNTED[strlen(mnt)] == '/') + return 0; + if (lstat(_PATH_MOUNTED, &stbuf) != -1 && S_ISLNK(stbuf.st_mode)) - return 1; - else return 0; + + return 1; } int fuse_mnt_add_mount(const char *progname, const char *fsname, @@ -34,7 +39,7 @@ int fuse_mnt_add_mount(const char *progname, const char *fsname, int res; int status; - if (mtab_is_symlink()) + if (!mtab_needs_update(mnt)) return 0; res = fork(); @@ -86,7 +91,7 @@ int fuse_mnt_umount(const char *progname, const char *mnt, int lazy) int res; int status; - if (mtab_is_symlink()) + if (!mtab_needs_update(mnt)) return 0; res = fork(); -- cgit v1.2.3