Check for async-signal-safety
elfring opened this issue · 1 comments
elfring commented
I see in a source file that functions like "fopen" and "getenv" are used before the function "execvp" will be called. Would you like to improve your program design if you consider information like the following?
... Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. ...
jsipprell commented
Async signal safety of the type you're talking about only applies to forking when multiple threads of execution are running in the parent prior to fork()
.
For single threaded processes there are a couple of process signal synchronization issues however:
- A race condition where the parent is unable to catch
SIGCHLD
caused by an immediately premature death of the new child. This is not an issue for daemonize however, as when in parent-mode it does not attempt to monitor the child process status post-fork and usesdaemon()
(either system-provided or the bundled version) to immediately terminate. ... but that leads to... - The bundled
daemon()
implementation does not maskSIGHUP
prior to forking and calling (in the child)setsid()
. This creates a race condition where a grandparent process, often a shell, sends the entire process groupSIGHUP
while it exits immediately after the initial parent daemonize exits. If the child has not successfully completed callingsetsid()
it will die with the rest of the process group. Obviously, this is only a problem on systems which do not providedaemon()
in their libc -- a rare case these days.