2020-11-09 13:23:58 +09:00
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2018-06-25 13:04:59 +09:00
# pragma once
2017-01-22 12:35:08 -05:00
2017-01-22 15:22:37 -05:00
# include <stdbool.h>
2017-01-22 12:35:08 -05:00
# include "time-util.h"
2017-01-22 15:22:37 -05:00
typedef int ( * gather_stdout_callback_t ) ( int fd , void * arg ) ;
enum {
STDOUT_GENERATE , /* from generators to helper process */
STDOUT_COLLECT , /* from helper process to main process */
STDOUT_CONSUME , /* process data in main process */
_STDOUT_CONSUME_MAX ,
} ;
2018-09-09 03:18:45 +02:00
typedef enum {
2021-02-01 00:51:33 +09:00
EXEC_DIR_NONE = 0 , /* No execdir flags */
EXEC_DIR_PARALLEL = 1 < < 0 , /* Execute scripts in parallel, if possible */
EXEC_DIR_IGNORE_ERRORS = 1 < < 1 , /* Ignore non-zero exit status of scripts */
EXEC_DIR_SET_SYSTEMD_EXEC_PID = 1 < < 2 , /* Set $SYSTEMD_EXEC_PID environment variable */
2023-03-16 11:34:14 +09:00
EXEC_DIR_SKIP_REMAINING = 1 < < 3 , /* Ignore remaining executions when one exit with 77. */
2018-09-09 03:18:45 +02:00
} ExecDirFlags ;
2019-02-20 14:53:58 -08:00
typedef enum ExecCommandFlags {
EXEC_COMMAND_IGNORE_FAILURE = 1 < < 0 ,
EXEC_COMMAND_FULLY_PRIVILEGED = 1 < < 1 ,
EXEC_COMMAND_NO_SETUID = 1 < < 2 ,
EXEC_COMMAND_AMBIENT_MAGIC = 1 < < 3 ,
EXEC_COMMAND_NO_ENV_EXPAND = 1 < < 4 ,
2021-02-16 23:19:37 +01:00
_EXEC_COMMAND_FLAGS_INVALID = - EINVAL ,
2019-02-20 14:53:58 -08:00
} ExecCommandFlags ;
2023-03-16 11:16:51 +09:00
int execute_strv (
const char * name ,
char * const * paths ,
2023-04-16 15:31:10 +09:00
const char * root ,
2023-03-16 11:16:51 +09:00
usec_t timeout ,
gather_stdout_callback_t const callbacks [ _STDOUT_CONSUME_MAX ] ,
void * const callback_args [ _STDOUT_CONSUME_MAX ] ,
char * argv [ ] ,
char * envp [ ] ,
ExecDirFlags flags ) ;
2017-01-22 15:22:37 -05:00
int execute_directories (
const char * const * directories ,
usec_t timeout ,
gather_stdout_callback_t const callbacks [ _STDOUT_CONSUME_MAX ] ,
void * const callback_args [ _STDOUT_CONSUME_MAX ] ,
2018-09-12 18:19:13 +01:00
char * argv [ ] ,
2018-09-09 03:18:45 +02:00
char * envp [ ] ,
ExecDirFlags flags ) ;
2017-02-10 21:49:01 -05:00
2019-02-20 14:53:58 -08:00
int exec_command_flags_from_strv ( char * * ex_opts , ExecCommandFlags * flags ) ;
int exec_command_flags_to_strv ( ExecCommandFlags flags , char * * * ex_opts ) ;
2017-02-10 21:49:01 -05:00
extern const gather_stdout_callback_t gather_environment [ _STDOUT_CONSUME_MAX ] ;
2019-02-20 14:53:58 -08:00
const char * exec_command_flags_to_string ( ExecCommandFlags i ) ;
ExecCommandFlags exec_command_flags_from_string ( const char * s ) ;
2020-09-18 14:28:08 +02:00
int fexecve_or_execve ( int executable_fd , const char * executable , char * const argv [ ] , char * const envp [ ] ) ;
2021-07-23 11:20:39 +02:00
2021-07-29 16:36:15 +02:00
int fork_agent ( const char * name , const int except [ ] , size_t n_except , pid_t * ret_pid , const char * path , . . . ) _sentinel_ ;