Commit Graph
1574 Commits
Author SHA1 Message Date
Joachim Wiberg 927acdbd7e Increase MAX_ID_LEN to support longer service identifiers
Allow service IDs up to 64 characters to support SHA-256 hashes,
UUIDs, and other long unique identifiers. This increases memory
usage by ~98 bytes per service instance, which is negligible for
typical deployments.

The IDENT column width in initctl output adapts dynamically based
on actual ID lengths in use, so short IDs remain unaffected.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-10-14 11:49:57 +02:00
Joachim Wiberg 6f6267f3b3 When collecting a script or unregistering a service, cancel timeouts
Both service and sysv stanzas support a cleanup:script (since v4.10), with an
optional timeout.  These timers must be stopped when collecting a PID for an
svc_t, or when unregistering an svc_t, otherwise the timer callback will be
continuously called, reporting "spurious problem", and cause 100% CPU usage.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 16:49:34 +02:00
Joachim Wiberg dec89d4054 Minor, drop __func__ from dbg() statements
The dbg() macro already includes __func__ as the first text string in
the format string.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 16:48:38 +02:00
Joachim Wiberg e7f97f8264 Fix state machine ordering issue
This patch fixes an ordering issue where the configuration generation is
stepped before all old/disabled services had been stopped.  Finit should
ensure disabled services are stopped before entering the next generation.

If the genation is stepped first, all conditions are put in "flux" state,
so, e.g, a podman container running as a sysv service may lock-up until
it is killed by Finit.  Found in the Infix OS project.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 12:47:43 +02:00
Joachim Wiberg 6415aeebac Ensure sysv 'stop' command has same env. as 'start'
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 10:17:19 +02:00
Mattias Barthel e69200ea43 Add exit status/signal info when a process dies
Signed-off-by: Mattias Barthel <mattiasbarthel@gmail.com>
2025-08-29 10:12:58 +02:00
Joachim Wiberg 26d5018224 Allow kill delay up to five minutes for debug
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 10:02:36 +02:00
Joachim Wiberg 1b7699ca93 Expand norespawn grasp to service_retry()
The norespawn hack pause Finit while a developer debugs the system.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 10:00:25 +02:00
Joachim Wiberg 8eab099f09 Minor, encase script + args in '' for debug help
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-08-29 09:58:10 +02:00
Joachim Wiberg e958189e6a initctl: rename command signal -> kill
Already backwards compatible, both kill and signal map to the same command.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-10 18:29:39 +02:00
Joachim Wiberg 8377f0e736 Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-10 14:34:16 +02:00
Joachim Wiberg 0cd51fb7d3 Add support for $MAINPID to reload, and stop:scripts
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-08 06:59:53 +02:00
Joachim Wiberg 0bef874cf3 logit: fix evaluation order violation, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 15:49:01 +02:00
Joachim Wiberg eadd01da1f Fix double-close, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 15:46:57 +02:00
Joachim Wiberg 80b0750523 Simplify if-if-else-if-else in service_start()
Coverity Scan gets very confused and think we are leaking sd in
the systemd notify case.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 15:45:44 +02:00
Joachim Wiberg 61be1ef880 Follow-up to b4b7ee1, also set process name -> "init"
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 15:15:25 +02:00
Joachim Wiberg a7428ababa logit: fix minor (possible) memory leak
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 15:14:38 +02:00
Joachim Wiberg b4b7ee1b71 Clear command line arguments after parsing
Fixes #442

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 14:41:40 +02:00
Joachim Wiberg d652211621 Follow-up to db840bd, use systemf() to simplify tmpfiles evn further
Also, added benefit, we don't get compiler warnings for ignoring the
return value of system(), which we don't care about in this case.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 14:38:27 +02:00
Joachim Wiberg 9f95934df9 Follow-up to 57545e1
Ensure 'rc' is defined for all code branches.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 14:35:49 +02:00
Joachim Wiberg 14336bd407 Add stop:'script [args]' support for service/sysv stanzas
Fixes #412

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 13:20:46 +02:00
Joachim Wiberg 57545e1ab0 Add reload:'script [args]' support for service/sysv stanzas
Fixes #446

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 12:05:51 +02:00
Joachim Wiberg 7ad802b092 Add quote support to pre/post/ready/cleanup scripts
- Allow scripts to take space separated arguments with quoting
 - Simplify script-exists check, which already checks for leading /
 - Unset current script on parse error
 - Allow setting no timeout

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 12:00:02 +02:00
Joachim Wiberg e319a606b8 tmpfiles: minor, fix memory leak
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 11:36:56 +02:00
Joachim Wiberg 7d434b1eaa Ignore new tmpfiles binary
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:28:42 +02:00
Joachim Wiberg 58d48b54b3 tmpfiles: add -d,--debug mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:28:02 +02:00
Joachim Wiberg 7d4603e13b Minor, simplify
clang-tidy noticed this unnecessary check.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:14:07 +02:00
Joachim Wiberg d0c5d7be5b Minor, constify
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:14:05 +02:00
Joachim Wiberg db840bdc19 Follow-up to 8be7a46, simplify linking of tmpfiles program
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:14:04 +02:00
Joachim Wiberg 3df3c51dae Relocate global configuration variables from finit.c -> conf.c
These variables really belong in conf.c.  Relocate and move external
decls. from finit.h -> conf.h to simplify linking of other programs.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:14:03 +02:00
Joachim Wiberg d37d241647 Drop log.h include from helpers.h
With the relocation of several functions, including inline functions,
from helpers to util, we no longer need to include log.h.  Which is a
good thing, since any subsystem that needs logging should explicitly
include log.h

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:14:02 +02:00
Joachim Wiberg b18b21830a Relocate functions helpers.c -> util.c
The file helpers.c should strictly only be used for misc. helper
functions to the main Finit daemon.  The functions moved in this
commit are generic enough to be used by any deamon or programs,
and for that we have util.c

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:14:00 +02:00
Joachim Wiberg 06daf2e4a5 Relocate helper function, only used by tmpfiles
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:13:59 +02:00
Joachim Wiberg 0861373d14 Minor, relocate path definition to finit.h
This is where the other path definitions live.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:13:57 +02:00
Joachim Wiberg 1b9e69414e Refactor state machine control functions
This refactor should have been done years ago when we first introduced
the big state machine.  The old functions service_runvel() and the oddly
named service_reload_dynamic() are actually state machine control fns,
so let relocate them.

Also in this commit, remove the global variable 'sm' and rename a few of
the critical functions to better names.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2025-07-06 03:13:56 +02:00
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