run mount util foregrounded on FreeBSD if kernel features backgrounded init
authorCsaba Henk <csaba.henk@creo.hu>
Sat, 22 Apr 2006 22:46:52 +0000 (22:46 +0000)
committerCsaba Henk <csaba.henk@creo.hu>
Sat, 22 Apr 2006 22:46:52 +0000 (22:46 +0000)
ChangeLog
lib/mount_bsd.c

index 32df2584202d9791a7443035dd689b8a29e0d683..7007037a09d8c1248b6258da5ad9c2e7ace4bb9d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-04-23  Csaba Henk <csaba.henk@creo.hu>
+
+       * lib: make FreeBSD mount routine recognize if kernel features
+        backgrounded init and if it does, run the mount util in foreground
+        (similarly to Linux)
+
 2006-04-21  Miklos Szeredi <miklos@szeredi.hu>
 
        * kernel: fix fput deadlock fix, the lockless solution could lead
index aefc69fcd97ed651f82d4ecf82164140a5c29460..ea4140a551b893a8eca2111d6ac96c72d72dede4 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <sys/sysctl.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -225,6 +226,20 @@ void fuse_kern_unmount(const char *mountpoint, int fd)
     system(umount_cmd);
 }
 
+/* Check if kernel is doing init in background */
+static int init_backgrounded(void)
+{
+    int ibg, len;
+
+    len = sizeof(ibg);
+
+    if (sysctlbyname("vfs.fuse.init_backgrounded", &ibg, &len, NULL, 0))
+        return 0;
+
+    return ibg;
+}
+
+
 static int fuse_mount_core(const char *mountpoint, const char *opts)
 {
     const char *mountprog = FUSERMOUNT_PROG;
@@ -273,12 +288,19 @@ mount:
     }
 
     if (pid == 0) {
-        pid = fork();
-
-        if (pid == -1) {
-            perror("fuse: fork() failed");
-            close(fd);
-            exit(1);
+        if (! init_backgrounded()) {
+            /*
+             * If init is not backgrounded, we have to call the mount util
+             * backgrounded, to avoid deadlock.
+             */
+
+            pid = fork();
+    
+            if (pid == -1) {
+                perror("fuse: fork() failed");
+                close(fd);
+                exit(1);
+            }
         }
 
         if (pid == 0) {