libfuse: call umount(8) directly...
authorMiklos Szeredi <miklos@szeredi.hu>
Fri, 27 Apr 2007 18:08:15 +0000 (18:08 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Fri, 27 Apr 2007 18:08:15 +0000 (18:08 +0000)
ChangeLog
lib/mount.c
lib/mount_util.c
lib/mount_util.h
util/fusermount.c

index 4f27cec08b1685b9c7b81169cf4088d73d33878c..8ad2462e369f4744cca86ebd6bfbb523002c0f85 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-27  Miklos Szeredi <miklos@szeredi.hu>
+
+       * libfuse: call umount(8) directly instead of fusermount if
+       possible
+
 2007-04-26  Miklos Szeredi <miklos@szeredi.hu>
 
        * In multithreaded loop, use a semaphore instead of SIGHUP to wake
index 0587bac9d03b7557f7c36c85205e1e2b54140ad7..24bcf8c6a7802b24e7e5538bba28d6ab7ddc54b4 100644 (file)
@@ -276,6 +276,11 @@ void fuse_kern_unmount(const char *mountpoint, int fd)
             return;
     }
 
+    if (geteuid() == 0) {
+        fuse_mnt_umount("fuse", mountpoint, 1);
+        return;
+    }
+
     res = umount2(mountpoint, 2);
     if (res == 0)
         return;
index 8aafa334e49a6229afb4a41d0a90c5012369d2e7..b82ab3b2b5a3a622b5d19dfa902c25c0478f89e0 100644 (file)
@@ -72,6 +72,35 @@ int fuse_mnt_add_mount(const char *progname, const char *fsname,
     return 0;
 }
 
+int fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
+{
+    int res;
+    int status;
+
+    res = fork();
+    if (res == -1) {
+        fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
+        return -1;
+    }
+    if (res == 0) {
+        setuid(geteuid());
+        execl("/bin/umount", "/bin/umount", "-i", mnt, lazy ? "-l" : NULL,
+              NULL);
+        fprintf(stderr, "%s: failed to execute /bin/umount: %s\n", progname,
+                strerror(errno));
+        exit(1);
+    }
+    res = waitpid(res, &status, 0);
+    if (res == -1) {
+        fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
+        return -1;
+    }
+    if (status != 0)
+        return -1;
+
+    return 0;
+}
+
 char *fuse_mnt_resolve_path(const char *progname, const char *orig)
 {
     char buf[PATH_MAX];
index c64423bd2c6d0ce2825836a3fec908baa5f5c72c..106a6f8f224930c2d6899cc4ee928aedfc75b36a 100644 (file)
@@ -10,6 +10,7 @@
 
 int fuse_mnt_add_mount(const char *progname, const char *fsname,
                        const char *mnt, const char *type, const char *opts);
+int fuse_mnt_umount(const char *progname, const char *mnt, int lazy);
 char *fuse_mnt_resolve_path(const char *progname, const char *orig);
 int fuse_mnt_check_empty(const char *progname, const char *mnt,
                          mode_t rootmode, off_t rootsize);
index 16a9f9a9b1248cd4257f7f340572f19a14866183..8f69599e88f77df9a34cb1f7dbede31dd94c1868 100644 (file)
@@ -73,35 +73,6 @@ static void restore_privs(void)
     }
 }
 
-static int do_unmount(const char *mnt, int quiet, int lazy)
-{
-    int res;
-    int status;
-
-    (void) quiet;
-    res = fork();
-    if (res == -1) {
-        perror("fork");
-        return -1;
-    }
-    if (res == 0) {
-        setuid(geteuid());
-        execl("/bin/umount", "/bin/umount", "-i", mnt, lazy ? "-l" : NULL,
-              NULL);
-        perror("execl /bin/umount");
-        exit(1);
-    }
-    res = waitpid(res, &status, 0);
-    if (res == -1) {
-        perror("waitpid");
-        return -1;
-    }
-    if (status != 0)
-        return -1;
-
-    return 0;
-}
-
 #ifndef IGNORE_MTAB
 static int add_mount(const char *fsname, const char *mnt, const char *type,
                      const char *opts)
@@ -164,7 +135,7 @@ static int unmount_fuse(const char *mnt, int quiet, int lazy)
         }
     }
 
-    return do_unmount(mnt, quiet, lazy);
+    return fuse_mnt_umount(progname, mnt, lazy);
 }
 
 static int count_fuse_fs(void)
@@ -205,7 +176,7 @@ static int add_mount(const char *fsname, const char *mnt, const char *type,
 
 static int unmount_fuse(const char *mnt, int quiet, int lazy)
 {
-    return do_unmount(mnt, quiet, lazy);
+    return fuse_mnt_umount(progname, mnt, lazy);
 }
 #endif /* IGNORE_MTAB */