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 3d161f991e
This commit is contained in:
dongshengyuan
2026-07-13 13:54:14 +08:00
parent 4e67935b77
commit d8f86dff81
2 changed files with 18 additions and 7 deletions

View File

@@ -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);

View File

@@ -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)