Don't call /bin/[u]mount if /etc/mtab is a symlink
authorMiklos Szeredi <miklos@szeredi.hu>
Wed, 25 Jul 2007 09:36:52 +0000 (09:36 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Wed, 25 Jul 2007 09:36:52 +0000 (09:36 +0000)
ChangeLog
lib/fuse_opt.c
lib/mount_util.c

index 0d46ef92b342f272ecebf7ca678f9a9b2f1b0072..2bf2251b87488c1abea53f1d6715e43271b7c79a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-07-25  Miklos Szeredi <miklos@szeredi.hu>
+
+       * Don't call /bin/[u]mount if /etc/mtab is a symlink.  Reported by
+       Tomas M
+
 2007-07-12  Miklos Szeredi <miklos@szeredi.hu>
 
        * Reset args->argc in fuse_opt_free_args().  Patch by Lucas
index 31cffaf59f31fcdee6b378e76ca9c663384c0081..9b464a1120fd13c10ff4ac22eab583e1ecc508bc 100644 (file)
@@ -27,11 +27,13 @@ struct fuse_opt_context {
 
 void fuse_opt_free_args(struct fuse_args *args)
 {
-    if (args && args->argv && args->allocated) {
-        int i;
-        for (i = 0; i < args->argc; i++)
-            free(args->argv[i]);
-        free(args->argv);
+    if (args) {
+        if (args->argv && args->allocated) {
+            int i;
+            for (i = 0; i < args->argc; i++)
+                free(args->argv[i]);
+            free(args->argv);
+        }
         args->argc = 0;
         args->argv = NULL;
         args->allocated = 0;
index dccecdf53812921e8fbece28ee40160467a822e4..55b5f4e3f32aa338585bca8eb5b02b44ea342de6 100644 (file)
 #include <dirent.h>
 #include <errno.h>
 #include <limits.h>
+#include <mntent.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 
+static int mtab_is_symlink(void)
+{
+    struct stat stbuf;
+
+    if (lstat(_PATH_MOUNTED, &stbuf) != -1 && S_ISLNK(stbuf.st_mode))
+        return 1;
+    else
+        return 0;
+}
+
 int fuse_mnt_add_mount(const char *progname, const char *fsname,
                        const char *mnt, const char *type, const char *opts)
 {
     int res;
     int status;
 
+    if (mtab_is_symlink())
+        return 0;
+
     res = fork();
     if (res == -1) {
         fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
@@ -72,6 +86,9 @@ int fuse_mnt_umount(const char *progname, const char *mnt, int lazy)
     int res;
     int status;
 
+    if (mtab_is_symlink())
+        return 0;
+
     res = fork();
     if (res == -1) {
         fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));