krb5_wrap: add smb_krb5_salt_principal()
[sfrench/samba-autobuild/.git] / lib / util / tfork.h
1 /*
2    fork on steroids to avoid SIGCHLD and waitpid
3
4    Copyright (C) Stefan Metzmacher 2010
5    Copyright (C) Ralph Boehme 2017
6
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.
11
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.
16
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/>.
19 */
20
21 #ifndef LIB_UTIL_TFORK_H
22 #define LIB_UTIL_TFORK_H
23
24 /**
25  * @brief a fork() that avoids SIGCHLD and waitpid
26  *
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
30  * own handler.
31  *
32  * The child process will start with SIGCHLD handler set to SIG_DFL, so the
33  * child might need to setup its own handler.
34  *
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
39  *                        status (an int).
40  *
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.
44  *
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.
49  */
50 int tfork(int *status_fd, int *parent);
51
52 #endif /* LIB_UTIL_TFORK_H */