We must wait for udevd to be started before we call udevadm. However,
udevd doesn't create a PID file, so we must also fake this. There is
still a slight risk of a race condition: udevd not having properly
started before udevadm tries to connect, but it works OK in Debian.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Issue #52 suggested calling service_reload_dynamic() automatically after
run-parts and /etc/rc.local. This may seem like a good idea, but not
only does it create extra overhead, it currently also freezes the boot
and fails to present a login prompt if a run-parts directory exists.
Yes, the directory can be empty, it just have to exist to trigger this
regression.
While trying to find the root cause I realized this was all just wrong.
If the user does something that requires reloading finit, they should
call `initctl reload` from the script instead.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
When finit calls out to external tools, like `ifup $IFACE`, that tool in
turn may use other external tools. On systems with BusyBox our calling
`ifup $IFACE` will result in BusyBox casting a magic spell: if $SHELL is
unset it goes looking in the file /etc/passwd for the shell of $USER
which may not be set to a Bourne compatible UNIX shell, so commands like
`ip link ...` or `run-parts ...` will fail hard.
This patch adds SHELL=/bin/sh as a sane early default.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Some systems, usually those built around BusyBox, have mdev installed
but have an option to install udev. In those cases the user likely
prefers to use udev over mdev and this patch addresses that.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The screen_init() call for each print() & C:o caused serious screen
artefacts in debug mode. This patch reworks f858d94 to only re-init
screen when toggling debug.
Also, avoid screen_init() completely if started in debug mode.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This gives the operator a way to add a post-mount script, e.g. to peform
a 2nd stage mount or mount preparations, before the bootmisc.so plugin
and others run in hook/mount/all
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
An external plugin to set up /etc can use HOOK_BASEFS_UP, but the Finit
conf_monitor() must then be called *after* not before that hook, or the
inotify watchers will listen on the wrong inode.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The file plugin.h is installed to $prefix/include and used by external
plugins. Therefore it must not include, or depend on, features set by
the configure script in config.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This is a quite intrusive change. In addition to the already reserved
runlevels 0 and 6, halt and reboot, respectively, this patch reserves
runlevel 1 as *no networking*, like the traditional SysV init did. One
of the reasons for this change is the new 'single' user mode, introduced
earlier. Most users when entering 'S' or 'single' on the kernel cmdline
expect the single user mode (runlevel 1) to be without networking.
This leaves 2, 3, 4, 5, and 7, 8, 9 as fully user-configurable runlevels
with networking.
Of course, networking can still be enabled in runlevel 1 using ifconfig
or ifupdown, or change runlevel.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch adds a rescue (revovery) mode to Finit. Simply add `rescue`
to the kernel cmdline at boot and the following steps at bootstrap will
be skipped:
- Load of services/run/task/etc in /etc/finit.conf + /etc/finit.d/*.conf
- fsck of filesystems in /etc/fstab
- Remount of / to read-write
- Mount of all filesystems in /etc/fstab
- swapon
- A few plugin hooks:
- HOOK_ROOTFS_UP
- HOOK_MOUNT_ERROR
- HOOK_BASEFS_UP
- `runparts DIR`
- /etc/rc.local
Instead of loading /etc/finit.conf and /etc/finit.d/*.conf Finit loads
the file /lib/finit/rescue.conf, which can be overridden by the operator
if needed. If this file is removed (or lost), Finit falls back to start
a simple root shell, without any login.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The difference between `runparts DIR` and `/etc/rc.local` is that one
should run just before the first runlevel change (to the configured
runlevel) at the end of bootstrap, whereas the other should run just
before launcing the TTYs, i.e. after all tasks in the configured
runlevel have been started.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch is an optimization. Now that we monitor for any .conf file
changes (as soon as the event loop starts) we can skip automatic reload
of all .conf files and services if no .conf file has changed. Unless
the user issues an `initctl reload`, `init q`, or sends us SIGHUP.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
As reported in #92, systems with an udevd very early register a service
using global_rlimit[]. The change was introduced in b68c5c1 but did
not take the ordering problem into consideration, global_rlimit[] was
left uninitialized, which likely led to severely limited udevd that
was continously crashing.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The new condition triggered hooks requrie /var/run/finit/cond to
be set up before calling the first user-configurable hooks.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Until now Finit has used mtime to determine if a file has been changed,
or simply touched to request reload, when `initctl reload` is called.
Using mtime for this purpose is a monumentally bad idea since time can
be changed at any point: a user may adjust the time, NTP continously
tunes the clock, and time stamps are stored as the walltime. So if we
compare timestamps against the last time we (booted or) did reload, we
would miss .conf file changes.
This patch replaces the mtime mistake with an inotify watcher for the
following files: /etc/finit.d/*.conf, /etc/finit.d/available/*.conf,
and /etc/finit.conf. All file changes between (bootstraps and) calls
to `initctl reload` are tracked, like the mtime backend it replaces.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
TIL, using mtimes for tracking event orderings is a monumentally bad
idea (queue the nodding UNIX-beards). Mtimes are in wallclock time which
is not necessarily monotonically increasing. A user may adjust the time,
an NTP daemon will continously tune the clock and so on.
Instead, store an explicit generation number in each condition file,
which will be monotonically increased by finit on each reconf.
This patch moves the networking bit to the latter part of bootstrap,
called finalize(), in favor of starting the event loop earlier.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This change removes a long standing kernel requirement and architectural
mishap in the design of Finit v1. It is no longer necessary to include
CONFIG_SYSVIPC in the kernel to use Finit and its command line tool
initctl. It is also no longer possible to connect to the internals of
PID 1 using shmat(), the initctl tool has already been updated to use
the domain socket API.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch fixes the problem with run/task jobs with conditions, run at
runlevel S (bootstrap), not being given enough time to actually start
and run even once.
The new svc counter 'once' is now inspected before transitioning away
from runlevel S to the configured runlevel. A global (currently hard
coded) timeout of 10 sec is given to all run/tasks.
As a spin-off, this patch starts up the event loop much earlier than
before. Meaning the initial runlevel change at boot is now done in
a finalize() callback when all run/tasks have completed, or when the
global timeout has expired. Starting the event loop earlier gives us
the possibility to rely on the pidfile plugin to provide our run/tasks
with the conditions necessary to start.
TODO: What remains is to add similar handling to all runlevel
transitions, not just the initial one at boot.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Don't really see the point of this code anymore, was possibly an issue
before we refactored the logging subsystem. Comment out for now, and
remove later.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Systems running OverlayFS, or similar, on /etc may have new/modified
.conf files in /etc/finit.d. This patch makes sure to reload them
after `mount -a` has run so any configured bootstrap tasks and the
new hook callback scripts may run as expected.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch extends the existing rlimit implementation to support setting
limits per service, run/task, inetd, and tty.
Use rlimit in /etc/finit.conf to change the global setting, which is
then inherited to each /etc/finit.d/*.conf. For each .conf file the
rlimit is reinitialized to the global finit.conf settings.
Also, add `unlimited` keyword, to replace the now deprecated `infinity`
keyword. The latter is however kept, for compatibility with previous
releases, for the foreseeable future.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch not only greatly simplifies the registration of the built-in
watchdog daemon, it also fixes a nasty race condition with an external
watchdog daemon. The INIT_CMD_WDOG_HELLO could reach finit in reversed
order, leading to the built-in daemon shutting down, but finit killing
the just registered external daemon.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Most Linux distributions, embedded or otherwise, do not need this
and only confuses the user of an OS with Finit.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
All this code did was trigger prctl() to set process name to "console",
which you could use as a simple means of figuring out if a process was
started from the system console.
There are other ways to do this, which Finit should not be involved in.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
In commit 34a1524 the start of udevd was refactored to allow it to be a
properly monitored service caused systems using eudev to malfunction.
This patch reverts part of that commit and adds a workaround found when
trying to reproduce issue #82 on Void Linux:
- Start a temporary udevd in the background
- Call udevadm to trigger bringup of all subsystems and devices
- Wait for everything to settle
- Tell temporary udevd to exit (new)
In the world of `mdev` this song and dance act is not required.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch, similar to the work done in the d-bus plugin, converts the
udevd service from a non-monitored run_interactive() task that forks
itself into the background, to a proper Finit monitored service.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>