forked from google/xsecurelock
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_util.h
More file actions
69 lines (55 loc) · 2.12 KB
/
Copy pathprocess_util.h
File metadata and controls
69 lines (55 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: Apache-2.0
#ifndef XSECURELOCK_PROCESS_UTIL_H
#define XSECURELOCK_PROCESS_UTIL_H
#include <stdbool.h>
#include <unistd.h> // for pid_t
typedef void (*ChildSetupFn)(void *arg);
struct ChildStdioSetup {
int stdin_fd;
int stdout_fd;
int stderr_fd; // -1 leaves stderr inherited.
};
/*! \brief Fork a subprocess, but do not inherit our signal handlers.
*
* Otherwise behaves exactly like fork().
*/
pid_t ForkWithoutSigHandlers(void);
/*! \brief Starts a new process group.
*
* Must be called from a child process, which will become the process group
* leader. The process group will never die, unless killed using KillPgrp.
*/
void StartPgrp(void);
/*! \brief Forks and execs a helper subprocess.
*
* The child resets inherited signal handlers, optionally runs setup, then
* execs the helper. The parent receives the child PID as fork() would.
*/
pid_t ForkHelperChild(const char *label, ChildSetupFn setup, void *setup_arg,
const char *path, const char *const argv[]);
/*! \brief Forks and execs a helper subprocess in a new process group.
*
* Like ForkHelperChild(), but the child calls StartPgrp() before setup.
*/
pid_t ForkHelperPgrpChild(const char *label, ChildSetupFn setup,
void *setup_arg, const char *path,
const char *const argv[]);
/*! \brief Executes an arbitrary PATH-resolved program and exits on failure.
*/
void ExecvpOrExit(const char *path, char *const argv[]);
/*! \brief Moves configured descriptors onto child stdin/stdout/stderr.
*
* Any field set to -1 is left inherited. This function exits the current child
* process on failure.
*/
void ChildWireStdioOrExit(const struct ChildStdioSetup *setup);
/*! \brief Waits for exactly pid, retrying EINTR.
*
* \return true when the child was waited successfully, false on waitpid
* failure.
*/
bool WaitPidNoEintr(pid_t pid, int *status_out);
/*! \brief Logs a wait status and returns whether it represents success. */
bool LogWaitStatus(const char *label, int status);
void KillProcIfRunning(pid_t pid, int signo);
#endif // XSECURELOCK_PROCESS_UTIL_H