]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/exec-util: minor rearrangement, drop unused EXEC_DIR_NONE
authorMike Yuan <me@yhndnzj.com>
Fri, 11 Oct 2024 15:53:34 +0000 (17:53 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 14 Oct 2024 23:16:57 +0000 (01:16 +0200)
src/shared/exec-util.c
src/shared/exec-util.h
src/test/test-exec-util.c

index 628e777da176efb922dd0235c8740270db2f3496..cdd05cfda2bb649bc0c3a759f5befb1e23123033 100644 (file)
@@ -438,6 +438,12 @@ static int gather_environment_consume(int fd, void *arg) {
         return r;
 }
 
+const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX] = {
+        gather_environment_generate,
+        gather_environment_collect,
+        gather_environment_consume,
+};
+
 int exec_command_flags_from_strv(char * const *ex_opts, ExecCommandFlags *ret) {
         ExecCommandFlags flags = 0;
 
@@ -478,12 +484,6 @@ int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ret) {
         return 0;
 }
 
-const gather_stdout_callback_t gather_environment[] = {
-        gather_environment_generate,
-        gather_environment_collect,
-        gather_environment_consume,
-};
-
 static const char* const exec_command_strings[] = {
         "ignore-failure", /* EXEC_COMMAND_IGNORE_FAILURE */
         "privileged",     /* EXEC_COMMAND_FULLY_PRIVILEGED */
index 4565ddbee086ba3a6ff8a66c1f27ee82d90fcc65..7658085b25875d72732877c057a13ee10b07c387 100644 (file)
@@ -14,8 +14,7 @@ enum {
         _STDOUT_CONSUME_MAX,
 };
 
-typedef enum {
-        EXEC_DIR_NONE                 = 0,      /* No execdir flags */
+typedef enum ExecDirFlags {
         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 */
@@ -23,15 +22,6 @@ typedef enum {
         EXEC_DIR_WARN_WORLD_WRITABLE  = 1 << 4, /* Warn if world writable files are found */
 } ExecDirFlags;
 
-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,
-        _EXEC_COMMAND_FLAGS_INVALID   = -EINVAL,
-} ExecCommandFlags;
-
 int execute_strv(
                 const char *name,
                 char* const* paths,
@@ -52,11 +42,20 @@ int execute_directories(
                 char *envp[],
                 ExecDirFlags flags);
 
+extern const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX];
+
+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,
+        _EXEC_COMMAND_FLAGS_INVALID   = -EINVAL,
+} ExecCommandFlags;
+
 int exec_command_flags_from_strv(char * const *ex_opts, ExecCommandFlags *ret);
 int exec_command_flags_to_strv(ExecCommandFlags flags, char ***ret);
 
-extern const gather_stdout_callback_t gather_environment[_STDOUT_CONSUME_MAX];
-
 const char* exec_command_flags_to_string(ExecCommandFlags i);
 ExecCommandFlags exec_command_flags_from_string(const char *s);
 
index 301e02db0b84d9f85baea3fc6565e099f6e96e6c..8ccede252a50d0529410b0af03520d9e03c5c0a2 100644 (file)
@@ -402,7 +402,9 @@ TEST(error_catching) {
         if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
                 return;
 
-        r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, NULL, NULL, EXEC_DIR_NONE);
+        r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC,
+                                /* callbacks = */ NULL, /* callback_args = */ NULL,
+                                /* argv = */ NULL, /* envp = */ NULL, /* flags = */ 0);
 
         /* we should exit with the error code of the first script that failed */
         assert_se(r == 42);