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 } ExecDirFlags;
23 
24 typedef enum ExecCommandFlags {
25         EXEC_COMMAND_IGNORE_FAILURE   = 1 << 0,
26         EXEC_COMMAND_FULLY_PRIVILEGED = 1 << 1,
27         EXEC_COMMAND_NO_SETUID        = 1 << 2,
28         EXEC_COMMAND_AMBIENT_MAGIC    = 1 << 3,
29         EXEC_COMMAND_NO_ENV_EXPAND    = 1 << 4,
30         _EXEC_COMMAND_FLAGS_INVALID   = -EINVAL,
31 } ExecCommandFlags;
32 
33 int execute_directories(
34                 const char* const* directories,
35                 usec_t timeout,
36                 gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
37                 void* const callback_args[_STDOUT_CONSUME_MAX],
38                 char *argv[],
39                 char *envp[],
40                 ExecDirFlags flags);
41 
42 int exec_command_flags_from_strv(char **ex_opts, ExecCommandFlags *flags);
43 int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ex_opts);
44 
45 extern const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX];
46 
47 const char* exec_command_flags_to_string(ExecCommandFlags i);
48 ExecCommandFlags exec_command_flags_from_string(const char *s);
49 
50 int fexecve_or_execve(int executable_fd, const char *executable, char *const argv[], char *const envp[]);
51 
52 int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret_pid, const char *path, ...) _sentinel_;
53