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.
/* 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