From 859706ccb165b702b3280d2235026ff4ab2b03e3 Mon Sep 17 00:00:00 2001 From: Wouter Verhelst Date: Thu, 15 Oct 2009 19:22:19 +0200 Subject: [PATCH] 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. --- nbd-client.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 -- 1.7.10.4