From: dongshengyuan <545258830@qq.com> Date: Mon, 13 Jul 2026 05:54:14 +0000 (+0800) Subject: run: honor --no-block for trigger units X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8f86dff810e9974ec9bf62dc61d870131666095;p=thirdparty%2Fsystemd.git run: honor --no-block for trigger units Reproducer: unit=run-nb-trigger-$(date +%s) systemd-run --no-block --collect --unit="$unit" \ --socket-property=ListenStream=/proc/systemd-run-repro/socket \ /usr/bin/true echo $? Before, systemd-run still waited for the trigger unit job and propagated the socket start failure. With --no-block it should only verify and enqueue the request, as the service path already does. Follow-up for 3d161f991e16369aa59f447eb4cdb90af33261c8 --- diff --git a/src/run/run.c b/src/run/run.c index 63c0718ad94..ac6d3c01961 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -2808,9 +2808,11 @@ static int start_transient_trigger(sd_bus *bus, const char *suffix) { assert(bus); assert(suffix); - r = bus_wait_for_jobs_new(bus, &w); - if (r < 0) - return log_error_errno(r, "Could not watch jobs: %m"); + if (!arg_no_block) { + r = bus_wait_for_jobs_new(bus, &w); + if (r < 0) + return log_error_errno(r, "Could not watch jobs: %m"); + } if (arg_unit) { switch (unit_name_to_type(arg_unit)) { @@ -2875,10 +2877,12 @@ static int start_transient_trigger(sd_bus *bus, const char *suffix) { if (r < 0) return bus_log_parse_error(r); - r = bus_wait_for_jobs_one(w, object, arg_quiet ? 0 : BUS_WAIT_JOBS_LOG_ERROR, - arg_runtime_scope == RUNTIME_SCOPE_USER ? STRV_MAKE_CONST("--user") : NULL); - if (r < 0) - return r; + if (w) { + r = bus_wait_for_jobs_one(w, object, arg_quiet ? 0 : BUS_WAIT_JOBS_LOG_ERROR, + arg_runtime_scope == RUNTIME_SCOPE_USER ? STRV_MAKE_CONST("--user") : NULL); + if (r < 0) + return r; + } if (!arg_quiet) { log_info("Running %s as unit: %s", suffix + 1, trigger); diff --git a/test/units/TEST-74-AUX-UTILS.run.sh b/test/units/TEST-74-AUX-UTILS.run.sh index bdb0fd1a7eb..ec73a0bd1c4 100755 --- a/test/units/TEST-74-AUX-UTILS.run.sh +++ b/test/units/TEST-74-AUX-UTILS.run.sh @@ -205,6 +205,13 @@ grep -q "^SocketMode=0644$" "/run/systemd/transient/$UNIT.socket" grep -qE "^ExecStart=.*true.*$" "/run/systemd/transient/$UNIT.service" systemctl stop "$UNIT.socket" "$UNIT.service" || : +UNIT="socket-no-block-$RANDOM" +systemd-run --no-block --collect \ + --unit="$UNIT" \ + --socket-property=ListenStream=/proc/systemd-run-repro/socket \ + true +systemctl stop "$UNIT.socket" "$UNIT.service" || : + : "Job mode" systemd-run --job-mode=help (! systemd-run --job-mode=foo --scope true)