TEST-80-NOTIFYACCESS: Add notify-reload signal handler validation test
Add a new integration test to verify the signal handler validation for Type=notify-reload services, as introduced in the previous commit. The test adds a shell harness and four service files to cover all scenarios: 1. `notify-reload-no-handler.service`: Verifies that the service fails to start with Result=protocol when the handler is missing at the first READY=1. 2. `notify-reload-sigstop.service`: Verifies that SIGSTOP is exempt from handler validation because it cannot be caught or blocked. 3. `notify-reload-toggle-handler.service`: Verifies that removing the handler at runtime results in a warning on reload, but the signal is still sent, causing the service to terminate from unhandled SIGHUP. 4. `notify-reload-well-behaved.service`: Verifies the happy path where a service with a handler starts and reloads successfully. Use bounded FIFO operations and journal cursors so failures are prompt and log assertions cannot race a relative time window.
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
MODE="${1:-well-behaved}"
|
||||
FIFO_IN="${2:-/tmp/reload-test-fifo-in}"
|
||||
FIFO_OUT="${3:-/tmp/reload-test-fifo-out}"
|
||||
|
||||
handle_signal() {
|
||||
echo "reload" >"$FIFO_OUT"
|
||||
systemd-notify --reloading
|
||||
systemd-notify --ready --status="Reloaded"
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
no-handler)
|
||||
;;
|
||||
toggle-handler|well-behaved)
|
||||
trap 'handle_signal' HUP
|
||||
;;
|
||||
*)
|
||||
echo "Unknown mode: $MODE" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
systemd-notify --ready --status="Started with mode=$MODE"
|
||||
|
||||
while read -r cmd < "$FIFO_IN"; do
|
||||
case "$cmd" in
|
||||
remove-handler)
|
||||
trap - HUP
|
||||
echo "handler-removed" >"$FIFO_OUT"
|
||||
;;
|
||||
exit)
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Unknown command: $cmd" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Test notify-reload without signal handler
|
||||
|
||||
[Service]
|
||||
Type=notify-reload
|
||||
ExecStart=/usr/lib/systemd/tests/testdata/TEST-80-NOTIFYACCESS.units/notify-reload-harness.sh no-handler /tmp/reload-nohandler-in /tmp/reload-nohandler-out
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Test notify-reload with SIGSTOP
|
||||
|
||||
[Service]
|
||||
Type=notify-reload
|
||||
ReloadSignal=SIGSTOP
|
||||
ExecStart=/usr/lib/systemd/tests/testdata/TEST-80-NOTIFYACCESS.units/notify-reload-harness.sh no-handler /tmp/reload-sigstop-in /tmp/reload-sigstop-out
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Test notify-reload with handler that can be removed
|
||||
|
||||
[Service]
|
||||
Type=notify-reload
|
||||
ExecStart=/usr/lib/systemd/tests/testdata/TEST-80-NOTIFYACCESS.units/notify-reload-harness.sh toggle-handler /tmp/reload-toggle-in /tmp/reload-toggle-out
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Test notify-reload with proper signal handler
|
||||
|
||||
[Service]
|
||||
Type=notify-reload
|
||||
ExecStart=/usr/lib/systemd/tests/testdata/TEST-80-NOTIFYACCESS.units/notify-reload-harness.sh well-behaved /tmp/reload-wellbehaved-in /tmp/reload-wellbehaved-out
|
||||
Reference in New Issue
Block a user