From f217d493b4f874d956f64f131b70f9bad001c469 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 16 Jun 2025 19:00:10 +0200 Subject: [PATCH 01/14] test: add --map-auto to unshare call Signed-off-by: Joachim Wiberg --- test/lib/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/start.sh b/test/lib/start.sh index b7698ee7..689abd8b 100755 --- a/test/lib/start.sh +++ b/test/lib/start.sh @@ -41,7 +41,7 @@ export PATH # Not supported by Busybox unshare: # --cgroup --time exec "$unshare" \ - --user --map-root-user \ + --user --map-root-user --map-auto \ --fork --pid --mount-proc \ --mount \ --mount-proc \ From 91f7a75beef27ef3b6c7b7a810d07880859f061f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 13:34:46 +0200 Subject: [PATCH 02/14] api: ensure socket is non-blocking Also, remember to refactor the client socket handling to prevent blocking PID 1. Signed-off-by: Joachim Wiberg --- src/api.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/api.c b/src/api.c index 69b2f228..02987c17 100644 --- a/src/api.c +++ b/src/api.c @@ -349,6 +349,12 @@ static void api_cb(uev_t *w, void *arg, int events) goto error; } + /* + * TODO: refactor to use accept4() and a new uev handler for the + * client socket instead of risking blocking PID 1 if the client + * is misbehaving. + */ +// sd = accept4(w->fd, NULL, NULL, SOCK_NONBLOCK); sd = accept(w->fd, NULL, NULL); if (sd < 0) { err(1, "Failed serving API request"); @@ -613,7 +619,7 @@ int api_init(uev_ctx_t *ctx) int sd; dbg("Setting up external API socket ..."); - sd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0); + sd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); if (-1 == sd) { err(1, "Failed starting external API socket"); return 1; From 0da6bbe4a8a9285ba917b0caaf305eeb10eed29f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 13:30:38 +0200 Subject: [PATCH 03/14] service: minor refactor of stdin redirect Signed-off-by: Joachim Wiberg --- src/service.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/service.c b/src/service.c index 754fbe63..7783c7a1 100644 --- a/src/service.c +++ b/src/service.c @@ -208,13 +208,16 @@ static int stdin_redirect(void) { int fd; - fd = open("/dev/null", O_RDONLY | O_APPEND); - if (-1 != fd) { - dup2(fd, STDIN_FILENO); - return close(fd); + fd = open("/dev/null", O_RDONLY); + if (fd == -1) { + warn("Failed opening /dev/null for stdin redirect"); + return -1; } - return -1; + dup2(fd, STDIN_FILENO); + close(fd); + + return 0; } /* @@ -261,12 +264,10 @@ static void fallback_logger(char *ident, char *prio) static int lredirect(svc_t *svc) { static int have_sysklogd = -1; - pid_t pid, svc_pid; + pid_t svc_pid = getpid(); + pid_t pid; int fd; - svc_pid = getpid(); - dbg("%s pid: %d", svc_ident(svc, NULL, 0), svc_pid); - /* * Open PTY to connect to logger. A pty isn't buffered * like a pipe, and it eats newlines so they aren't logged From dc497bcd57944afc68f431e13338cd9a9672464e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 13:31:24 +0200 Subject: [PATCH 04/14] service: slight improvement of restart log message Signed-off-by: Joachim Wiberg --- src/service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.c b/src/service.c index 7783c7a1..30415f7b 100644 --- a/src/service.c +++ b/src/service.c @@ -2390,7 +2390,7 @@ static void service_retry(svc_t *svc) timeout = ((*restart_cnt) <= (svc->restart_max / 2)) ? 2000 : 5000; /* If a longer timeout was specified in the conf, use that instead. */ svc->restart_tmo = max(svc->restart_tmo, timeout); - logit(LOG_CONSOLE|LOG_WARNING, "Service %s[%d] died, restarting in %d msec (%d/%d)", + logit(LOG_CONSOLE|LOG_WARNING, "Service %s[%d] died, restarting (retry in %d msec) (attempt: %d/%d)", svc_ident(svc, NULL, 0), svc->oldpid, svc->restart_tmo, *restart_cnt, svc->restart_max); svc_unblock(svc); From 76f8a18816388841d15efb73df7ac81135a41057 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 13:19:58 +0200 Subject: [PATCH 05/14] Fix #440: refactor systemd and s6 readiness notifcation This patch fixes issue #440 which details how systemd readiness notification has been broken since its inception in Finit. In addition to now providing a proper abstract socket, the refactor also drops the reliance on the Finit client API to fetch a socket. Now an s6 descriptor is the write end of a pipe() and the systemd socket is instead created before forking off the service. Signed-off-by: Joachim Wiberg --- src/api.c | 14 ------ src/client.c | 10 ----- src/finit.h | 1 - src/private.h | 1 - src/service.c | 122 +++++++++++++++++++++++++++++++++++++++++--------- src/svc.h | 2 +- 6 files changed, 102 insertions(+), 48 deletions(-) diff --git a/src/api.c b/src/api.c index 02987c17..a9fb0745 100644 --- a/src/api.c +++ b/src/api.c @@ -571,20 +571,6 @@ static void api_cb(uev_t *w, void *arg, int events) result = do_signal(rq.data, sizeof(rq.data), rq.runlevel); break; - case INIT_CMD_NOTIFY_SOCKET: - svc = svc_find_by_pid(rq.runlevel); - if (!svc) { - errx(1, "Unknown PID, cannot register notify socket"); - result = 1; - break; - } - - if (uev_io_init(ctx, &svc->notify_watcher, service_notify_cb, svc, sd, UEV_READ)) { - err(1, "Failed initializing %s readiness notifier", svc_ident(svc, NULL, 0)); - break; - } - return; /* Don't close sd, used for notify */ - default: dbg("Unsupported cmd: %d", rq.cmd); break; diff --git a/src/client.c b/src/client.c index a8c06ac4..426b406e 100644 --- a/src/client.c +++ b/src/client.c @@ -97,16 +97,6 @@ int client_request(struct init_request *rq, ssize_t len) return -1; } - /* - * Exception, only command that don't need to wait for a - * response from Finit. Registers the client socket as a - * readiness notification socket with Finit - */ - if (rq->cmd == INIT_CMD_NOTIFY_SOCKET) { - rq->cmd = INIT_CMD_ACK; - return 0; - } - pfd.fd = sd; pfd.events = POLLIN | POLLERR | POLLHUP; if ((rc = poll(&pfd, 1, REQUEST_TIMEOUT)) <= 0) { diff --git a/src/finit.h b/src/finit.h index 04ca5597..b65c8f81 100644 --- a/src/finit.h +++ b/src/finit.h @@ -99,7 +99,6 @@ #define INIT_CMD_SVC_FIND 131 #define INIT_CMD_SVC_FIND_BYC 132 #define INIT_CMD_SIGNAL 133 -#define INIT_CMD_NOTIFY_SOCKET 200 /* For readiness notification socket */ #define INIT_CMD_NACK 254 #define INIT_CMD_ACK 255 diff --git a/src/private.h b/src/private.h index 8f02f3b6..f1b6f37b 100644 --- a/src/private.h +++ b/src/private.h @@ -46,7 +46,6 @@ int api_exit (void); void conf_flush_events(void); void service_monitor (pid_t lost, int status); -void service_notify_cb(uev_t *w, void *arg, int events); const char *plugin_hook_str (hook_point_t no); int plugin_exists (hook_point_t no); diff --git a/src/service.c b/src/service.c index 30415f7b..a8a9d60c 100644 --- a/src/service.c +++ b/src/service.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #ifdef _LIBITE_LITE @@ -56,6 +57,9 @@ #include "utmp-api.h" #include "schedule.h" +#define NOTIFY_PATH "@run/finit/notify/%d" + + /* * run tasks block other tasks/services from starting, we track the * current run task here. For service_step() and service_start(). @@ -68,6 +72,8 @@ static struct wq work = { int service_interval = SERVICE_INTERVAL_DEFAULT; static void svc_set_state(svc_t *svc, svc_state_t new_state); +static void service_notify_cb(uev_t *w, void *arg, int events); + /** * service_timeout_cb - libuev callback wrapper for service timeouts @@ -582,6 +588,9 @@ static int service_start(svc_t *svc) int result = 0, do_progress = 1; char cmdline[CMD_SIZE] = ""; sigset_t nmask, omask; + int pipefd[2]; + int fd = -1; + int sd = -1; pid_t pid; size_t i; @@ -627,6 +636,29 @@ static int service_start(svc_t *svc) if (svc_is_sysv(svc)) logit(LOG_CONSOLE | LOG_NOTICE, "Calling '%s start' ...", cmdline); + switch (svc->notify) { + case SVC_NOTIFY_S6: + if (pipe(pipefd) == -1) { + err(1, "%s: failed opening pipe for s6 notify", svc_ident(svc, NULL, 0)); + svc_missing(svc); + return 1; + } + fd = pipefd[1]; + sd = pipefd[0]; + break; + + case SVC_NOTIFY_SYSTEMD: + sd = socket(AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); + if (sd == -1) { + err(1, "%s: failed opening notify socket", svc_ident(svc, NULL, 0)); + svc_missing(svc); + return 1; + } + break; + default: + break; + } + if (!svc->desc[0]) do_progress = 0; @@ -653,38 +685,72 @@ static int service_start(svc_t *svc) pid = service_fork(svc); if (pid < 0) { + if (sd != -1) + close(sd); + if (fd != -1) + close(fd); result = -1; goto fail; } if (pid > 1) { + struct sockaddr_un sun; + size_t len; + dbg("Starting %s as PID %d", svc_ident(svc, NULL, 0), pid); svc->pid = pid; svc->start_time = jiffies(); + + switch (svc->notify) { + case SVC_NOTIFY_SYSTEMD: + memset(&sun, 0, sizeof(sun)); + sun.sun_family = AF_UNIX; + snprintf(sun.sun_path, sizeof(sun.sun_path), NOTIFY_PATH, pid); + len = strlen(sun.sun_path); + sun.sun_path[0] = 0; + result = bind(sd, (struct sockaddr *)&sun, offsetof(struct sockaddr_un, sun_path) + len); + if (result == -1) { + err(1, "%s: failed binding to notify socket", svc_ident(svc, NULL, 0)); + close(sd); + break; + } + /* fallthrough */ + case SVC_NOTIFY_S6: + close(fd); /* client-end of pipefd for s6 notify */ + result = uev_io_init(ctx, &svc->notify_watcher, service_notify_cb, svc, sd, UEV_READ); + if (result < 0) { + err(1, "%s: failed setting up notify callback", svc_ident(svc, NULL, 0)); + if (svc->notify == SVC_NOTIFY_S6) + close(fd); + close(sd); + break; + } + default: + break; + } } else if (pid == 0) { + char str[strlen(NOTIFY_PATH) + 32]; char *args[MAX_NUM_SVC_ARGS + 1]; int status; if (!svc_is_tty(svc)) redirect(svc); + switch (svc->notify) { + case SVC_NOTIFY_SYSTEMD: + snprintf(str, sizeof(str), NOTIFY_PATH, getpid()); + setenv("NOTIFY_SOCKET", str, 1); + /* fallthrough */ + case SVC_NOTIFY_S6: + close(sd); + break; + default: + break; + } + if (!svc_is_sysv(svc)) { wordexp_t we = { 0 }; int rc; - if (svc->notify == SVC_NOTIFY_SYSTEMD || svc->notify == SVC_NOTIFY_S6) { - if (client_command(INIT_CMD_NOTIFY_SOCKET)) { - err(1, "%s: failed creating notify socket", svc_ident(svc, NULL, 0)); - client_disconnect(); - /* does not change parent, restarting may work. */ - svc->notify = SVC_NOTIFY_NONE; - } else { - char val[20]; - - snprintf(val, sizeof(val), "%d", client_socket()); - setenv("NOTIFY_SOCKET", val, 1); - } - } - if ((rc = wordexp(svc->cmd, &we, 0))) { errx(1, "%s: failed wordexp(%s): %d", svc_ident(svc, NULL, 0), svc->cmd, rc); nomem: @@ -701,11 +767,11 @@ static int service_start(svc_t *svc) if (len == 0) break; - if (svc->notify == SVC_NOTIFY_SYSTEMD || svc->notify == SVC_NOTIFY_S6) { + if (svc->notify == SVC_NOTIFY_S6) { char *ptr = strstr(arg, "%n"); if (ptr) { - len = snprintf(str, sizeof(str), "%d", client_socket()); + len = snprintf(str, sizeof(str), "%d", fd); if (len > 0 && len <= 2) { ptr[0] = ' '; ptr[1] = ' '; @@ -2929,14 +2995,15 @@ void service_notify_reconf(void) * Called when a service sends readiness notification, or when * the service closes its end of the IPC connection. */ -void service_notify_cb(uev_t *w, void *arg, int events) +static void service_notify_cb(uev_t *w, void *arg, int events) { svc_t *svc = (svc_t *)arg; + int ready = 0; char buf[32]; ssize_t len; if (UEV_ERROR == events) { - dbg("Spurious problem with %s notify callback, restarting.", svc_ident(svc, NULL, 0)); + dbg("%s: spurious problem with notify callback, restarting.", svc_ident(svc, NULL, 0)); uev_io_start(w); return; } @@ -2946,11 +3013,24 @@ void service_notify_cb(uev_t *w, void *arg, int events) warn("Failed reading notification from %s", svc_ident(svc, NULL, 0)); return; } - buf[len] = 0; - /* systemd and s6, respectively. The latter then closes the socket */ - if (!strcmp(buf, "READY=1\n") || buf[len - 1] == '\n') { + /* Check for systemd READY=1 or s6 newline termination */ + if (svc->notify == SVC_NOTIFY_SYSTEMD) { + char *token = strtok(buf, "\n"); + + while (token) { + if (!strcmp(token, "READY=1")) { + ready = 1; + break; + } + token = strtok(NULL, "\n"); + } + } else if (svc->notify == SVC_NOTIFY_S6 && buf[len - 1] == '\n') { + ready = 1; + } + + if (ready) { /* * native (pidfile) services are marked as started by * the pidfile plugin. diff --git a/src/svc.h b/src/svc.h index 91b647ea..2b425f3a 100644 --- a/src/svc.h +++ b/src/svc.h @@ -85,7 +85,7 @@ typedef enum { SVC_ONCRASH_SCRIPT, } svc_oncrash_action_t; -/* 0: none, 1: systemd, 2: s6 */ +/* 0: none, 1: finit (native), 2: systemd, 3: s6 */ typedef enum { SVC_NOTIFY_NONE = 0, SVC_NOTIFY_PID, From d0d9b83b66ec611be32d3a9d1e8f7b4e85dea46c Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 13:24:37 +0200 Subject: [PATCH 06/14] test: update serv daemon to use proper systemd abstract socket This commit introduces a stripped down sd_notify(), taken from the systemd man page example, which is used by the serv daemon in lieu of the previous broken implementation. Signed-off-by: Joachim Wiberg --- test/src/Makefile.am | 2 +- test/src/sd-daemon.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ test/src/sd-daemon.h | 6 ++++ test/src/serv.c | 34 ++++++++++++------ 4 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 test/src/sd-daemon.c create mode 100644 test/src/sd-daemon.h diff --git a/test/src/Makefile.am b/test/src/Makefile.am index 226c37bd..a54bbae1 100644 --- a/test/src/Makefile.am +++ b/test/src/Makefile.am @@ -1,4 +1,4 @@ noinst_PROGRAMS = serv -serv_SOURCES = serv.c +serv_SOURCES = serv.c sd-daemon.c sd-daemon.h serv_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE diff --git a/test/src/sd-daemon.c b/test/src/sd-daemon.c new file mode 100644 index 00000000..67bea2d5 --- /dev/null +++ b/test/src/sd-daemon.c @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: MIT-0 */ + +/* + * systemd notify protocol, supporting readiness notification on startup + * and reloading, according to the protocol defined at: + * https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html + * + * This protocol is guaranteed to be stable as per: + * https://systemd.io/PORTABILITY_AND_STABILITY/ + */ + +#define _GNU_SOURCE 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * NOTE: As per spec., this function does not return POSIX OK(0) but + * rather "a positive value", i.e., 1. + */ +int sd_notify(int unset_environment, const char *state) +{ + struct sockaddr_un sun = { + .sun_family = AF_UNIX, + }; + size_t len, sun_len; + const char *path; + ssize_t written; + int sd; + + if (!state) + return -EINVAL; + + len = strlen(state); + if (len == 0) + return -EINVAL; + + /* If the variable is not set, the protocol is a noop */ + path = getenv("NOTIFY_SOCKET"); + if (!path) + return 0; /* Not set? Nothing to do */ + + /* Only AF_UNIX is supported, with path or abstract sockets */ + if (path[0] != '/' && path[0] != '@') + return -EAFNOSUPPORT; + + /* Ensure there is room for NUL byte */ + sun_len = strlen(path); + if (sun_len >= sizeof(sun.sun_path)) + return -E2BIG; + + strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); + if (sun.sun_path[0] == '@') + sun.sun_path[0] = 0; + + sd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sd == -1) + return -errno; + + if (connect(sd, (struct sockaddr *)&sun, offsetof(struct sockaddr_un, sun_path) + sun_len) == -1) { + close(sd); + return -errno; + } + + if (unset_environment) + unsetenv("NOTIFY_SOCKET"); + + written = write(sd, state, len); + if (written != (ssize_t) len) { + close(sd); + return written < 0 ? -errno : -EPROTO; + } + + return 1; +} diff --git a/test/src/sd-daemon.h b/test/src/sd-daemon.h new file mode 100644 index 00000000..b9ed4a0d --- /dev/null +++ b/test/src/sd-daemon.h @@ -0,0 +1,6 @@ +#ifndef SD_DAEMON_H_ +#define SD_DAEMON_H_ + +int sd_notify(int unset_environment, const char *state); + +#endif /* SD_DAEMON_H_ */ diff --git a/test/src/serv.c b/test/src/serv.c index fbb7031c..b8ece7b9 100644 --- a/test/src/serv.c +++ b/test/src/serv.c @@ -16,6 +16,7 @@ #include #include #include +#include "sd-daemon.h" #define PROGNM "serv" @@ -160,7 +161,7 @@ static int usage(int rc) " -h Show help text (this)\n" " -i IDENT Change process identity, incl. logs, pidfile, etc.\n" " -n Run in foreground\n" - " -N SOCK Send 'READY=1\\n' on $NOTIFY_SOCKET or SOCK\n" + " -N SOCK Send '\\n' on SOCK (integer), for s6 readiness\n" " -p Create PID file despite running in foreground\n" " -P FILE Create PID file using FILE\n" " -r SVC Call initctl to restart service SVC (self)\n" @@ -170,6 +171,8 @@ static int usage(int rc) "to let the rest of the system know it's done. When the program runs\n" "in the foreground it does not create a PID file by default.\n" "\n" + "When acting as a systemd daemon, this program expects NOTIFY_SOCKET\n" + "\n" "Regardless of how This daemon is started it provides a single service\n" "to others, spice ... guarded by sandworms.\n", ident); @@ -256,13 +259,13 @@ int main(int argc, char *argv[]) if (do_pidfile > 0) pidfile(pidfn); - if (!do_notify) { - const char *sock = getenv("NOTIFY_SOCKET"); + if (!do_notify && getenv("NOTIFY_SOCKET")) + do_notify = 1; - /* systemd style */ - if (sock) - do_notify = atoi(sock); - } + if (do_notify) + inf("Will notify %s ...", notify_s6 ? "s6" : "systemd"); + else + inf("No notify socket ..."); if (do_crash) { inf("Simulating crash, exiting with code %d", EX_SOFTWARE); @@ -279,15 +282,24 @@ int main(int argc, char *argv[]) if (reloading) { if (do_notify > 0) { + /* Issue #343: see notify.sh test for more details */ inf("Delaying notify by 3 seconds for notify.sh ..."); sleep(3); - inf("Notifying Finit on socket %d, READY=1", do_notify); - if (write(do_notify, "READY=1\n", 8) == -1) - err(1, "Failed sending ready notification to Finit"); + if (notify_s6) { + inf("Notifying Finit on socket %d", do_notify); + if (write(do_notify, "\n", 1) < 1) + err(1, "Failed sending ready notification to Finit"); inf("s6 notify, closing socket %d ...", do_notify); - close(do_notify); + if (close(do_notify)) + err(1, "Failed closing notify socket"); do_notify = 0; + } else { + int rc; + + inf("Notifying Finit on NOTIFY_SOCKET"); + rc = sd_notify(0, "READY=1"); + inf("sd_notify () => %d", rc); } } if (do_pidfile > 0) From 7cf0a293fd2f5611ca2076d469a11b7c18404a61 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 28 Jun 2025 14:04:39 +0200 Subject: [PATCH 07/14] test: adjust unexpected-restart.sh for proper systemd/s6 notify A systemd service should only use NOTIFY_SOCKET and an s6 style service reads its notify descript from the command line. For details, see notify.sh Signed-off-by: Joachim Wiberg --- test/unexpected-restart.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unexpected-restart.sh b/test/unexpected-restart.sh index 49ebc3ef..d415d8d6 100755 --- a/test/unexpected-restart.sh +++ b/test/unexpected-restart.sh @@ -15,8 +15,8 @@ test_setup() { run "cat >> $FINIT_CONF" < name:B serv -np -i B -N 0 -- B needs A (systemd) -service log:stdout notify:s6 name:C serv -np -i C -N 0 -- C needs B (s6) +service log:stdout notify:systemd name:B serv -np -i B -- B needs A (systemd) +service log:stdout notify:s6 name:C serv -np -i C -N %n -- C needs B (s6) service log:stdout notify:none name:D type:forking serv -i D -- D needs A (forking) task name:allup initctl cond set allup -- Everything is up EOF From 13961777067765794bffa417f4f6eefefdc1576a Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 29 Jun 2025 11:59:46 +0200 Subject: [PATCH 08/14] test: expand with command line options for increased usability Signed-off-by: Joachim Wiberg --- check.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/check.sh b/check.sh index 56c32bb2..3c091323 100755 --- a/check.sh +++ b/check.sh @@ -1,8 +1,33 @@ #!/bin/sh # Run test suite with the correct configure params +run_make=1 +jobs=17 -make distclean -./configure --prefix=/usr --exec-prefix= --sysconfdir=/etc --localstatedir=/var \ - --enable-x11-common-plugin --with-watchdog --with-keventd \ +while [ $# -gt 0 ]; do + case "$1" in + -n|--no-make) + run_make=0 + ;; + -j|--jobs) + shift + jobs="$1" + ;; + *) + echo "Usage: $0 [--no-make] [-j N]" + exit 1 + ;; + esac + shift +done + +if [ "$run_make" -eq 1 ]; then + make distclean +fi + +./configure --prefix=/usr --exec-prefix= --sysconfdir=/etc --localstatedir=/var \ + --enable-x11-common-plugin --with-watchdog --with-keventd \ CFLAGS='-fsanitize=address -ggdb' -make -j17 clean check + +if [ "$run_make" -eq 1 ]; then + make -j"$jobs" clean check +fi From da834627319ca8c3d3b81a9e0d9511b92b301687 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 29 Jun 2025 11:00:09 +0200 Subject: [PATCH 09/14] libsystemd: new library, refactor sd-daemon.[ch] test code This commit introduces a bare-bones replacement for libsystemd: - Build .so file and add --with-libsystemd to configure - Add capabilities support to test/src/serv.c - Update tests to account for a Finit built w/o libsystemd support Signed-off-by: Joachim Wiberg --- Makefile.am | 13 ++++++++++++- configure.ac | 26 ++++++++++++++++++-------- libsystemd/.gitignore | 7 +++++++ libsystemd/Makefile.am | 12 ++++++++++++ libsystemd/libsystemd.pc.in | 10 ++++++++++ {test/src => libsystemd}/sd-daemon.c | 0 {test/src => libsystemd}/sd-daemon.h | 0 src/Makefile.am | 1 + test/notify.sh | 9 +++++++++ test/src/.gitignore | 2 +- test/src/Makefile.am | 8 ++++++-- test/src/serv.c | 25 ++++++++++++++++++++++++- 12 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 libsystemd/.gitignore create mode 100644 libsystemd/Makefile.am create mode 100644 libsystemd/libsystemd.pc.in rename {test/src => libsystemd}/sd-daemon.c (100%) rename {test/src => libsystemd}/sd-daemon.h (100%) diff --git a/Makefile.am b/Makefile.am index 9760e458..63f8250c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = man plugins src system test tmpfiles.d +SUBDIRS = man plugins src system tmpfiles.d doc_DATA = README.md LICENSE contrib/finit.conf EXTRA_DIST = README.md LICENSE ChangeLog.md contrib/finit.conf @@ -9,6 +9,17 @@ endif if DOC SUBDIRS += doc endif +if LIBSYSTEMD +SUBDIRS += libsystemd +endif + +if LIBSYSTEMD +SUBDIRS += test +# Explicit dependency to ensure libsystemd is built before test +test: libsystemd +else +SUBDIRS += test +endif if BASH bashdir = $(BASH_DIR) diff --git a/configure.ac b/configure.ac index 5e591fd1..64d05de7 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,7 @@ AC_CONFIG_FILES([Makefile contrib/debian/Makefile contrib/debian/finit.d/Makefile contrib/debian/finit.d/available/Makefile contrib/void/Makefile contrib/void/finit.d/Makefile contrib/void/finit.d/available/Makefile doc/Makefile + libsystemd/Makefile libsystemd/libsystemd.pc man/Makefile plugins/Makefile src/Makefile @@ -168,6 +169,10 @@ AC_ARG_WITH(watchdog, AS_HELP_STRING([--with-watchdog@<:@=DEV@:>@], [Enable built-in watchdog, default: /dev/watchdog]), [watchdog=$withval], [with_watchdog=no watchdog=]) +AC_ARG_WITH(libsystemd, + AS_HELP_STRING([--with-libsystemd], [Build replacement libsystemd library, default: yes]), + [with_libsystemd=$withval], [with_libsystemd=yes]) + AC_ARG_WITH(hook-scripts-path, AS_HELP_STRING([--with-hook-scripts-path=DIR], [Base directory for hook scripts, default $libexecdir/finit/hook]), [hook_scripts_path=$withval], [hook_scripts_path=yes]) @@ -308,6 +313,9 @@ AS_IF([test "x$with_watchdog" != "xno"], [ AC_DEFINE_UNQUOTED(WDT_DEVNODE, "$watchdog", [Built-in watchdog device node])], [ watchdog=]) +AS_IF([test "x$with_libsystemd" != "xno"], [ + AC_DEFINE(HAVE_LIBSYSTEMD, 1, [Build replacement libsystemd library support])]) + AS_IF([test "x$enable_hook_scripts_plugin" != "xno"], [ AS_IF([test "x$hook_scripts_path" = "xyes"], [hook_scripts_path=$libexecdir/finit/hook]) AC_EXPAND_DIR(hook_scripts_path, "$hook_scripts_path") @@ -319,14 +327,15 @@ AS_IF([test "x$with_plugin_path" != "xno"], [ AC_DEFINE_UNQUOTED(EXTERNAL_PLUGIN_PATH, "$plugin_path", [Built-in default: /usr/lib/finit/plugins:/usr/local/lib/finit/plugins])]) # Control build with automake flags -AM_CONDITIONAL(BASH, [test "x$bash_dir" != "xno"]) -AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) -AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"]) -AM_CONDITIONAL(SULOGIN, [test "x$with_sulogin" != "xno"]) -AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"]) -AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"]) -AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"]) -AM_CONDITIONAL(TESTSERV, [test "x$enable_testserv_plugin" = "xyes"]) +AM_CONDITIONAL(BASH, [test "x$bash_dir" != "xno"]) +AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) +AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"]) +AM_CONDITIONAL(SULOGIN, [test "x$with_sulogin" != "xno"]) +AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"]) +AM_CONDITIONAL(LIBSYSTEMD, [test "x$with_libsystemd" != "xno"]) +AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"]) +AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"]) +AM_CONDITIONAL(TESTSERV, [test "x$enable_testserv_plugin" = "xyes"]) # Workaround for as-of-yet unreleased runstatedir support, planned for # autoconf 2.70, which some major distros have backported. @@ -408,6 +417,7 @@ Optional features: Built-in sulogin......: $with_sulogin $sulogin Built-in watchdogd....: $with_watchdog $watchdog Built-in logrotate....: $enable_logrotate + Replacement libsystemd: $with_libsystemd Use cgroup v2.........: $enable_cgroup Parse kernel cmdline..: $enable_kernel_cmdline Keep kernel logging...: $enable_kernel_logging diff --git a/libsystemd/.gitignore b/libsystemd/.gitignore new file mode 100644 index 00000000..52829a19 --- /dev/null +++ b/libsystemd/.gitignore @@ -0,0 +1,7 @@ +.deps/* +.libs/* +.dirstamp +*.lo +libsystemd.* +Makefile +Makefile.in diff --git a/libsystemd/Makefile.am b/libsystemd/Makefile.am new file mode 100644 index 00000000..cbde1500 --- /dev/null +++ b/libsystemd/Makefile.am @@ -0,0 +1,12 @@ +# libsystemd replacement library +lib_LTLIBRARIES = libsystemd.la +libsystemd_la_SOURCES = sd-daemon.c sd-daemon.h +libsystemd_la_LDFLAGS = -version-info 0:0:0 + +# pkg-config support +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libsystemd.pc + +# Install header to systemd/ subdirectory +systemddir = $(includedir)/systemd +systemd_HEADERS = sd-daemon.h \ No newline at end of file diff --git a/libsystemd/libsystemd.pc.in b/libsystemd/libsystemd.pc.in new file mode 100644 index 00000000..17881f60 --- /dev/null +++ b/libsystemd/libsystemd.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libsystemd +Description: Finit replacement for systemd notification library +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lsystemd +Cflags: -I${includedir} \ No newline at end of file diff --git a/test/src/sd-daemon.c b/libsystemd/sd-daemon.c similarity index 100% rename from test/src/sd-daemon.c rename to libsystemd/sd-daemon.c diff --git a/test/src/sd-daemon.h b/libsystemd/sd-daemon.h similarity index 100% rename from test/src/sd-daemon.h rename to libsystemd/sd-daemon.h diff --git a/src/Makefile.am b/src/Makefile.am index 04ff8137..f9fb60ec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ endif sbin_PROGRAMS = finit initctl pkglibexec_PROGRAMS = getty logit runparts tmpfiles + if SULOGIN pkglibexec_PROGRAMS += sulogin endif diff --git a/test/notify.sh b/test/notify.sh index e77a0141..9baa37f4 100755 --- a/test/notify.sh +++ b/test/notify.sh @@ -25,6 +25,15 @@ test_one() type=$1 service=$2 + # Skip systemd tests if serv doesn't have libsystemd support + if [ "$type" = "systemd" ]; then + if ! "$TEST_DIR/src/serv" -C | grep -q "libsystemd"; then + sep + say "Skipping systemd test - serv built without libsystemd support" + return 0 + fi + fi + sep # num=$(run "find /proc/1/fd |wc -l") diff --git a/test/src/.gitignore b/test/src/.gitignore index 8d844137..fdb16e7f 100644 --- a/test/src/.gitignore +++ b/test/src/.gitignore @@ -1,5 +1,5 @@ /Makefile /Makefile.in - +/.libs/ /.deps/ /serv diff --git a/test/src/Makefile.am b/test/src/Makefile.am index a54bbae1..9cebdeea 100644 --- a/test/src/Makefile.am +++ b/test/src/Makefile.am @@ -1,4 +1,8 @@ noinst_PROGRAMS = serv -serv_SOURCES = serv.c sd-daemon.c sd-daemon.h -serv_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE +serv_SOURCES = serv.c +serv_CPPFLAGS = -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -I$(top_builddir) +if LIBSYSTEMD +serv_CPPFLAGS += -I$(top_srcdir)/libsystemd +serv_SOURCES += $(top_srcdir)/libsystemd/sd-daemon.c +endif diff --git a/test/src/serv.c b/test/src/serv.c index b8ece7b9..dd9567e2 100644 --- a/test/src/serv.c +++ b/test/src/serv.c @@ -5,6 +5,10 @@ * in foregrund it does not create a PID file by default. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -16,7 +20,9 @@ #include #include #include +#ifdef HAVE_LIBSYSTEMD #include "sd-daemon.h" +#endif #define PROGNM "serv" @@ -146,6 +152,16 @@ static void pidfile(char *pidfn) } } +static int capabilities(void) +{ +#ifdef HAVE_LIBSYSTEMD + puts("libsystemd"); +#endif + puts("s6"); + + return 0; +} + static int usage(int rc) { FILE *fp = rc ? stderr : stdout; @@ -153,6 +169,7 @@ static int usage(int rc) fprintf(fp, "%s [-nhp] [-P FILE]\n" "\n" + " -C Show capabilities and exit\n" " -c Crash (exit) immediately\n" " -e K:V Verify K environment variable is V value\n" " -E K Verify K is not set in the environment\n" @@ -195,11 +212,13 @@ int main(int argc, char *argv[]) char cmd[80]; int c; - while ((c = getopt(argc, argv, "ce:E:f:F:hi:nN:pP:r:")) != EOF) { + while ((c = getopt(argc, argv, "cCe:E:f:F:hi:nN:pP:r:")) != EOF) { switch (c) { case 'c': do_crash = 1; break; + case 'C': + return capabilities(); case 'e': verify_env(optarg); break; @@ -295,11 +314,15 @@ int main(int argc, char *argv[]) err(1, "Failed closing notify socket"); do_notify = 0; } else { +#ifdef HAVE_LIBSYSTEMD int rc; inf("Notifying Finit on NOTIFY_SOCKET"); rc = sd_notify(0, "READY=1"); inf("sd_notify () => %d", rc); +#else + inf("Skipping systemd notify - built without libsystemd support"); +#endif } } if (do_pidfile > 0) From a7b8e1b94df49b8ea631e276e9ecca16f80e7716 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 29 Jun 2025 13:12:26 +0200 Subject: [PATCH 10/14] libsystemd: expand with with some common sd-daemon(3) functions Signed-off-by: Joachim Wiberg --- libsystemd/sd-daemon.c | 133 +++++++++++++++++++++++++++++++++++++++++ libsystemd/sd-daemon.h | 22 +++++++ 2 files changed, 155 insertions(+) diff --git a/libsystemd/sd-daemon.c b/libsystemd/sd-daemon.c index 67bea2d5..c58ab7fd 100644 --- a/libsystemd/sd-daemon.c +++ b/libsystemd/sd-daemon.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,8 @@ #include #include +#include "sd-daemon.h" + /* * NOTE: As per spec., this function does not return POSIX OK(0) but * rather "a positive value", i.e., 1. @@ -82,3 +85,133 @@ int sd_notify(int unset_environment, const char *state) return 1; } + +/* + * Printf-style notification function + */ +int sd_notifyf(int unset_environment, const char *format, ...) +{ + va_list ap; + char *state; + int ret; + + if (!format) + return -EINVAL; + + va_start(ap, format); + ret = vasprintf(&state, format, ap); + va_end(ap); + + if (ret < 0) + return -ENOMEM; + + ret = sd_notify(unset_environment, state); + free(state); + + return ret; +} + +/* + * PID-specific notification function + */ +int sd_pid_notify(pid_t pid, int unset_environment, const char *state) +{ + char path[256], *env; + size_t len; + int ret; + + if (!state) + return -EINVAL; + + len = strlen(state); + if (len == 0) + return -EINVAL; + + if (pid == 0) + pid = getpid(); + + env = getenv("NOTIFY_SOCKET"); + if (env) { + env = strdup(env); + if (!env) + return -errno; + } + + snprintf(path, sizeof(path), "@run/finit/notify/%d", pid); + setenv("NOTIFY_SOCKET", path, 1); + + ret = sd_notify(unset_environment, state); + + if (env) { + setenv("NOTIFY_SOCKET", env, 1); + free(env); + } + + return ret; +} + +/* + * PID-specific printf-style notification function + */ +int sd_pid_notifyf(pid_t pid, int unset_environment, const char *format, ...) +{ + va_list ap; + char *state; + int ret; + + if (!format) + return -EINVAL; + + va_start(ap, format); + ret = vasprintf(&state, format, ap); + va_end(ap); + + if (ret < 0) + return -ENOMEM; + + ret = sd_pid_notify(pid, unset_environment, state); + free(state); + + return ret; +} + +/* + * Socket activation stub - Finit doesn't support socket activation yet + * Returns 0 (no file descriptors passed) + */ +int sd_listen_fds(int unset_environment) +{ + if (unset_environment) { + unsetenv("LISTEN_PID"); + unsetenv("LISTEN_FDS"); + unsetenv("LISTEN_FDNAMES"); + } + + return 0; +} + +/* + * Watchdog stub - Finit doesn't support watchdog yet + * Returns 0 (no watchdog enabled) + */ +int sd_watchdog_enabled(int unset_environment, uint64_t *usec) +{ + if (unset_environment) { + unsetenv("WATCHDOG_PID"); + unsetenv("WATCHDOG_USEC"); + } + + if (usec) + *usec = 0; + + return 0; +} + +/* + * System detection function + * Returns 1 to indicate systemd compatibility (trick applications) + */ +int sd_booted(void) +{ + return 1; +} diff --git a/libsystemd/sd-daemon.h b/libsystemd/sd-daemon.h index b9ed4a0d..672968f0 100644 --- a/libsystemd/sd-daemon.h +++ b/libsystemd/sd-daemon.h @@ -1,6 +1,28 @@ #ifndef SD_DAEMON_H_ #define SD_DAEMON_H_ +#include +#include + +#define SD_LISTEN_FDS_START 3 + +/* Basic notification function */ int sd_notify(int unset_environment, const char *state); +/* Printf-style notification functions */ +int sd_notifyf(int unset_environment, const char *format, ...); + +/* PID-specific notification functions */ +int sd_pid_notify(pid_t pid, int unset_environment, const char *state); +int sd_pid_notifyf(pid_t pid, int unset_environment, const char *format, ...); + +/* Socket activation stubs */ +int sd_listen_fds(int unset_environment); + +/* Watchdog stub */ +int sd_watchdog_enabled(int unset_environment, uint64_t *usec); + +/* System detection */ +int sd_booted(void); + #endif /* SD_DAEMON_H_ */ From 10a1257e4796b86753f9028b0a30f8592e698330 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 30 Jun 2025 07:38:28 +0200 Subject: [PATCH 11/14] logit: minor cleanup, reverse christmas tree Signed-off-by: Joachim Wiberg --- src/logit.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/logit.c b/src/logit.c index 217eac08..6fd51714 100644 --- a/src/logit.c +++ b/src/logit.c @@ -36,6 +36,9 @@ # include #endif +#define LOG_MAX (200 * 1024) +#define LOG_NUM 5 + static const char version_info[] = PACKAGE_NAME " v" PACKAGE_VERSION; extern int logrotate(char *file, int num, off_t sz); @@ -161,13 +164,14 @@ static int usage(int code) int main(int argc, char *argv[]) { - int c, rc, num = 5; + char *ident = NULL, *logfile = NULL; + int log_opts = LOG_NOWAIT; int facility = LOG_USER; int level = LOG_INFO; - int log_opts = LOG_NOWAIT; - off_t size = 200 * 1024; - char *ident = NULL, *logfile = NULL; + off_t size = LOG_MAX; char buf[512] = ""; + int num = LOG_NUM; + int c, rc; while ((c = getopt(argc, argv, "f:hn:p:r:st:v")) != EOF) { switch (c) { From d95fc5f790efe373f5527ffef7c7d68edd650322 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 30 Jun 2025 07:39:07 +0200 Subject: [PATCH 12/14] logit: fix parse_prio(), check result of parse clang-tidy complained that parse_prio() always returned OK(0), turns out it was right. This patch adds validation of the parsing. Signed-off-by: Joachim Wiberg --- src/logit.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/logit.c b/src/logit.c index 6fd51714..03ff23e7 100644 --- a/src/logit.c +++ b/src/logit.c @@ -103,10 +103,12 @@ static int logit(int level, char *buf, size_t len) return 0; } -static int parse_prio(char *arg, int *f, int *l) +static int parse_prio(char *arg, int *fac, int *lvl) { char *duparg = strdup(arg); - char *ptr, *prio; + const char *prio; + char *ptr; + int found; if (!duparg) prio = arg; @@ -117,23 +119,34 @@ static int parse_prio(char *arg, int *f, int *l) if (ptr) { *ptr++ = 0; + found = -1; for (int i = 0; facilitynames[i].c_name; i++) { if (!strcmp(facilitynames[i].c_name, prio)) { - *f = facilitynames[i].c_val; + found = facilitynames[i].c_val; break; } } + if (found == -1) + return 1; + + *fac = found; prio = ptr; } + found = -1; for (int i = 0; prioritynames[i].c_name; i++) { + if (!strcmp(prioritynames[i].c_name, prio)) { - *l = prioritynames[i].c_val; + found = prioritynames[i].c_val; break; } } + if (found == -1) + return 1; + *lvl = found; + if (duparg != arg) free(duparg); From f24f76fc80d75f79d27de880a372aa6354b303a4 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 30 Jun 2025 07:40:50 +0200 Subject: [PATCH 13/14] logit: parse leading in log messages Add support for systemd daemon log style. Signed-off-by: Joachim Wiberg --- src/logit.c | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/logit.c b/src/logit.c index 03ff23e7..8ebdd21f 100644 --- a/src/logit.c +++ b/src/logit.c @@ -90,15 +90,51 @@ reopen: return fclose(fp); } -static int logit(int level, char *buf, size_t len) +/* + * Parse possible systemd style log prefix from message + * For details, see libsystemd/sd-daemon.h + * + * Returns the level, and updates buf to point past the prefix + */ +static int parse_level(char **buf, int default_level) { - if (buf[0]) { - syslog(level, "%s", buf); - return 0; + char *msg = *buf; + + if (msg[0] == '<' && msg[2] == '>' && msg[1] >= '0' && msg[1] <= '7') { + int level; + + switch (msg[1]) { + case '0': level = LOG_EMERG; break; + case '1': level = LOG_ALERT; break; + case '2': level = LOG_CRIT; break; + case '3': level = LOG_ERR; break; + case '4': level = LOG_WARNING; break; + case '5': level = LOG_NOTICE; break; + case '6': level = LOG_INFO; break; + case '7': level = LOG_DEBUG; break; + default: level = default_level; break; + } + + *buf = msg + 3; + return (default_level & ~LOG_PRIMASK) | level; } + return default_level; +} + +static int do_log(int level, char *msg) +{ + syslog(parse_level(&msg, level), "%s", msg); + return 0; +} + +static int logit(int level, char *buf, size_t len) +{ + if (buf[0]) + return do_log(level, buf); + while ((fgets(buf, len, stdin))) - syslog(level, "%s", buf); + do_log(level, buf); return 0; } From a27903c7451f942214a01201439cb73e5df52202 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Mon, 30 Jun 2025 07:41:28 +0200 Subject: [PATCH 14/14] libsystemd: translate leading log in stderr logging This commit also switches the stdout/stderr log capture backend for all notify:systemd services from the sysklogd project's logger tool to the bundled logit tool. Signed-off-by: Joachim Wiberg --- libsystemd/sd-daemon.h | 10 ++++++++++ src/service.c | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libsystemd/sd-daemon.h b/libsystemd/sd-daemon.h index 672968f0..73389edd 100644 --- a/libsystemd/sd-daemon.h +++ b/libsystemd/sd-daemon.h @@ -6,6 +6,16 @@ #define SD_LISTEN_FDS_START 3 +/* systemd logging defines for stderr parsing by Finit */ +#define SD_EMERG "<0>" /* system is unusable */ +#define SD_ALERT "<1>" /* action must be taken immediately */ +#define SD_CRIT "<2>" /* critical conditions */ +#define SD_ERR "<3>" /* error conditions */ +#define SD_WARNING "<4>" /* warning conditions */ +#define SD_NOTICE "<5>" /* normal but significant condition */ +#define SD_INFO "<6>" /* informational */ +#define SD_DEBUG "<7>" /* debug-level messages */ + /* Basic notification function */ int sd_notify(int unset_environment, const char *state); diff --git a/src/service.c b/src/service.c index a8a9d60c..41bb4751 100644 --- a/src/service.c +++ b/src/service.c @@ -342,6 +342,7 @@ static int lredirect(svc_t *svc) if (svc->log.prio[0]) prio = svc->log.prio; + /* Neither sysklogd logger or native logit tool available */ if (!have_sysklogd && !whichp(_PATH_LOGIT)) { logit(LOG_INFO, _PATH_LOGIT " missing, using syslog for %s instead", svc->name); fallback_logger(tag, prio); @@ -367,7 +368,13 @@ static int lredirect(svc_t *svc) _exit(1); } - if (have_sysklogd) { + /* + * For now, let systemd programs go via our native logit + * tool. It supports systemd logging defines for stderr + * parsing. The only real downside is that it cannot do + * PID faking, like sysklogd's logger tool. + */ + if (have_sysklogd && svc->notify != SVC_NOTIFY_SYSTEMD) { char pid[16]; snprintf(pid, sizeof(pid), "%d", svc_pid);