Commit Graph
1539 Commits
Author SHA1 Message Date
Joachim Wiberg 39f4aa3f2c Simplify, a daemon is one of service or sysv
Historically we've kept these two apart, but their commonalities are far
more than what separates them.

This fixes a bug where ready:scripts were not called for sysv daemons,
and also opens up for adding support for a reload:script for both types.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:13:54 +02:00
Joachim Wiberg a27903c745 libsystemd: translate leading log <LEVEL> 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 <troglobit@gmail.com>
2025-07-02 16:47:34 +02:00
Joachim Wiberg f24f76fc80 logit: parse leading <LEVEL> in log messages
Add support for systemd daemon log style.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 16:43:44 +02:00
Joachim Wiberg d95fc5f790 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 <troglobit@gmail.com>
2025-07-02 16:43:43 +02:00
Joachim Wiberg 10a1257e47 logit: minor cleanup, reverse christmas tree
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 16:43:43 +02:00
Joachim Wiberg da83462731 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 <troglobit@gmail.com>
2025-07-02 16:42:06 +02:00
Joachim Wiberg 76f8a18816 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 <troglobit@gmail.com>
2025-07-02 16:36:58 +02:00
Joachim Wiberg dc497bcd57 service: slight improvement of restart log message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 16:36:58 +02:00
Joachim Wiberg 0da6bbe4a8 service: minor refactor of stdin redirect
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 16:36:57 +02:00
Joachim Wiberg 91f7a75bee api: ensure socket is non-blocking
Also, remember to refactor the client socket handling to prevent
blocking PID 1.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 16:36:57 +02:00
Joachim Wiberg 77404a2ea0 Merge pull request #445 from troglobit/space-in-argval
Space in argval

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:50:21 +02:00
Joachim Wiberg 1275f05343 devmon: add error checking to callback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:29:54 +02:00
Joachim Wiberg 61a92aa0b6 devmon: silence unnecessary dbg() in devmon_add_cond()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:29:54 +02:00
Joachim Wiberg b38ff0cc79 service: fix service log priority in fallback mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:29:53 +02:00
Joachim Wiberg 168f5bf1d8 log: new function, log_parse()
Converts from syslog priority string format to facility and level.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:29:53 +02:00
Joachim Wiberg ffd00f646c Declare unused parameters
When building with global CFLAGS=-Wunused-parameter the output from the
build looks terrible.  This commit explicitly declares unused variables
to prevent triggering -Wunused-parameter

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:29:52 +02:00
Joachim Wiberg 5e2e273cad conf: check return value of strdup() in parse_env()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:28:41 +02:00
Joachim Wiberg 33f6697cd5 conf: new function conf_parse_env()
Reduce code duplication.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:28:27 +02:00
Joachim Wiberg 6f0ba22a0f util: new function unquote()
Refactor to reduce code duplication

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:28:10 +02:00
Joachim Wiberg ecb690c9ec service: support quoted arguments to run/task/service options
Fixes #441

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-02 14:27:39 +02:00
Aaron Andersen 0459bb432a service.c/parse_cmdline_args: handle loooooong arguments 2025-07-01 20:31:59 -04:00
Ming Liu 62ab990129 cgroup.c: fix some compilation warnings
Fix the following warnings:
| cgroup.c:296:13: warning: implicit declaration of function 'conf_any_change' [-Wimplicit-function-declaration]
| cgroup.c:297:17: warning: implicit declaration of function 'service_reload_dynamic' [-Wimplicit-function-declaration]

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
2025-06-27 14:31:18 +02:00
Ming Liu 0c2836d747 Makefile.am: fix tmpfiles linking issues
Fix the following linking issues of tmpfiles:
| exec.c:308: warning: stty is not implemented and will always fail
| plugin.c:237: undefined reference to `run_parts'

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
2025-06-27 14:31:02 +02:00
Joachim Wiberg 8be7a462e0 Merge pull request #439 from aanderse/tmpfiles
tmpfiles: refactor into separate executable
2025-06-09 07:56:10 +02:00
Aaron Andersen 5993b4bb5d tmpfiles: refactor code into new is_dir_empty function
The existing implementation seemed useful enough to warrant a new
helper function. Care was taken to ensure the revised code no longer
suffers any memory leaks.
2025-06-05 20:53:25 -04:00
Aaron Andersen 2957246092 tmpfiles: implement remove logic for 'D'
> D
> Similar to d, but in addition the contents of the directory will be removed when --remove is used.
2025-06-02 19:27:24 -04:00
Aaron Andersen a5710125f6 tmpfiles: add --create and --remove flags
Allow execution of tmpfiles to specify which mode(s) of operation to run in.
2025-06-02 19:27:24 -04:00
Aaron Andersen ff95ebeb91 tmpfiles: split up create & remove logic
The tmpfiles.d spec contains entry types that should be acted upon in different modes
of operation: create, clean, remove, and purge - split up create & remove logic to
clarify the modes of operation finit supports.
2025-06-02 19:27:24 -04:00
Aaron Andersen 1921b3f2c5 tmpfiles: refactor into separate executable
The tmpfiles.d spec has proven useful in systemd, enough so that some developers
are starting to ship tmpfiles.d configuration files with their software.
By splitting the tmpfiles functionality in finit out into a separate executable
we are providing a useful piece of software that package managers can hook into.
2025-06-02 19:27:24 -04:00
Joachim Wiberg 051ef81e53 initctl: drop unused function pid_comm()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-05-30 10:45:01 +02:00
Joachim Wiberg 90993c237a Add hexdump() debug helper function
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-05-30 10:44:05 +02:00
Joachim Wiberg b0b4f7b2ba initctl: refactor pid_cgroup(), return allocated buffer
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-05-30 10:42:50 +02:00
Joachim Wiberg 4d79d84fb8 Fix #438: refactor initctl ps/top to handle loooooong command lines
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-05-30 10:21:24 +02:00
Joachim Wiberg 9684127eb7 initctl: refactor runlevel string composition
Related to issue #437

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-05-05 07:27:06 +02:00
Joachim Wiberg 8d2cfd69fa initctl: buffer overflow in runlevel string formatting
Fix #437

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-05-05 07:19:12 +02:00
Joachim Wiberg c67d15e272 runparts: update usage text, missing '-b' flag for batch mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-31 14:17:55 +02:00
Joachim Wiberg 8984c655f8 cond_get_agg: minor refactor
- Use stack instead of heap memory
 - constify

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-31 14:16:24 +02:00
Aaron Andersen fa13cddc28 improve notify:s6 compatibility 2025-03-29 08:03:43 -04:00
Joachim Wiberg ac4b9c2f93 Unblock signals for pre/post/ready/cleanup scripts
The service_fork() function blocks all signals for the new process, it
is up to the callee to call sig_unblock() before calling exec().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-27 19:10:56 +01:00
Joachim Wiberg 6528628b5c getty: improve argument handling when launching login
Add explicit argument separator before username to ensure correct
parsing of the login command regardless of username format.  This
follows best practices for command execution and prevents unexpected
behavior when processing special characters in usernames.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-18 13:18:10 +01:00
Joachim Wiberg 33e378a345 Fix #432: allow services in 'setup' to be stopped
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-18 07:21:44 +01:00
Joachim Wiberg b695b46a9d Revert last part of 91a9c83, fallback SIGKILL when stopping services
When a service is stopped, but does not respond to the default SIGTERM,
a fallback kicks in after 3 seconds (default) to send SIGKILL.  Since
91a9c83 (v3.2-rc2) this has however not worked since the signal was
only sent to the process group.

It is the job of service_monitor(), when it reaps the process leader,
to forward the signal to the process group.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-18 07:18:16 +01:00
Joachim Wiberg 0e61ed727f Add helper function, svc_is_stopped() when stopped by user
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-18 07:17:37 +01:00
Joachim Wiberg e9d60a6c04 Minor, coding style
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-18 07:17:23 +01:00
Joachim Wiberg 8ed2751ae1 Fix pre/post/ready/cleanup script execution if env:file is missing
Don't try to source an optional env:file if it is missing.  Otherwise
execution of pre/post/ready/cleanup script will fail.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-17 18:39:05 +01:00
Joachim Wiberg 7fec66dc09 Simplify, svc_checkenv() already checks if optional
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-17 18:38:31 +01:00
Joachim Wiberg 75fa868a4b Fix various typos found by codepsell
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-17 16:46:28 +01:00
Joachim Wiberg 1691ebb292 logit(): RFC3164 conformance for /dev/kmsg fallback
RFC3164 section 5.3 states; "a colon and a space character usually
follow the TAG".  This is also the reference format in the kernel:
https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-03-03 03:39:55 +01:00
Joachim Wiberg 9210f2851e Skip killing initctl on shutdown/reboot
Initiating a shutdown/reboot from `initctl` should not cause `initctl`
to be killed in do_shutdown().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-02-25 08:37:27 +01:00
Joachim Wiberg 9a357b7aab Fix possible NULL pointer dereference
When a user sets up a TTY without a device, triggering the tty->notty
code path, the tty->dev will be NULL and tty_parse_args() still return
OK result.

Found by Coverity Scan

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-02-23 10:30:16 +01:00