]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: avoid test-fdstore failing units when exiting
authorLuca Boccassi <luca.boccassi@gmail.com>
Mon, 18 May 2026 14:49:23 +0000 (15:49 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 21 May 2026 09:13:17 +0000 (10:13 +0100)
This is used as payload, so ensure the wrapping unit/container
doesn't register a failure when this exits

Follow-up for 9de91f0f4c715b278637af8b73cabac892d7e000

src/test/test-fdstore.c
test/units/TEST-13-NSPAWN.unpriv.sh
test/units/TEST-91-LIVEUPDATE.sh

index 6469d396e1cea27826c4bcb457dd6ebb40271e86..0d7c16faf7d369ba1580b4b8b8e6d06c69abdc5b 100644 (file)
@@ -6,6 +6,7 @@
  *
  * This binary is intentionally linked against libsystemd only so that it can go in the minimal image. */
 
+#include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -28,6 +29,10 @@ static void closep(int *fd) {
         *fd = -EBADF;
 }
 
+static _Noreturn void exit_handler(int sig) {
+        _exit(EXIT_SUCCESS);
+}
+
 static int push_one(const char *fdname, const char *content) {
         _cleanup_(closep) int fd = -EBADF;
         int r;
@@ -159,8 +164,16 @@ int main(int argc, char *argv[]) {
         if (r != EXIT_SUCCESS)
                 return r;
 
-        /* On success, become sleep so if we are a container payload it can stay alive. */
-        execlp("sleep", "sleep", "infinity", (char *) NULL);
-        fprintf(stderr, "execlp(sleep) failed: %m\n");
-        return EXIT_FAILURE;
+        /* On success, stay alive so if we are a container payload we keep it running. Install handlers
+         * for the signals an outer supervisor may use to terminate us, so we exit cleanly (with status 0)
+         * and the container service ends up in 'inactive' rather than 'failed'. */
+        struct sigaction sa = { .sa_handler = exit_handler };
+        if (sigaction(SIGTERM, &sa, /* __oact= */ NULL) < 0 ||
+            sigaction(SIGINT, &sa, /* __oact= */ NULL) < 0) {
+                fprintf(stderr, "Failed to install signal handlers: %m\n");
+                return EXIT_FAILURE;
+        }
+
+        for (;;)
+                pause();
 }
index 19b1d445c89d97dc27080dd52bca88ec6249bbd3..f14e3121d41d6b1a908291bcee3347e161caf0b7 100755 (executable)
@@ -336,7 +336,7 @@ systemd-dissect --shift /home/testuser/.local/state/machines/fdstore foreign
 run0 -u testuser mkdir -p .config/systemd/nspawn/
 run0 -u testuser -i "cat >.config/systemd/nspawn/fdstore.nspawn <<EOF
 [Exec]
-KillSignal=SIGKILL
+KillSignal=SIGTERM
 EOF"
 
 run0 -u testuser mkdir -p ".config/systemd/user/systemd-nspawn@fdstore.service.d/"
index 1d2df255cf2c29ac60e903bc835128e440f24777..802aaae1b5d499036516d264b436c9cf3fda732a 100755 (executable)
@@ -92,7 +92,7 @@ EOF
     mkdir -p /run/systemd/nspawn
     cat >/run/systemd/nspawn/fdstore.nspawn <<EOF
 [Exec]
-KillSignal=SIGKILL
+KillSignal=SIGTERM
 EOF
     n_nspawn_fds=$(systemctl show -P NFileDescriptorStore systemd-nspawn@fdstore.service)
     test "${n_nspawn_fds}" -ge 2
@@ -170,7 +170,7 @@ EOF
     mkdir -p /run/systemd/nspawn
     cat >/run/systemd/nspawn/fdstore.nspawn <<EOF
 [Exec]
-KillSignal=SIGKILL
+KillSignal=SIGTERM
 EOF
 
     systemctl start systemd-nspawn@fdstore.service