* lib/wait-process.h (wait_subprocess): Accept a new exitsignal argument.
[gnulib.git] / lib / wait-process.h
1 /* Waiting for a subprocess to finish.
2    Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc.
3    Written by Bruno Haible <haible@clisp.cons.org>, 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 2, or (at your option)
8    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, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #ifndef _WAIT_PROCESS_H
20 #define _WAIT_PROCESS_H
21
22 /* Get pid_t.  */
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <sys/types.h>
26
27 #include <stdbool.h>
28
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34
35 /* Wait for a subprocess to finish.  Return its exit code.
36    If it didn't terminate correctly, exit if exit_on_error is true, otherwise
37    return 127 and set exitsignal if the child terminated because of a signal.
38    Arguments:
39    - child is the pid of the subprocess.
40    - progname is the name of the program executed by the subprocess, used for
41      error messages.
42    - exitsignal is an optional pointer to an int to hold the signal number of
43      any signal that caused the child to exit.  It will be set to zero if this
44      function exits with an error not caused by the child catching a signal.
45    - If ignore_sigpipe is true, consider a subprocess termination due to
46      SIGPIPE as equivalent to a success.  This is suitable for processes whose
47      only purpose is to write to standard output.  This flag can be safely set
48      to false when the process' standard output is known to go to DEV_NULL.
49    - If null_stderr is true, the usual error message to stderr will be omitted.
50      This is suitable when the subprocess does not fulfill an important task.
51    - slave_process should be set to true if the process has been launched as a
52      slave process.
53    - If exit_on_error is true, any error will cause the main process to exit
54      with an error status.  */
55 extern int wait_subprocess (pid_t child, const char *progname,
56                             int *exitsignal,
57                             bool ignore_sigpipe, bool null_stderr,
58                             bool slave_process, bool exit_on_error);
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 */