document the change in prompt timeout handling
[vlock.git] / src / process.h
blob9c20ab3878853d475507a1577fedec3268446336
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_process_error_quark(void);
24 enum {
25 VLOCK_PROCESS_ERROR_FAILED,
26 VLOCK_PROCESS_ERROR_NOT_FOUND,
29 /* Wait for the given amount of time for the death of the given child process.
30 * If the child process dies in the given amount of time or already was dead
31 * true is returned and false otherwise. */
32 bool wait_for_death(pid_t pid, long sec, long usec);
34 /* Try hard to kill the given child process. */
35 void ensure_death(pid_t pid);
37 #define NO_REDIRECT (-2)
38 #define REDIRECT_DEV_NULL (-3)
39 #define REDIRECT_PIPE (-4)
41 struct child_process
43 /* Function that will be run in the child. */
44 int (*function)(void *argument);
45 /* Argument for the function. */
46 void *argument;
47 /* First argument to execv. */
48 const char *path;
49 /* Second argument to execv. */
50 const char *const *argv;
51 /* The child's stdin. */
52 int stdin_fd;
53 /* The child's stdout. */
54 int stdout_fd;
55 /* The child's stderr. */
56 int stderr_fd;
57 /* The child's PID. */
58 pid_t pid;
61 /* Create a new child process. All file descriptors except stdin, stdout and
62 * stderr are closed and privileges are dropped. All fields of the child
63 * struct except pid must be set. If a stdio file descriptor field has the
64 * special value of REDIRECT_DEV_NULL it is redirected from or to /dev/null.
65 * If it has the value REDIRECT_PIPE a pipe will be created and one end will be
66 * connected to the respective descriptor of the child. The file descriptor of
67 * the other end is stored in the field after the call. It is up to the caller
68 * to close the pipe descriptor(s). */
69 bool create_child(struct child_process *child, GError **error);