]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/exec-util.h
man: Remove OSConfig project mentioning for systemd-confext
[thirdparty/systemd.git] / src / shared / exec-util.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5
6 #include "time-util.h"
7
8 typedef int (*gather_stdout_callback_t) (int fd, void *arg);
9
10 enum {
11 STDOUT_GENERATE, /* from generators to helper process */
12 STDOUT_COLLECT, /* from helper process to main process */
13 STDOUT_CONSUME, /* process data in main process */
14 _STDOUT_CONSUME_MAX,
15 };
16
17 typedef enum {
18 EXEC_DIR_NONE = 0, /* No execdir flags */
19 EXEC_DIR_PARALLEL = 1 << 0, /* Execute scripts in parallel, if possible */
20 EXEC_DIR_IGNORE_ERRORS = 1 << 1, /* Ignore non-zero exit status of scripts */
21 EXEC_DIR_SET_SYSTEMD_EXEC_PID = 1 << 2, /* Set $SYSTEMD_EXEC_PID environment variable */
22 EXEC_DIR_SKIP_REMAINING = 1 << 3, /* Ignore remaining executions when one exit with 77. */
23 } ExecDirFlags;
24
25 typedef enum ExecCommandFlags {
26 EXEC_COMMAND_IGNORE_FAILURE = 1 << 0,
27 EXEC_COMMAND_FULLY_PRIVILEGED = 1 << 1,
28 EXEC_COMMAND_NO_SETUID = 1 << 2,
29 EXEC_COMMAND_AMBIENT_MAGIC = 1 << 3,
30 EXEC_COMMAND_NO_ENV_EXPAND = 1 << 4,
31 _EXEC_COMMAND_FLAGS_INVALID = -EINVAL,
32 } ExecCommandFlags;
33
34 int execute_strv(
35 const char *name,
36 char* const* paths,
37 const char *root,
38 usec_t timeout,
39 gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
40 void* const callback_args[_STDOUT_CONSUME_MAX],
41 char *argv[],
42 char *envp[],
43 ExecDirFlags flags);
44
45 int execute_directories(
46 const char* const* directories,
47 usec_t timeout,
48 gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
49 void* const callback_args[_STDOUT_CONSUME_MAX],
50 char *argv[],
51 char *envp[],
52 ExecDirFlags flags);
53
54 int exec_command_flags_from_strv(char **ex_opts, ExecCommandFlags *flags);
55 int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ex_opts);
56
57 extern const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX];
58
59 const char* exec_command_flags_to_string(ExecCommandFlags i);
60 ExecCommandFlags exec_command_flags_from_string(const char *s);
61
62 int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]);
63
64 int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) _sentinel_;