[mapplauncherd] Fix race when in writing the daemon PID file and exiting. Contributes to JB#41671

The process forks twice when daemonizing, we need to wait for
the first fork to exit after it has written the PID of the second
fork before exiting the original process otherwise systemd may
try and read the file before it exists.
pull/1/head
Andrew den Exter 8 years ago
parent 78d0dc16f1
commit d57148540f

@ -522,7 +522,10 @@ void Daemon::daemonize()
// If we got a good PID, then we can exit the parent process.
if (pid > 0)
{
exit(EXIT_SUCCESS);
// Wait for the child fork to exit to ensure the PID has been written before a caller
// is notified of the exit.
waitpid(pid, NULL, 0);
_exit(EXIT_SUCCESS);
}
// Fork off the parent process: second fork
@ -541,7 +544,7 @@ void Daemon::daemonize()
fclose(pidFile);
}
exit(EXIT_SUCCESS);
_exit(EXIT_SUCCESS);
}
// Change the file mode mask

Loading…
Cancel
Save