]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: reject waiting for remain-after-exit services 43003/head
authordongshengyuan <545258830@qq.com>
Mon, 13 Jul 2026 06:23:26 +0000 (14:23 +0800)
committerdongshengyuan <545258830@qq.com>
Tue, 14 Jul 2026 04:03:22 +0000 (12:03 +0800)
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
src/run/run.c
test/units/TEST-74-AUX-UTILS.run.sh

index d0eec8cf0daaa2504b3cc6da1856f52bee7f9712..e9c638436353c4c0192134f0c5c21a67eda229d5 100644 (file)
         <listitem><para>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
         <varname>RemainAfterExit=</varname> in
-        <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
+        <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
+        option may not be combined with <option>--wait</option>, <option>--scope</option>, <option>--pty</option>,
+        <option>--pty-late</option>, or <option>--pipe</option>.
         </para>
 
         <xi:include href="version-info.xml" xpointer="v207"/>
         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 <option>--quiet</option>.
-        This option may not be combined with <option>--no-block</option>, <option>--scope</option> or the various
-        path, socket, or timer options.</para>
+        This option may not be combined with <option>--no-block</option>,
+        <option>--remain-after-exit</option>, <option>--scope</option> or the various path, socket, or timer
+        options.</para>
 
         <xi:include href="version-info.xml" xpointer="v232"/></listitem>
       </varlistentry>
index dd5a207455579a459426d8151b050f64ea3a8cee..85256a2b1b11720282cdb4fc273286078ffff03e 100644 (file)
@@ -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)
index c85117e135e239fde200f006558c3b5ec93e5f7b..1c0efdf08fae4b0779365edf46c9f3a964659128 100755 (executable)
@@ -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@ \