lib/util: enhanced tfork()
authorRalph Boehme <slow@samba.org>
Tue, 25 Apr 2017 22:48:39 +0000 (00:48 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 3 Jul 2017 17:59:07 +0000 (19:59 +0200)
commit844db654987936cf257d3fa8a256e43c4c96d7e7
tree192463b9974b5f91d3b5aed6b33c91f43145c294
parent1f5a297b516b56ab6afbfc4ba1513dc73764dcf7
lib/util: enhanced tfork()

This function is a solution to the problem of fork() requiring special
preperations in the caller to handle SIGCHLD signals and to reap the
child by wait()ing for it.

Instead, tfork provides a pollable file descriptor. The caller gets the
file descriptor by calling tfork_event_fd() on the handle returned from
tfork_create() and the caller can then get the status of the child
with a call to tfork_status().

tfork avoids raising SIGCHLD signals in the caller by installing a
temporary SIGCHLD handler from inside tfork_create() and tfork_status().

The termination signal of other child processes not created with tfork()
is forwarded to the existing signal handler if any.

There's one thing this thing can't protect us against and that is if a
process installs a SIGCHLD handler from one thread while another thread
is running inside tfork_create() or tfork_status() and the signal
handler doesn't forward signals for exitted childs it didn't fork, ie
our childs.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/util/tests/tfork.c
lib/util/tfork.c
lib/util/tfork.h