Workaround FUSE/Linux-kernel to try ourselves to modprobe FUSE on ENODEV.
[captive.git] / src / client / fuse / fusermount.c
index c7e45f9..9ceadc1 100644 (file)
@@ -121,7 +121,7 @@ static int lock_mtab(void)
 static void unlock_mtab(int mtablock)
 {
     if (mtablock >= 0) {
-       lockf(mtablock, F_ULOCK, 0);
+       int trash0=lockf(mtablock, F_ULOCK, 0);
        close(mtablock);
     }
 }
@@ -289,8 +289,9 @@ static int unmount_rename(const char *mnt, int quiet, int lazy,
     if (res == -1)
         return -1;
 
-    if (stat(mtab, &sbuf) == 0)
-        chown(mtab_new, sbuf.st_uid, sbuf.st_gid);
+    if (stat(mtab, &sbuf) == 0) {
+        int trash0=chown(mtab_new, sbuf.st_uid, sbuf.st_gid);
+                               }
 
     res = rename(mtab_new, mtab);
     if (res == -1) {
@@ -791,6 +792,17 @@ static int try_open(const char *dev, char **devp, int silent)
         if ((group = getgrnam("fuse")) && !chown(dev, 0, group->gr_gid))
             fd = open(dev, O_RDWR);
     }
+    if (fd == -1 && errno == ENODEV) {
+        const char *cmd = "/sbin/modprobe fuse";
+
+        if (!system(cmd))
+            fprintf(stderr, "%s: Notice: Loaded Linux kernel module FUSE: %s\n",
+                    progname, cmd);
+        else
+            fprintf(stderr, "%s: Warning: \"%s\" cannot be opened and even failed: %s\n",
+                    progname, dev, cmd);
+        fd = open(dev, O_RDWR);
+    }
     if (fd != -1) {
         *devp = strdup(dev);
         if (*devp == NULL) {
@@ -890,7 +902,7 @@ static int mount_fuse(const char *mnt, const char *opts)
         restore_privs();
 
     if (currdir_fd != -1) {
-        fchdir(currdir_fd);
+        int trash0=fchdir(currdir_fd);
         close(currdir_fd);
     }
     if (mountpoint_fd != -1)