]> git.tuebingen.mpg.de Git - paraslash.git/commit
daemon: Fix race condition in daemonize().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 16 Jun 2016 18:17:21 +0000 (20:17 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 4 Oct 2016 10:19:48 +0000 (12:19 +0200)
commit7d28108f4691e0e7df199fd89f386cafeb3466c7
tree37e0e84496ec32bf729648177677c78fb005bda0
parentcf1b5fd816348658393b7c2583b67560b17f30a2
daemon: Fix race condition in daemonize().

If parent_waits is true, the parent process waits for a signal from
the child before it exits. However, this signal can arive before the
parent has set up its signal handler.

This patch closes the race window by switching from signals to
pipes. We now create a pipe before the new process is forked, and
let the parent block on read(2) until the child exits or indicates
success by writing a byte to one end of the pipe. The child process
receives the file descriptor of the writing end of the pipe as the
return value of daemonize().

The only user of the parent_waits feature is para_server, which is
changed accordingly.
daemon.c
daemon.h
server.c