| 1 |
/* Waiting for a subprocess to finish. |
| 2 |
Copyright (C) 2001-2003, 2006, 2008-2024 Free Software Foundation, Inc. |
| 3 |
Written by Bruno Haible <[email protected]>, 2001. |
| 4 |
|
| 5 |
This program is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation, either version 3 of the License, or |
| 8 |
(at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 17 |
|
| 18 |
#ifndef _WAIT_PROCESS_H |
| 19 |
#define _WAIT_PROCESS_H |
| 20 |
|
| 21 |
/* Get pid_t. */ |
| 22 |
#include <stdlib.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <sys/types.h> |
| 25 |
|
| 26 |
|
| 27 |
#ifdef __cplusplus |
| 28 |
extern "C" { |
| 29 |
#endif |
| 30 |
|
| 31 |
|
| 32 |
/* Wait for a subprocess to finish. Return its exit code. |
| 33 |
If it didn't terminate correctly, exit if exit_on_error is true, otherwise |
| 34 |
return 127. |
| 35 |
Arguments: |
| 36 |
- child is the pid of the subprocess. |
| 37 |
- progname is the name of the program executed by the subprocess, used for |
| 38 |
error messages. |
| 39 |
- If ignore_sigpipe is true, consider a subprocess termination due to |
| 40 |
SIGPIPE as equivalent to a success. This is suitable for processes whose |
| 41 |
only purpose is to write to standard output. This flag can be safely set |
| 42 |
to false when the process' standard output is known to go to DEV_NULL. |
| 43 |
- If null_stderr is true, the usual error message to stderr will be omitted. |
| 44 |
This is suitable when the subprocess does not fulfill an important task. |
| 45 |
- slave_process should be set to true if the process has been launched as a |
| 46 |
slave process. |
| 47 |
- If exit_on_error is true, any error will cause the main process to exit |
| 48 |
with an error status. |
| 49 |
- If termsigp is not NULL: *termsig will be set to the signal that |
| 50 |
terminated the subprocess (if supported by the platform: not on native |
| 51 |
Windows platforms), otherwise 0, and the error message about the signal |
| 52 |
that terminated the subprocess will be omitted. |
| 53 |
Prerequisites: The signal handler for SIGCHLD should not be set to SIG_IGN, |
| 54 |
otherwise this function will not work. */ |
| 55 |
extern int wait_subprocess (pid_t child, const char *progname, |
| 56 |
bool ignore_sigpipe, bool null_stderr, |
| 57 |
bool slave_process, bool exit_on_error, |
| 58 |
int *termsigp); |
| 59 |
|
| 60 |
/* Register a subprocess as being a slave process. This means that the |
| 61 |
subprocess will be terminated when its creator receives a catchable fatal |
| 62 |
signal or exits normally. Registration ends when wait_subprocess() |
| 63 |
notices that the subprocess has exited. */ |
| 64 |
extern void register_slave_subprocess (pid_t child); |
| 65 |
|
| 66 |
|
| 67 |
#ifdef __cplusplus |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
#endif /* _WAIT_PROCESS_H */ |