Put the -nofork check on the right spot
authorWouter Verhelst <w@uter.be>
Thu, 15 Oct 2009 17:22:19 +0000 (19:22 +0200)
committerWouter Verhelst <w@uter.be>
Thu, 15 Oct 2009 17:22:19 +0000 (19:22 +0200)
nbd-client will fork in two occasions: once when going daemon, once when
forking itself off to be able to open the device so we can trigger the
kernel to reread its partition table (if any), which in turn will cause
udev to DTRT.

The NOFORK macros were written in to make debugging simpeler, and
predate the daemon() thing. I think. Anyhow, what's useful for code
debugging is not necessarily useful for runtime debugging; so this moves
the daemon() call inside the macros, makes it not be called if -nofork
has been specified, and changes the code so that the partition table
reread is still triggered even if -nofork has been specified.

nbd-client.c

index ff22c83..9f67da4 100644 (file)
@@ -312,17 +312,15 @@ int main(int argc, char *argv[]) {
 
        /* Go daemon */
        
 
        /* Go daemon */
        
-       daemon(0,0);
-       do {
 #ifndef NOFORK
 #ifndef NOFORK
-               if (!nofork) {
-                       if (fork()) {
-                               while(check_conn(nbddev, 0)) {
-                                       sleep(1);
-                               }
-                               open(nbddev, O_RDONLY);
-                               exit(0);
+       if(!nofork) daemon(0,0);
+       do {
+               if (fork()) {
+                       while(check_conn(nbddev, 0)) {
+                               sleep(1);
                        }
                        }
+                       open(nbddev, O_RDONLY);
+                       exit(0);
                }
 #endif
 
                }
 #endif