Commit Graph
340 Commits
Author SHA1 Message Date
Joachim Wiberg bd4efb59ca Refactor, change API for create()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-28 00:48:25 +01:00
Joachim Wiberg a90cfd4a75 plugins: fix octal permission on /run/lock and /var/lock
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-28 00:48:25 +01:00
Joachim Wiberg 4d2b97e4cc plugins: spellcheck
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-15 19:29:11 +01:00
Joachim Wiberg 21eda9dd1c plugins: create cache dir for nginx and runstatedir for clixon
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-15 19:21:09 +01:00
Joachim Wiberg c26dded49c Further box-in testserv so it doesn't conflict with other serv tests
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-05 14:42:32 +01:00
Joachim Wiberg 2e36590bbd plugins/bootmisc: create /run/dnsmasq directory, for resolv.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-05 11:02:25 +01:00
Joachim Wiberg 82dfa002ff Follow-up to c9fe9afa, proper fix for HOOK_BASFFS_UP mess
Instead of the revert in c9fe9afa, we restore HOOK_BASFFS_UP to its
proper place at the end of fs_mount_all().  For this to not cause any
regressions we add a new hook, HOOK_SVC_PLUGIN, and update all plugins
that call service_register() to run at the new hook.

This will cause regressions for external 3rd party plugins that rely on
HOOK_BASEFS_UP to be called at its previous postion.  Nevertheless, this
is the proper fix to the problem.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-05 01:15:49 +01:00
Joachim Wiberg a664fd7192 Add plugin and test to reproduce failing tests since c9fe9af
With all the change and revert mess of the HOOK_BASEFS_UP tests started
failing due to usr.so and sys.so failed to set up their conditions.  It
then became clear that boomisc.so cleaned up /run ... with the revert
we got service_register() to be called before global_rlimit[] was setup
causing services registered by plugins, before conf_init(), to crash.

This plugin and test is here to ensure we catch this problem in case of
any future refactor.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-05 01:15:49 +01:00
Joachim Wiberg 0cfd867816 plugins: fix memory leak in sys.so
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-02-04 23:04:41 +01:00
Joachim Wiberg 934a4db7d5 plugins/dbus: adapt to other operating systems
Not all Linux systems are based on Debian, and even if they are inspired
by Debian (Buildroot), they do not necessarily use the same defaults.

This patch probes the current system for:

 - dbus user and group
 - dbus PID file

If the user/group cannot be found we fall back to "root", if the PID
file cannot be determined we ignore PID file readiness.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-25 12:29:08 +01:00
Joachim Wiberg 2508495b8c Fix #343: only mark native services as started in pidfile plugin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-17 07:22:28 +01:00
Joachim Wiberg 05b72281e6 plugins: minor, fix clang warning
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-16 22:12:03 +01:00
Joachim Wiberg c22d123ab0 plugins: sys.so and usr.so must run after bootmisc
The bootmisc plugin sets up the base path for finit and figures out if
the system has /run or /var/run -- needed by the other plugins.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 18:07:40 +01:00
Joachim Wiberg 8bbae3d414 plugins: ensure /var/run/finit/cond exists
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 17:42:49 +01:00
Joachim Wiberg 525aaf1f66 plugins: s/Initializing/Seeding/ better choice of words
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2023-01-07 09:43:27 +01:00
Joachim Wiberg f6bfbc86e9 Drop mdevd plugin, not needed since notify:s6 support was added
For an example how to set it up, see the finit-skel repository:

https://github.com/troglobit/finit-skel/blob/main/skel/etc/finit.d/available/mdevd.conf

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-21 11:57:48 +01:00
Joachim Wiberg 48cfbfe5ed Follow-up to 685e0a80, drop extra snprintf() args
Issue #332

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-20 13:35:19 +01:00
Joachim Wiberg 180859a429 plugins: update mdevd to use new notification framework
Last update of plugin before dropping it in favor of an equivalent .conf
snippet.  (Pending new finit-conf repository).

Issue #327

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-16 13:54:46 +01:00
Joachim Wiberg 685e0a80a4 Fix #332: silence confusing [ OK ] status progress from modules-load
This change drops the confusing status progress output, which was always
OK since the actual modprobe operation runs in the background.  No need
to show status of the "added a task to finit, found modprobe" command.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-11 10:05:53 +01:00
Joachim Wiberg 19847d2997 plugins/modules-load: change default, load modules in runlevel S
Instead of waiting until runlevel 2, 3, 4, or 5 to load modules with
this plugin, we should load modules as soon as possible, i.e., in
runlevel S.  This also means that Finit will clean up all the tasks
so we don't have to see them in `initctl status`.

To allow users to revert to the old behavior, we add a new setting

    set runlevel 2345

that per modules-load.d/file changes the runlevel for all modprobe
commands.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-10 13:29:53 +01:00
Joachim Wiberg 3df154b798 Fix #325: allow custom modprobe command in modules-load.d plugin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-12-06 14:01:20 +01:00
Joachim Wiberg 70c2939596 Fix #315: add environment variables to hook scripts
All hook scripts are called with at least one environment variable set,
FINIT_HOOK_NAME, useful when reusing the same hook script for multiple
hook points.  It is set to the string name, also used by the path, e.g.,
hook/net/up.

For all hook points from hook/sys/shutdown and later, FINIT_SHUTDOWN is
also set, to one of:  halt, poweroff, reboot.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 22:51:40 +01:00
Joachim Wiberg 0498326962 Fix #318: only show "[ OK ] Calling foo" progress for runparts ...
For all other run_parts() use-cases we just give the script control over
stdout/stderr to prevent clobbering ANSI color escape codes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-23 21:49:30 +01:00
Joachim Wiberg f26009ec3e Follow-up to 912a281: reassert 'ready' condition on reload
Services that have not been changed, or otherwise needed to be reloaded,
need to have their 'ready' condition reasserted on 'initctl reload',
otherwise it will remain in 'flux'.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-09 14:25:49 +01:00
Joachim Wiberg d810ac00bc Fix #302: add support for running scripts at shutdown
This change adds support for running hook scripts at two new hook points
during the shutdown process:

 - HOOK_SVC_DN: after all services and non-reserved processes have been
   killed (and collected)
 - HOOK_SYS_DN: after all file systems have been unmounted, *just prior*
   to Finit calling reboot() to shut down or reboot the system

See doc/plugins.md for details and an example.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-11-07 07:01:21 +01:00
Joachim Wiberg c9f1bff419 Refactor ready:script to support new notify framework
Follow-up to abcb3ce, calling the service ready:script when readiness
has been signaled to or detected by Finit.

Issue #300

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 22:11:12 +02:00
Joachim Wiberg 912a281ee2 Fix #299: add support for service readiness notification
This patch adds service readiness notification to support daemons
employing systemd and s6 notification.  Complementing the native
Finit readiness support using PID files that exist already.

The two have slightly different ways of implementing readiness:

 - https://www.freedesktop.org/software/systemd/man/sd_notify.html
 - https://skarnet.org/software/s6/notifywhenup.html

Finit now provides both a NOTIFY_SOCKET environemnt variable, for
systemd, and a way to start s6 daemons with a descriptor argument.

For details on the syntax, see the `service` documentation.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:06:26 +02:00
Joachim Wiberg 488e6c2adf Follow-up to d82d1197: ensure PID file doesn't exist
Before we clear all conditions for a service, ensure pid_file_read()
didn't fail due to the PID file not (yet) containing a valid number.

If the process dies while starting up, and subsequently removes its
PID file, then the file shouldn't exist.  However, if we get inotify
before the process has finished writing the PID, then we just return
and wait for the next event.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-16 20:01:29 +02:00
Joachim Wiberg d22dea74e3 Finalize refactor to new log macros, following-up to 37e3be9
This possible also mitigates the issue tracked in #307.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-10-09 12:52:40 +02:00
Joachim Wiberg 37e3be9a0d Refactor to share err/warn log API between daemon and client code
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-09-05 09:57:45 +02:00
Joachim Wiberg 51ade57723 Rename internal run/task/service states => changes condition names
This patch renames the internal states for run/task/services to avoid
any confusion with the introduction of 'ready:scripts'.

 * WAITING -> PAUSED
 * READY   -> WAITING

A service condition that used, e.g., <service/foo/ready> should now
instead use <service/foo/waiting>.

Note: A new condition with the old name <service/foo/ready> will be
      introduced shortly to signify service "readiness", a concept
      used in other PID 1, like systemd and s6.

For details, see issue #299.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-23 15:31:24 +02:00
Joachim Wiberg d6f35903d6 Fix #195: add mdevd plugin as complement to hotplug.sh
This patch adds the mdevd[1] plugin from Andy's fork of Finit, only
minor whitespace adjustment and group fix introduced, along with
updates to configure.ac and the documentation.

Currently the hotplug.sh calls mdevd-coldplug (instad of mdev -s), but
since mdevd is not guaranteed to have started and be ready, it is also
started with mdevd -C.  A better solution is to use the s6 notify code
to synchronize the start of mdevd-coldplug.  Support for this is coming
soon to Finit.

[1]: https://github.com/hongkongkiwi/finit/blob/master/plugins/mdevd.c

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-08-16 14:00:57 +02:00
Joachim Wiberg d9dbfa23c7 plugins: minor whitespace and coding style cleanup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-06-25 13:42:53 +02:00
Tobias Waldekranz 5fb4a6ae8f plugins: modprobe: Support for coldplugging more devices
As it turns out, not all buses in Linux will add `modalias` attributes
to their devices in sysfs. One notable exception are MDIO buses. The
plugin's scan routine would thus not pick them up.

Fortunately, the information is always available in the device's
`uevent` attribute.

Therefore, default to looking for modaliases in the device's `uevent`
attribute instead, falling back to `modalias` only if `uevent` is not
availble (this should never happen).
2022-06-23 14:23:04 +02:00
Tobias Waldekranz e84333662e plugins: hotplug: Run after modprobe plugin, if available
Since the modprobe plugin (unsurpricingly) may cause new modules to be
loaded, it makes sense to to delay the initial device node scan until
we know that no mode nodes will show up within the next few
microseconds.
2022-06-23 14:19:30 +02:00
Andy Savage c129f06195 plugins: create missing d-bus directories
- Prefix plugin defines with DBUS_ to allow overriding at build-time
 - Create missing directories for modern d-bus

Signed-off-by: Andy Savage <andy@savage.hk>
2022-06-15 06:33:12 +02:00
Joachim Wiberg d11dc63bc2 Fix #269: add compulsory kernel symlinks in /dev
Add missing symlinks for compulsory and recommended /dev symlinks, as
specified in the Linux Administrator's Guide, section Linux Allocated
devices.

https://github.com/torvalds/linux/blob/v5.18/Documentation/admin-guide/devices.rst#compulsory-links

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-06-14 21:49:19 +02:00
Joachim Wiberg fdbd25c1b5 Use svc_ident() for more cases
- Drop basename() of svc->cmd from remaining code
  - Replace uses of svc->cmd with svc_ident(svc)
  - Use svc_ident() as default log tag

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-13 13:36:33 +02:00
Joachim Wiberg eca3098c0e plugins: refactor modules-load to read files in lexicographic order
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-07 16:29:18 +02:00
Tobias Waldekranz b62c975dc4 plugins: hook-scripts: Add
Add a plugin that will allow the user to trigger the execution of
scripts from plugin hook points. This is particularly useful for early
boot debugging that needs to take place before regular services are
available.

For example, let's say that you want to enable some kernel tracing
before modules are loaded. With hook-scripts, you can just drop in a
shell script in /libexec/finit/hook/mount/all/ that will poke the
right control files in tracefs.
2022-05-06 10:36:37 +02:00
Joachim Wiberg 9b17ce0b7c Fix restart logic of sysv start/stop scripts and forking services
Init script return pretty quickly after launch, so we cannot use that to
detect if they, or the daemon they launched, have crashed.  So we start
the service_retry() with a 2 sec delay, which should be ample time to
allow the pidfile plugin to detect a forking service's new PID.

In release-cycle regression, no public issue needed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-06 07:57:08 +02:00
Joachim Wiberg 7f19474d8d plugins: skip backup files in modules-load plugin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-06 07:57:07 +02:00
Joachim Wiberg a5941165a0 plugins: add support for 'set noindex' to modules-load plugin
This adds support for a `set` directive in the modules-load plugin.
Currently only `set noindex` and `set index = NUM` are supported and
either disable indexing (:ID) of modules, or reset the index to NUM,
for the given file.  For each new file read the index is reset to
the value it would have had.  E.g.

01-foo.conf:          => name:id
   esp4.ko            => modprobe.esp4.ko:1
   set noindex
   deflate.ko         => modprobe.deflate.ko
02-bar.conf:
   nls_iso8859-15.ko  => modprobe.nls_iso8859-15.ko:3
   nls_utf8.ko        => modprobe.nls_utf8.ko:4

Fixes issue #257

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-06 07:57:07 +02:00
Joachim Wiberg 181d9556a1 Drop config.h include from helpers.h, exported header file
Drop the config.h include from helpers.h after a report from a colleague
trying to build an external plugin from the latest GIT sources.

Instead, make sure config.h is included, and properly commented, in all
.c files that have configure #ifdefs and other deps.  Also, move more
ot the includes from helpers.h to their respective .c file instead to
reduce the amount of headers an external plugin pulls in.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-05 14:48:30 +02:00
Joachim Wiberg e50fe3b060 plugins: use reentrant API getmntent_r()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-05-01 22:12:02 +02:00
Joachim Wiberg 10392e9639 plugins: modules-load: skip lines starting with '#'
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-27 07:46:03 +02:00
Joachim Wiberg b01f9f38f2 Improve logging of forking services having started and stopped
Since a forking service, e.g. a sysv init script, will exit very early
we cannot log the same as for regular services "Starting foo[123]", so
instead we log "Started bar[321]" when we get the pidfile update and
the same when stopping a forking service, log "Stopped bar[321]" when
we collect the PID.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-26 20:58:57 +02:00
Joachim Wiberg e2753d75f8 plugins: silence netlink developer debug messages
Default debug level for the netlink plugin is just too noisy.  Let's
drop debug messages (mostly) intended for developers.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-25 23:35:02 +02:00
Joachim Wiberg 108bbf56dd Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-19 19:35:49 +02:00
Joachim Wiberg 7d831170ae plugins: close/exit iwatch *after* event loop has been detached
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2022-04-14 08:33:24 +02:00