*
* 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>
*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;
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();
}
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
mkdir -p /run/systemd/nspawn
cat >/run/systemd/nspawn/fdstore.nspawn <<EOF
[Exec]
-KillSignal=SIGKILL
+KillSignal=SIGTERM
EOF
systemctl start systemd-nspawn@fdstore.service