]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
exec-util: introduce EXEC_DIR_SKIP_REMAINING flag 26861/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 Mar 2023 02:34:14 +0000 (11:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Mar 2023 11:38:15 +0000 (20:38 +0900)
Will be used in later commits.

src/shared/exec-util.c
src/shared/exec-util.h

index 29f83818833f977da651f673971587312737a808..ac68cbc4cb16681e3d25cecb3cba6567310c4b67 100644 (file)
@@ -30,6 +30,8 @@
 #include "terminal-util.h"
 #include "tmpfile-util.h"
 
+#define EXIT_SKIP_REMAINING 77
+
 /* Put this test here for a lack of better place */
 assert_cc(EAGAIN == EWOULDBLOCK);
 
@@ -145,11 +147,22 @@ static int do_execute(
                                 return log_oom();
                         t = NULL;
                 } else {
-                        r = wait_for_terminate_and_check(t, pid, WAIT_LOG);
+                        bool skip_remaining = false;
+
+                        r = wait_for_terminate_and_check(t, pid, WAIT_LOG_ABNORMAL);
                         if (r < 0)
                                 return r;
-                        if (!FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS) && r > 0)
-                                return r;
+                        if (r > 0) {
+                                if (FLAGS_SET(flags, EXEC_DIR_SKIP_REMAINING) && r == EXIT_SKIP_REMAINING) {
+                                        log_info("%s succeeded with exit status %i, not executing remaining executables.", *path, r);
+                                        skip_remaining = true;
+                                } else if (FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS))
+                                        log_warning("%s failed with exit status %i, ignoring.", *path, r);
+                                else {
+                                        log_error("%s failed with exit status %i.", *path, r);
+                                        return r;
+                                }
+                        }
 
                         if (callbacks) {
                                 if (lseek(fd, 0, SEEK_SET) < 0)
@@ -159,6 +172,9 @@ static int do_execute(
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to process output from %s: %m", *path);
                         }
+
+                        if (skip_remaining)
+                                break;
                 }
         }
 
@@ -202,6 +218,8 @@ int execute_strv(
         pid_t executor_pid;
         int r;
 
+        assert(!FLAGS_SET(flags, EXEC_DIR_PARALLEL | EXEC_DIR_SKIP_REMAINING));
+
         if (strv_isempty(paths))
                 return 0;
 
index a18c108e1bd0d76516b11ac1e9e9b68706f746d5..91dbe3f3b4074f1900d3e0b0cffde4cbfe7b0550 100644 (file)
@@ -19,6 +19,7 @@ typedef enum {
         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 */
+        EXEC_DIR_SKIP_REMAINING       = 1 << 3, /* Ignore remaining executions when one exit with 77. */
 } ExecDirFlags;
 
 typedef enum ExecCommandFlags {