src/process.{c,h}: add GError handling
[vlock.git] / src / process.h
blob2a42035e69bcc9187061b82231df216e8289728f
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 #pragma once
16 #include <stdbool.h>
17 #include <sys/types.h>
18 #include <glib.h>
20 /* Errors */
21 #define VLOCK_PROCESS_ERROR vlock_process_error_quark()
22 GQuark vlock_plugin_error_quark(void);
24 enum {
25 VLOCK_PROCESS_ERROR_FAILED,
28 /* Wait for the given amount of time for the death of the given child process.
29 * If the child process dies in the given amount of time or already was dead
30 * true is returned and false otherwise. */
31 bool wait_for_death(pid_t pid, long sec, long usec);
33 /* Try hard to kill the given child process. */
34 void ensure_death(pid_t pid);
36 #define NO_REDIRECT (-2)
37 #define REDIRECT_DEV_NULL (-3)
38 #define REDIRECT_PIPE (-4)
40 struct child_process {
41 /* Function that will be run in the child. */
42 int (*function)(void *argument);
43 /* Argument for the function. */
44 void *argument;
45 /* First argument to execv. */
46 const char *path;
47 /* Second argument to execv. */
48 const char *const *argv;
49 /* The child's stdin. */
50 int stdin_fd;
51 /* The child's stdout. */
52 int stdout_fd;
53 /* The child's stderr. */
54 int stderr_fd;
55 /* The child's PID. */
56 pid_t pid;
59 /* Create a new child process. All file descriptors except stdin, stdout and
60 * stderr are closed and privileges are dropped. All fields of the child
61 * struct except pid must be set. If a stdio file descriptor field has the
62 * special value of REDIRECT_DEV_NULL it is redirected from or to /dev/null.
63 * If it has the value REDIRECT_PIPE a pipe will be created and one end will be
64 * connected to the respective descriptor of the child. The file descriptor of
65 * the other end is stored in the field after the call. It is up to the caller
66 * to close the pipe descriptor(s). */
67 bool create_child(struct child_process *child, GError **error);