From 06247b0804fcd75f26a329b35ec92033f6c56bd7 Mon Sep 17 00:00:00 2001 From: dongshengyuan <545258830@qq.com> Date: Mon, 13 Jul 2026 14:23:26 +0800 Subject: [PATCH] run: reject waiting for remain-after-exit services Reproducer: unit=run-wait-rae-$(date +%s) sudo timeout 3s systemd-run --wait --remain-after-exit \ --unit="$unit" /bin/true echo $? systemctl is-active "$unit.service" Before, the command timed out with exit status 124 while the service stayed active. --wait waits for deactivation, but RemainAfterExit=yes keeps the service active after the command exits. Follow-up for 2a453c2ee3090e1942bfd962262f3eff0adbfa97 --- man/systemd-run.xml | 9 ++++++--- src/run/run.c | 8 ++++++++ test/units/TEST-74-AUX-UTILS.run.sh | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/man/systemd-run.xml b/man/systemd-run.xml index d0eec8cf0da..e9c63843635 100644 --- a/man/systemd-run.xml +++ b/man/systemd-run.xml @@ -216,7 +216,9 @@ After the service process has terminated, keep the service around until it is explicitly stopped. This is useful to collect runtime information about the service after it finished running. Also see RemainAfterExit= in - systemd.service5. + systemd.service5. This + option may not be combined with , , , + , or . @@ -529,8 +531,9 @@ completed). On exit, terse information about the unit's runtime is shown, including total runtime (as well as CPU, memory, IO, and IP accounting data, if the corresponding cgroup accounting settings are enabled) and the exit code and status of the main process. This output may be suppressed with . - This option may not be combined with , or the various - path, socket, or timer options. + This option may not be combined with , + , or the various path, socket, or timer + options. diff --git a/src/run/run.c b/src/run/run.c index dd5a2074555..85256a2b1b1 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -717,6 +717,10 @@ static int parse_argv(int argc, char *argv[]) { if (arg_no_block) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--pty/--pty-late/--pipe is not compatible with --no-block."); + + if (arg_remain_after_exit) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "--pty/--pty-late/--pipe is not compatible with --remain-after-exit."); } if (arg_stdio == ARG_STDIO_PTY && arg_pty_late && streq_ptr(arg_service_type, "oneshot")) @@ -761,6 +765,10 @@ static int parse_argv(int argc, char *argv[]) { if (arg_scope) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--wait may not be combined with --scope."); + + if (arg_remain_after_exit) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "--wait may not be combined with --remain-after-exit."); } if (arg_scope && arg_root_directory) diff --git a/test/units/TEST-74-AUX-UTILS.run.sh b/test/units/TEST-74-AUX-UTILS.run.sh index c85117e135e..1c0efdf08fa 100755 --- a/test/units/TEST-74-AUX-UTILS.run.sh +++ b/test/units/TEST-74-AUX-UTILS.run.sh @@ -72,6 +72,8 @@ systemctl cat "$UNIT" grep -q "^Type=oneshot" "/run/systemd/transient/$UNIT.service" systemctl stop "$UNIT" (! systemctl cat "$UNIT") +(! systemd-run --wait --remain-after-exit true) +(! systemd-run --pipe --remain-after-exit true) : "Transient service (user daemon)" systemd-run --wait --pipe --user --machine=testuser@ \ -- 2.47.3