mirror of
https://github.com/systemd/systemd.git
synced 2026-08-10 17:14:31 +00:00
run: accept explicit trigger unit names
Reproducer:
unit=run-explicit-path-$(date +%s)
systemd-run --unit="$unit.path" \
--path-property=PathExists=/tmp \
/bin/true
echo $?
Before, an explicit .path unit name was not recognized as the
trigger unit. It was mangled again as a service name, so PID 1 rejected
the transient request with an already-loaded unit conflict.
Follow-up for d59ef3e243
This commit is contained in:
@@ -2815,7 +2815,9 @@ static int start_transient_trigger(sd_bus *bus, const char *suffix) {
|
||||
}
|
||||
|
||||
if (arg_unit) {
|
||||
switch (unit_name_to_type(arg_unit)) {
|
||||
UnitType t = unit_name_to_type(arg_unit);
|
||||
|
||||
switch (t) {
|
||||
|
||||
case UNIT_SERVICE:
|
||||
service = strdup(arg_unit);
|
||||
@@ -2827,7 +2829,14 @@ static int start_transient_trigger(sd_bus *bus, const char *suffix) {
|
||||
return log_error_errno(r, "Failed to change unit suffix: %m");
|
||||
break;
|
||||
|
||||
case UNIT_PATH:
|
||||
case UNIT_SOCKET:
|
||||
case UNIT_TIMER:
|
||||
if (!streq(suffix + 1, unit_type_to_string(t)))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Specified unit '%s' does not match requested %s trigger.",
|
||||
arg_unit, suffix + 1);
|
||||
|
||||
trigger = strdup(arg_unit);
|
||||
if (!trigger)
|
||||
return log_oom();
|
||||
|
||||
@@ -189,6 +189,17 @@ grep -q "^PathChanged=/root/bar$" "/run/systemd/transient/$UNIT.path"
|
||||
grep -qE "^ExecStart=.*true.*$" "/run/systemd/transient/$UNIT.service"
|
||||
systemctl stop "$UNIT.path" "$UNIT.service" || :
|
||||
|
||||
UNIT="path-explicit-$RANDOM.path"
|
||||
SERVICE="${UNIT%.path}.service"
|
||||
systemd-run --remain-after-exit \
|
||||
--unit="$UNIT" \
|
||||
--path-property=PathExists=/tmp \
|
||||
true
|
||||
systemctl cat "$UNIT" "$SERVICE"
|
||||
grep -q "^PathExists=/tmp$" "/run/systemd/transient/$UNIT"
|
||||
grep -qE "^ExecStart=.*true.*$" "/run/systemd/transient/$SERVICE"
|
||||
systemctl stop "$UNIT" "$SERVICE" || :
|
||||
|
||||
: "Transient socket unit"
|
||||
UNIT="socket-0-$RANDOM"
|
||||
systemd-run --remain-after-exit \
|
||||
@@ -206,6 +217,17 @@ 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-explicit-$RANDOM.socket"
|
||||
SERVICE="${UNIT%.socket}.service"
|
||||
systemd-run --remain-after-exit \
|
||||
--unit="$UNIT" \
|
||||
--socket-property=ListenFIFO=/tmp/socket-explicit.fifo \
|
||||
true
|
||||
systemctl cat "$UNIT" "$SERVICE"
|
||||
grep -q "^ListenFIFO=/tmp/socket-explicit.fifo$" "/run/systemd/transient/$UNIT"
|
||||
grep -qE "^ExecStart=.*true.*$" "/run/systemd/transient/$SERVICE"
|
||||
systemctl stop "$UNIT" "$SERVICE" || :
|
||||
|
||||
UNIT="socket-no-block-$RANDOM"
|
||||
systemd-run --no-block --collect \
|
||||
--unit="$UNIT" \
|
||||
|
||||
Reference in New Issue
Block a user