src/util.{c,h}: get rid of ensure_* functions
[vlock.git] / src / process.h
blob2ea43a50034fad70d66da1ba7f4f7b29e673c2a6
1 /* process.h -- header for child process routines for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
10 * the author.
14 #include <stdbool.h>
15 #include <sys/types.h>
17 /* Wait for the given amount of time for the death of the given child process.
18 * If the child process dies in the given amount of time or already was dead
19 * true is returned and false otherwise. */
20 bool wait_for_death(pid_t pid, long sec, long usec);
22 /* Try hard to kill the given child process. */
23 void ensure_death(pid_t pid);
25 #define NO_REDIRECT (-2)
26 #define REDIRECT_DEV_NULL (-3)
27 #define REDIRECT_PIPE (-4)
29 struct child_process {
30 /* Function that will be run in the child. */
31 int (*function)(void *argument);
32 /* Argument for the function. */
33 void *argument;
34 /* First argument to execv. */
35 const char *path;
36 /* Second argument to execv. */
37 const char *const *argv;
38 /* The child's stdin. */
39 int stdin_fd;
40 /* The child's stdout. */
41 int stdout_fd;
42 /* The child's stderr. */
43 int stderr_fd;
44 /* The child's PID. */
45 pid_t pid;
48 /* Create a new child process. All file descriptors except stdin, stdout and
49 * stderr are closed and privileges are dropped. All fields of the child
50 * struct except pid must be set. If a stdio file descriptor field has the
51 * special value of REDIRECT_DEV_NULL it is redirected from or to /dev/null.
52 * If it has the value REDIRECT_PIPE a pipe will be created and one end will be
53 * connected to the respective descriptor of the child. The file descriptor of
54 * the other end is stored in the field after the call. It is up to the caller
55 * to close the pipe descriptor(s). */
56 bool create_child(struct child_process *child);