From: Wouter Verhelst Date: Thu, 15 Oct 2009 17:22:19 +0000 (+0200) Subject: Put the -nofork check on the right spot X-Git-Url: http://git.alex.org.uk Put the -nofork check on the right spot 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. --- diff --git a/nbd-client.c b/nbd-client.c index ff22c83..9f67da4 100644 --- a/nbd-client.c +++ b/nbd-client.c @@ -312,17 +312,15 @@ int main(int argc, char *argv[]) { /* Go daemon */ - daemon(0,0); - do { #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