]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
manager: pass monitor metadata in more cases 22460/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 1 Mar 2022 09:49:26 +0000 (10:49 +0100)
committerLuca Boccassi <bluca@debian.org>
Thu, 10 Mar 2022 14:51:28 +0000 (14:51 +0000)
The first ExecStartPre or the first ExecStart commands would get the metadata,
but not the subsequent ones. Also check that we do not pass it in
ExecStartPost.

src/core/service.c
test/units/testsuite-68.sh

index 942bc7c0ff71f33ae91a2cef9b74f6c329c07001..acf3df77da4b0e5a258a3d2ba729ddc92cb49935 100644 (file)
@@ -2459,6 +2459,7 @@ static void service_run_next_control(Service *s) {
                           EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_IS_CONTROL|
                           (IN_SET(s->control_command_id, SERVICE_EXEC_CONDITION, SERVICE_EXEC_START_PRE, SERVICE_EXEC_STOP_POST) ? EXEC_APPLY_TTY_STDIN : 0)|
                           (IN_SET(s->control_command_id, SERVICE_EXEC_STOP, SERVICE_EXEC_STOP_POST) ? EXEC_SETENV_RESULT : 0)|
+                          (IN_SET(s->control_command_id, SERVICE_EXEC_START_PRE, SERVICE_EXEC_START) ? EXEC_SETENV_MONITOR_RESULT : 0)|
                           (IN_SET(s->control_command_id, SERVICE_EXEC_START_POST, SERVICE_EXEC_RELOAD, SERVICE_EXEC_STOP, SERVICE_EXEC_STOP_POST) ? EXEC_CONTROL_CGROUP : 0),
                           &s->control_pid);
         if (r < 0)
@@ -2495,7 +2496,7 @@ static void service_run_next_main(Service *s) {
         r = service_spawn(s,
                           s->main_command,
                           s->timeout_start_usec,
-                          EXEC_PASS_FDS|EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN|EXEC_SET_WATCHDOG,
+                          EXEC_PASS_FDS|EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN|EXEC_SET_WATCHDOG|EXEC_SETENV_MONITOR_RESULT,
                           &pid);
         if (r < 0)
                 goto fail;
index 89c5d2618cc343b89c8b1e12964d475de07c00ce..3072a945758a6d8ada2ed7237cd6978751589913 100755 (executable)
@@ -169,8 +169,13 @@ cat >/run/systemd/system/testservice-failure-exit-handler-68.service <<EOF
 Description=TEST-68-PROPAGATE-EXIT-STATUS handle service exiting in failure
 
 [Service]
+# repeat the check to make sure that values are set correctly on repeated invocations
+Type=oneshot
 ExecStartPre=/tmp/check_on_failure.sh
+ExecStartPre=/tmp/check_on_failure.sh
+ExecStart=/tmp/check_on_failure.sh
 ExecStart=/tmp/check_on_failure.sh
+ExecStartPost=test -z '$MONITOR_SERVICE_RESULT'
 EOF
 
 # Template version.
@@ -179,9 +184,13 @@ cat >/run/systemd/system/testservice-failure-exit-handler-68-template@.service <
 Description=TEST-68-PROPAGATE-EXIT-STATUS handle service exiting in failure (template)
 
 [Service]
+Type=oneshot
 ExecStartPre=echo "triggered by %i"
 ExecStartPre=/tmp/check_on_failure.sh
+ExecStartPre=/tmp/check_on_failure.sh
+ExecStart=/tmp/check_on_failure.sh
 ExecStart=/tmp/check_on_failure.sh
+ExecStartPost=test -z '$MONITOR_SERVICE_RESULT'
 EOF
 
 systemctl daemon-reload