Commit Graph
583 Commits
Author SHA1 Message Date
Joachim Wiberg fccba7cd4c Replace %m GNUism with strerror(errno)
Even musl libc supports %m today, as well as most syslog daemons, but
that's no excuse to use this.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-07 13:21:55 +01:00
Joachim Wiberg 3e8d63c29c Support for multiple (3) console= on kernel cmdline
Some targets, like Raspberry Pi, have both serial and HDMI console
enabled.  Depending on the order of arguments on the kernel cmdline
either one were selected the default 'stderr', which finit used.

This patch adds support for parsing the console= string(s) and
opening multiple outputs for system startup/progress.  In the
end, however, a getty still needs to be started on each of the
consoles to use.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-07 13:15:46 +01:00
Joachim Wiberg 18359ef448 Follow-up to 4febd28: bring back /dev, /proc, and /sys
We need /proc for rs_remount_root() and conf_parse_cmdline(), /dev for
early multi-console support, and /sys for the cgroups support.  All of
these may be in the system /etc/fstab, which fs_mount() later remounts.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-07 12:53:35 +01:00
Joachim Wiberg 0c85f8adfe initctl: add 'ls' alias for 'list'
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-06 20:55:09 +01:00
Joachim Wiberg 84c6ab737e Silence kernel output on console when starting up
Many systems have a very verbose kernel by default.  This patch calls
`klogctl(SYSLOG_ACTION_CONSOLE_OFF, NULL, 0)`, which is sysklogd also
calls but later when it starts emptying /dev/kmsg.

We do this to get an undisturbed console while starting up.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-06 20:37:41 +01:00
Joachim Wiberg 9e73fda2ac Follow-up to 4febd28: remount / as rw requires /proc to be mounted
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-06 20:37:41 +01:00
Jacques de Laval 022f140b3a Handle SIGPWR like SIGUSR2
This seems to be inline with Busybox init, SysV init and, according
to the comments in code, the intended behaviour of Finit.

The effect is that `SIGPWR` will lead to Finit issuing the syscall `reboot`
with `cmd` parameter set to `RB_POWER_OFF` (rather than `RB_AUTOBOOT`), which
in turn will lead to a halt rather than a reboot.
The effect of the above inside a PID namespace other than the initial PID
namespace is that `wait` inside the parent of Finit will report that Finit was
killed with a `SIGINT` signal rather than `SIGHUP`.
2021-02-02 15:13:16 +01:00
Tobias Waldekranz bdceeb83d5 Ensure that plugins are loaded before the first hook point
We want plugins to be able to register themselves at the banner hook
point, but that requires that we have actually loaded them before
then.
2020-10-20 09:48:33 +02:00
Tobias Waldekranz 100cea5d9f Read configuration after filesystem mount
The contents of /etc/finit.conf and friends could potentially change
after mounting /etc/fstab. If, for example, /etc was to be re-mounted
from ro to rw using an overlay filesystem, we want any user changes to
the configuration to take effect.
2020-10-20 09:31:58 +02:00
Tobias Waldekranz cc655609e2 Do not exempt basefs up hook in rescue mode
No other hook is treated in this fashion, so it seems silly to single
out poor HOOK_BASEFS_UP.
2020-10-20 09:31:58 +02:00
Tobias Waldekranz 18ab7d3183 Remove hard-coded hotplug and watchdog daemons
Instead of heuristically trying to determine the correct hotplug
daemon to use (mdev/udev), defer to the user to specify it in the
configuration.  Same goes for the built-in watchdog.
2020-10-20 09:31:58 +02:00
Tobias Waldekranz 4febd288ef Defer all filesystem setup to the user via /etc/fstab
Traditionally, Finit has setup _some_ filesystems that are Nice To
Have (tm), using options that do the Right Thing (tm).

On the one hand, this is very convenient for users that don't
necessarily know what a reasonable mode= value is for /tmp etc. (pun
intended).  It also means that mountpoints can be created if they
don't exist.

On the other hand it means that all users are forced to submit to the
choices made by Finit.  Also, different filesystems where spread out
at many different points in `main()`, meaning that the fact that
`/proc` was available at a given hook point did not imply that `/sys`
was, for example.

Instead, defer _all_ filesystem setup to the user by simply calling
`mount -a`.  We then ship an example `fstab` that shows how to
re-create the old behavior.
2020-10-20 09:31:58 +02:00
Tobias Waldekranz b280c8a16a Remove comments from fsck 2020-10-13 15:26:51 +02:00
Tobias Waldekranz 9c8df123e8 Always run banner plugin hook
Upcoming external plugin support means that even though there are no
internal plugins that depend on this hook, there might be external
ones.
2020-10-13 15:23:41 +02:00
Tobias Waldekranz e558d5871b Move argument-hiding magic together with argument parsing
Everything else Finit does related to parsing the incoming arguments
is in conf.c, so it makes sense for this block to also reside there.
2020-10-12 13:09:41 +02:00
Joachim Wiberg 24a78d3246 Update copyright years and author last name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2020-09-02 23:38:11 +02:00
Joachim Nilsson 57ab42bb7f Final (?) change to banner, use standard unicode bullet U+25CF
This patch to the banner "hello" is hopefully the last in this new style
progress.  Previous efforts have used unicode symbols not available in
all fonts.  This time we standardize on one that looks good both the
default Ubuntu Mono and Source Code Pro fonts.  It's a bit small in my
preferred font, Envy Code R, but that might be a mistake in the font.

Not tested with PuTTY or Windows Hyper Terminal.  I think they use the
Courier font by default, both of them, which I have tested.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 16:27:47 +02:00
Joachim Nilsson b7e4310542 Drop final period '.' in new style progress
Some ppl have their own '.' in service descriptions, adding anther just
messes things up and is confusing.  The old style progress still adds
dots, but thats for padding up to [ OK ].

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 16:12:57 +02:00
Joachim Nilsson 15ee8f172b Skip loopback in ifup if its already up, for containers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 13:38:36 +02:00
Joachim Nilsson 9e778aa7e8 Treat finit.conf tty console as /dev/console
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 13:13:45 +02:00
Joachim Nilsson 16e401f253 Revert "Add support for 'console' as compat alias to '@console'"
Because we want to reserve @console for going dumpster diving in
/sys/class/tty/console/active and 'console' to mean the literal
/dev/console

This reverts commit 217df432d6.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 13:10:10 +02:00
Joachim Nilsson fdead062cd Support reading --debug et al from process command line
Up until now Finit has only read /proc/cmdline to determine debug level,
single user mode, etc.  This patch is one in a series to make enable it
to run also in containers.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 13:08:41 +02:00
Joachim Nilsson 2dd5d40833 Switch traffic lights to more readily available unicode symbols
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-06-26 07:01:35 +02:00
Ming Liu a7adff4c4b helpers.c: dont hard code /etc/hostname
Introduce a macro HOSTNAME_PATH instead.

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
2020-06-09 10:51:19 +02:00
Joachim Nilsson 9eb8e8dd99 Only track built-in watchdogd, not external ones
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-05-03 12:01:41 +02:00
Joachim Nilsson 23461f1ef5 Track built-in watchdogd immediately after registering it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-05-03 12:00:35 +02:00
Joachim Nilsson 3b63946973 svc: The 'id' is optional now, lets default it to "" if unset
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-05-03 12:00:28 +02:00
Joachim Nilsson 1eca65fcda plugins: rtc: Move TZ set/unset to rtc plugin from Finit main
This patch makes the RTC plugin a bit more stand-alone, it is now also
back in the hands of the user to set a default timezone.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-05-03 11:04:48 +02:00
Joachim Nilsson b364492a8c Refactor prepare_tty() & C:o, pass tty around
Most of the helper functions around TTYs assumed that STDIN_FILENO was
already set up and unique for the give TTY they operated on.  It turns
out it wasn't.  This patch refactors the open() of TTYs to ensure we
do not clobber our TTY settings with multiple calls to tcsetattr() for
the same TTY.

Took a while to track this one down.  Usually I don't run systems with
more than one TTY, but the Alpine system on my home server did, and boy
I've never been this close to giving up on computers, ever.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-27 01:30:34 +02:00
Joachim Nilsson 484aa0ba97 Fix issue with VINTR, VEOF et al not being restored after boot
On Alpine Linux 3.6 the tcsetattr() calls failed.  This turned out to be
a deeply rooted issue not limited to just musl libc.  The workaround is
to call tcsetattr() in several rounds.  In particular the modem signals,
c_cflag bits, always fail, so we take a bet on Linux having set up the
terminals (hope as a strategy) and ignore that problem, for now.

Also, use TCSAFLUSH with tcsetattr(), that seems to work better and is
what BusyBox stty use.

The local CTL() macro is replaced with CTL() from ttydefaults.h, which
exists also in musl libc.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 22:06:59 +02:00
Joachim Nilsson 83078d1947 Ignore ENOENT from realpath(), origin probably moved
The svc_find_by_pidfile() function is called async from the pidfile
plugin, so by the time the queue is processed the origin may have
moved or been removed even.  Safe to ignore.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 21:46:24 +02:00
Joachim Nilsson e02f8cf353 Check result of fsck before attempting remounting / read-write
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 21:45:12 +02:00
Joachim Nilsson 317fe7aceb Follow-up to e16a6ad: cgroups must be initialized after /sys
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 21:41:53 +02:00
Joachim Nilsson 54fd38adcc Default to set TZ=UTC0 for RTC plugin
This patch sets the TZ variable to a sane default, UTC.  Fixing, at
least, the time restore problems of the RTC plugin.

Also, let the C library figure out DST, as the docs say -1 does ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 21:38:07 +02:00
Joachim Nilsson 5fd5e722a8 Only mount /proc if it isn't already mounted
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 15:05:17 +02:00
Joachim Nilsson e16a6ad4f0 Check if /sys exists and only mount if /sys isn't already mounted
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 15:04:56 +02:00
Joachim Nilsson 2f87c10cf1 Remount / as read-write as soon as possible (after fsck)
We may need to create directories early, e.g., /sys and directories in
/var that plugins rely on.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 14:56:45 +02:00
Joachim Nilsson 389328c99f Allow fsck for read-only mounted filesystems
When starting up a system booted from initramfs / may already be
mounted (read-only), so we can safely fsck it before proceeding
to remount it as read-write later (possibly).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 14:55:38 +02:00
Joachim Nilsson e3884597a5 Delay mount of /proc & /sys to *after* emergency_shell()
In case we run into problems mounting /sys or /proc we should have
signals and the optional emergency shell available for recovery.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 14:55:38 +02:00
Joachim Nilsson dc99d8637b Let create() macro return result of operation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 14:55:38 +02:00
Joachim Nilsson 3f5ff0d339 Export ismnt() and fismnt() helper functions, for modprobe plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 14:55:38 +02:00
Joachim Nilsson 37d92e87bc sig.c: Skip unknown signals, e.g. musl libc does not define SIGCLD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-26 11:29:19 +02:00
Joachim Nilsson c0b74c5e53 Fix minor build warning for --disable-inetd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 18:06:25 +02:00
Joachim Nilsson 88a6864fd4 Relocate docs/ --> doc/, like most other projects have
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 17:53:36 +02:00
Joachim Nilsson 8ed37f5fa0 Always append /ID to cond if run/task/service is declared with :ID
This patch is a follow-up to the idea introduced in 1d6737e, but this
time we make sure to always append the svc ID to conditions if their
.conf has been declared with :ID

Meaning, the following .conf:

    service :0 /sbin/teamd --config-file /etc/teamd-lag0.conf
    service :1 /sbin/teamd --config-file /etc/teamd-lag0.conf

results in the following two conditions:

    svc/sbin/teamd/0
    svc/sbin/teamd/1

With a custom 'name:foo':

    service name:lag :0 /sbin/teamd
    service name:lag :1 /sbin/teamd

the resulting conditions look even prettier:

    svc/lag/0
    svc/lag/1

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:22:29 +02:00
Joachim Nilsson 8fe4aad53e Make run/task/service :ID optional, default to zero/NULL
This patch makes the ':ID' field optional when registering non-inetd
run/taks/service etc.  It has always been optional in the .conf files,
but internally we defaulted to ':1'.

To open up for more useful conditions we now default to zero/NULL :ID,
meaning the user now *must* keep track of the :ID field if they have
multiple services with the same name.  This should already have been
an issue since such services would likely have conflicted with their
PID files (same name).  So it's unlikely to affect any user severely.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:21:28 +02:00
Joachim Nilsson 54e5fd2a78 initctl: Show :ID in process listing(s) only if non-zero
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 15:14:09 +02:00
Joachim Nilsson 1d6737eac1 Custom conditions include :ID; 'name:foo :bar' => svc/foo/bar
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 09:56:30 +02:00
Joachim Nilsson fa0c2f7050 Custom name:foo will now create condition svc/foo w/o path
When registering a service there is the option to set a custom PID file,
and even tell Finit to maintain that PID file in case the daemon doesn't

Until now there hasn't been a way to create custom conditions though ...

This patch leverages the new 'name:foo' argument to tas/run/services to
trigger condition 'svc/foo' (notice lack of path!) when a custom name is
set and either the default, or the custom, PID file is created.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 08:57:12 +02:00
Joachim Nilsson 70c0a38307 Provide description to built-in watchdog daemon
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 23:00:21 +02:00