| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "shared-forward.h" |
| 5 |
|
| 6 |
typedef int (*gather_stdout_callback_t) (int fd, void *arg); |
| 7 |
|
| 8 |
enum { |
| 9 |
STDOUT_GENERATE, /* from generators to helper process */ |
| 10 |
STDOUT_COLLECT, /* from helper process to main process */ |
| 11 |
STDOUT_CONSUME, /* process data in main process */ |
| 12 |
_STDOUT_CONSUME_MAX, |
| 13 |
}; |
| 14 |
|
| 15 |
typedef enum ExecDirFlags { |
| 16 |
EXEC_DIR_PARALLEL = 1 << 0, /* Execute scripts in parallel, if possible */ |
| 17 |
EXEC_DIR_IGNORE_ERRORS = 1 << 1, /* Ignore non-zero exit status of scripts */ |
| 18 |
EXEC_DIR_SET_SYSTEMD_EXEC_PID = 1 << 2, /* Set $SYSTEMD_EXEC_PID environment variable */ |
| 19 |
EXEC_DIR_SKIP_REMAINING = 1 << 3, /* Ignore remaining executions when one exit with 77. */ |
| 20 |
EXEC_DIR_WARN_WORLD_WRITABLE = 1 << 4, /* Warn if world writable files are found */ |
| 21 |
} ExecDirFlags; |
| 22 |
|
| 23 |
int execute_strv( |
| 24 |
const char *name, |
| 25 |
char * const *paths, |
| 26 |
const char *root, |
| 27 |
usec_t timeout, |
| 28 |
gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX], |
| 29 |
void * const callback_args[_STDOUT_CONSUME_MAX], |
| 30 |
char *argv[], |
| 31 |
char *envp[], |
| 32 |
ExecDirFlags flags); |
| 33 |
|
| 34 |
int execute_directories( |
| 35 |
const char *name, |
| 36 |
const char * const *directories, |
| 37 |
usec_t timeout, |
| 38 |
gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX], |
| 39 |
void * const callback_args[_STDOUT_CONSUME_MAX], |
| 40 |
char *argv[], |
| 41 |
char *envp[], |
| 42 |
ExecDirFlags flags); |
| 43 |
|
| 44 |
extern const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX]; |
| 45 |
|
| 46 |
typedef enum ExecCommandFlags { |
| 47 |
EXEC_COMMAND_IGNORE_FAILURE = 1 << 0, |
| 48 |
EXEC_COMMAND_FULLY_PRIVILEGED = 1 << 1, |
| 49 |
EXEC_COMMAND_NO_SETUID = 1 << 2, |
| 50 |
EXEC_COMMAND_NO_ENV_EXPAND = 1 << 3, |
| 51 |
EXEC_COMMAND_VIA_SHELL = 1 << 4, |
| 52 |
_EXEC_COMMAND_FLAGS_INVALID = -EINVAL, |
| 53 |
_EXEC_COMMAND_FLAGS_ALL = (1 << 5) -1, |
| 54 |
} ExecCommandFlags; |
| 55 |
|
| 56 |
int exec_command_flags_from_strv(char * const *ex_opts, ExecCommandFlags *ret); |
| 57 |
int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ret); |
| 58 |
|
| 59 |
DECLARE_STRING_TABLE_LOOKUP(exec_command_flags, ExecCommandFlags); |
| 60 |
|
| 61 |
int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]); |
| 62 |
|
| 63 |
int shall_fork_agent(void); |
| 64 |
int _fork_agent(const char *name, char * const *argv, const int except[], size_t n_except, PidRef *ret); |
| 65 |
#define fork_agent(name, except, n_except, ret, ...) _fork_agent(name, STRV_MAKE(__VA_ARGS__), except, n_except, ret) |