2 fork on steroids to avoid SIGCHLD and waitpid
4 Copyright (C) Stefan Metzmacher 2010
5 Copyright (C) Ralph Boehme 2017
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef LIB_UTIL_TFORK_H
22 #define LIB_UTIL_TFORK_H
25 * @brief a fork() that avoids SIGCHLD and waitpid
27 * This function is a workaround for the problem of using fork() in
28 * library code. In that case the library should avoid to set a global
29 * signal handler for SIGCHLD, because the application may wants to use its
32 * The child process will start with SIGCHLD handler set to SIG_DFL, so the
33 * child might need to setup its own handler.
35 * @param[out] status_fd If this is not NULL, tfork creates a pipe and returns
36 * the readable end via this pointer. The caller can
37 * wait for the process to finish by polling the
38 * status_fd for readability and can then read the exit
41 * @param[out] parent The PID of the parent process, if 0 is returned
42 * otherwise the variable will not be touched at all.
43 * It is possible to pass NULL.
45 * @return On success, the PID of the child process is returned
46 * in the parent, and 0 is returned in the child. On
47 * failure, -1 is returned in the parent, no child
48 * process is created, and errno is set appropriately.
50 int tfork(int *status_fd, int *parent);
52 #endif /* LIB_UTIL_TFORK_H */