systemd-run: reject unsupported option combinations (#43003)
Boundary tests were conducted on the "run" command tool, and the identified issues were resolved.
This commit is contained in:
@@ -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@ \
|
||||
@@ -111,10 +113,16 @@ systemd-run --scope --slice-inherit --slice=foo \
|
||||
bash -xec '[[ "$(</proc/self/cgroup)" =~ /system\.slice/system-foo\.slice/run-.+\.scope$ ]]'
|
||||
# We should inherit caller's environment
|
||||
systemd-run --scope bash -xec '[[ "$PARENT_FOO" == bar ]]'
|
||||
systemd-run --scope --uid=testuser \
|
||||
bash -xec '[[ " $(id -G) " != *" 0 "* ]]'
|
||||
systemd-run --scope --gid=testuser \
|
||||
bash -xec '[[ " $(id -G) " != *" 0 "* ]]'
|
||||
systemd-run --scope \
|
||||
--property=RuntimeMaxSec=10 \
|
||||
--property=RuntimeMaxSec=infinity \
|
||||
true
|
||||
(! systemd-run --scope --ignore-failure false)
|
||||
(! systemd-run --scope --json=short true)
|
||||
|
||||
: "Transient scope (user daemon)"
|
||||
# FIXME: https://github.com/systemd/systemd/issues/27883
|
||||
@@ -188,6 +196,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 \
|
||||
@@ -205,6 +224,24 @@ 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" \
|
||||
--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)
|
||||
@@ -222,6 +259,9 @@ systemd-run --wait --pty true
|
||||
systemd-run --wait --machine=.host --pty true
|
||||
systemd-run --json=short true | jq . >/dev/null
|
||||
systemd-run --json=pretty true | jq . >/dev/null
|
||||
(! systemd-run --wait --pipe --json=short true)
|
||||
(! systemd-run --json=short --on-active=30s true)
|
||||
(! systemd-run --wait --verbose --json=short true)
|
||||
(! SHELL=/bin/false systemd-run --quiet --shell)
|
||||
|
||||
(! systemd-run)
|
||||
|
||||
Reference in New Issue
Block a user