Revert "Fix cleanup in case of failed mount"
authorMiklos Szeredi <mszeredi@suse.cz>
Fri, 11 Mar 2011 12:46:13 +0000 (13:46 +0100)
committerMiklos Szeredi <mszeredi@suse.cz>
Fri, 11 Mar 2011 12:46:13 +0000 (13:46 +0100)
This reverts commit bf5ffb5fd8558bd799791834def431c0cee5a11f.

Cleanup of mount doesn't work the way it was envisioned, because the
kernel doesn't follow mounts on the umount() call, hence it will find
a non-mounted directory.

ChangeLog
util/fusermount.c

index 61716754cdc0130c96889c3a88d7b9b4825dee9e..1e9173fedb3414695edeebf558e39dd52cfb7292 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,9 +8,6 @@
 
 2011-01-31  Miklos Szeredi <miklos@szeredi.hu>
 
-       * In case of failure to add to /etc/mtab use same mountpoint for
-       cleanup as for mounting.  Reported by Marc Deslauriers
-
        * fusermount: chdir to / before performing mount/umount
 
        * fusermount: only allow mount and umount if util-linux supports
index 94a5dbcd5f88c709ff428bb4224bab6d7afab642..48f23fa8630afff3d0706be5ed0ca4c13993e6c6 100644 (file)
@@ -896,8 +896,7 @@ static int check_version(const char *dev)
        return 0;
 }
 
-static int check_perm(const char **mntp, struct stat *stbuf,
-                     int *mountpoint_fd, int *isdir)
+static int check_perm(const char **mntp, struct stat *stbuf, int *mountpoint_fd)
 {
        int res;
        const char *mnt = *mntp;
@@ -915,17 +914,10 @@ static int check_perm(const char **mntp, struct stat *stbuf,
                return 0;
 
        if (S_ISDIR(stbuf->st_mode)) {
-               *isdir = 1;
-               *mountpoint_fd = open(mnt, O_RDONLY);
-               if (*mountpoint_fd == -1) {
-                       fprintf(stderr, "%s: failed to open %s: %s\n",
-                               progname, mnt, strerror(errno));
-                       return -1;
-               }
-               res = fchdir(*mountpoint_fd);
+               res = chdir(mnt);
                if (res == -1) {
                        fprintf(stderr,
-                               "%s: failed to fchdir to mountpoint: %s\n",
+                               "%s: failed to chdir to mountpoint: %s\n",
                                progname, strerror(errno));
                        return -1;
                }
@@ -1050,7 +1042,6 @@ static int mount_fuse(const char *mnt, const char *opts)
        char *mnt_opts = NULL;
        const char *real_mnt = mnt;
        int mountpoint_fd = -1;
-       int isdir = 0;
 
        fd = open_fuse_device(&dev);
        if (fd == -1)
@@ -1070,7 +1061,7 @@ static int mount_fuse(const char *mnt, const char *opts)
 
        res = check_version(dev);
        if (res != -1) {
-               res = check_perm(&real_mnt, &stbuf, &mountpoint_fd, &isdir);
+               res = check_perm(&real_mnt, &stbuf, &mountpoint_fd);
                restore_privs();
                if (res != -1)
                        res = do_mount(real_mnt, &type, stbuf.st_mode & S_IFMT,
@@ -1081,37 +1072,22 @@ static int mount_fuse(const char *mnt, const char *opts)
 
        chdir("/");
        if (mountpoint_fd != -1)
-               fcntl(mountpoint_fd, F_SETFD, FD_CLOEXEC);
+               close(mountpoint_fd);
 
        if (res == -1) {
                close(fd);
-               if (mountpoint_fd != -1)
-                       close(mountpoint_fd);
                return -1;
        }
 
        if (geteuid() == 0) {
                res = add_mount(source, mnt, type, mnt_opts);
                if (res == -1) {
-                       if (isdir && mountpoint_fd != -1) {
-                               res = fchdir(mountpoint_fd);
-                               if (res == -1) {
-                                       close(mountpoint_fd);
-                                       close(fd);
-                                       return -1;
-                               }
-                       }
-                       umount2(real_mnt, UMOUNT_DETACH); /* lazy umount */
-                       if (mountpoint_fd != -1)
-                               close(mountpoint_fd);
+                       umount2(mnt, UMOUNT_DETACH); /* lazy umount */
                        close(fd);
                        return -1;
                }
        }
 
-       if (mountpoint_fd != -1)
-               close(mountpoint_fd);
-
        free(source);
        free(type);
        free(mnt_opts);