Compare commits

...
2332 Commits
Author SHA1 Message Date
Joachim Wiberg 68c7352108 Update ChangeLog and bump version for 4.1-rc2
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-01 16:16:00 +02:00
Joachim Wiberg 0d40e43c4b Update ChangeLog with fixes for containers
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-01 13:33:35 +02:00
Joachim Wiberg 9867fd82df Check correct struct member to determine if / has 'ro' flag
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-01 12:50:48 +02:00
Joachim Wiberg 1c941fdfbb plugins: add support for disabling RTC and urandom plugins
Some systems may want to handle RTC and /dev/urandom by themselves, or
not at all as in the case of containers where the host does all this.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-01 11:43:58 +02:00
Joachim Wiberg 0ba67a72f8 plugins: add missing x11-common plugin to static libplug.la
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-06-01 11:43:26 +02:00
Joachim Wiberg 09b9e26b2d fs_init(): skip mounting proc/dev/sys if already mounted
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 17:35:07 +02:00
Joachim Wiberg d25c1d5564 logit: avoid modifying argv[] strings
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 17:03:10 +02:00
Joachim Wiberg d4358ed3f7 Drop nasty hide_args() hack, should not be needed anymore
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 16:51:08 +02:00
Joachim Wiberg cc6ffa35fc Drop parsing of /proc/cmdline by default, instead use argc + argv[]
For most use-cases the kernel will give Finit its arguments as proper
command line args in argc + argv[], like any other program.  However,
for some users, most notably Alpine Linux, there is a slightly broken
initramfs that cannot forward more than one argument using init_args,
for such systems you can re-enable the old behavior with a configure
switch --enable-kernel-cmdline -- it's not ideal but what can you do.

The main reason for removing this feature by default is to support
use-cases where Finit runs as the init for container apps that can read
/proc -- we do not want them to use the init args from the host.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 16:51:08 +02:00
Joachim Wiberg 55e9cb2f58 Update with info on dropped multiple consoles
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 13:59:21 +02:00
Joachim Wiberg 2641256254 plugins: sys: no need to compose path, name is already absolute path
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 13:58:30 +02:00
Joachim Wiberg 473116f603 Drop experimental multiple console output support
It has barely worked and only caused more problems than solved annoying
issues.  We have one console for output, /dev/console, which the kernel
sets up for us.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 10:48:37 +02:00
Joachim Wiberg e18d63df4a Always make sure to not acquire controlling TTY for output redirect
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 10:48:04 +02:00
Joachim Wiberg 4b1b3f6913 Update ChangeLog with latest changes
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 09:35:20 +02:00
Joachim Wiberg f6da5e4136 Revert "Travis-CI: disable clang temporarily for Coverity Scan run"
This reverts commit 754358113f.
2021-05-31 07:48:49 +02:00
Joachim Wiberg d1d5d39144 Fix possible NULL ptr deref, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 07:43:29 +02:00
Joachim Wiberg 754358113f Travis-CI: disable clang temporarily for Coverity Scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 07:27:12 +02:00
Joachim Wiberg c24207516d keventd: properly zero terminate buffer, found by Coverity Scan
Also, fix default: case in error handling, must always continue back to
poll() on any recv() error.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 07:22:50 +02:00
Joachim Wiberg 2a23bce78d Hide progress output also on stop/shutdown for services w/o -- descr
Progress at startup has been hidden for services w/o -- description, but
for some reason this check was not added to service_stop().  This patch
rectifies the situation, finally.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 07:17:48 +02:00
Joachim Wiberg a19b82ea5f Allow tty's to always respawn, no max restart count
This patch adds a `respawn` flag for services and ttys, always set for
ttys, that allows bypassing the crash/restart counter and immediately
restart a 'crashing' service.

For tty type services this is the expected behavior, but for regular
services it is not.  That is why `respawn` flags is not advertised in
the docs.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 06:29:11 +02:00
Joachim Wiberg ed9590aef1 Fix tty default :ID => tty:S0 instead of tty:ttyS0
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-31 06:27:59 +02:00
Joachim Wiberg 25683221cc Set default envs like sysvinit and busybox does; TERM, LOGNAME, USER
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 13:22:50 +02:00
Joachim Wiberg 9cc9e3ddbb getty: if we cannot execute /bin/login, try sulogin before /bin/sh
Basic security measure, don't bail to shell if we cannot find/exec
login, instead try sulogin before falling back to plain shell.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 12:42:48 +02:00
Joachim Wiberg 654f8aeb19 getty: handle variable number of arguments, only tty required
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:55:21 +02:00
Joachim Wiberg e349abb897 stty: allow utf8 input characters
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 3027a6755f Adjust logic in finding system consoles for progress/debug output
By default, Linux gives us /dev/console for output.  This is a pseudo
device that uses the same actual device as the last console=foo listed
in /proc/cmdline.  The last one listed is the main console, which is
also the *first* one listed in /sys/class/tty/console/active, so we skip
that when we check for system consoles to avoid duplicating output.

The getty code in tty.c currently has its own handling of @console,
which we keep for now.  Ideally, however, the code should be merged.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 5404aa6037 Refactor run_getty() and run_getty2() into one
By moving the built-in getty to a stand-alone bundled getty we can now
refactor the old run_getty() functions into a single one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg a319e32438 Clean up prepare_tty()
When TTYs became first class citizens in Finit 4.0 much of the
boilerplate setup is now down by service_start().  Also, the calls to
TIOCSCTTY, VINTR, and SIGINT ignore is not necessary to do here, it
should be done by the getty used, if any.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 2eaf57fc67 stty: simplify and ignore BREAK/SIGINT
It is up to /bin/login, sulogin, or plain shells to unblock SIGINT.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 88ec4a55cb Call setsid() before redirecting stdio or unblocking signals
We must detach from the controlling TTY before enabling signals and
setting up new stdio.  TTYs have their own handling of stdio.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 0acbc60ec1 initctl: drop confusing 'errno 0' from "Timed out" message
errno is not set when we timeout waiting for a reply from Finit.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 4362971c6a run(): Drop extra sig_unblock()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 94c0d1b833 Refactor built-in getty into a standalone getty in /libexec
This patch moves the built-in getty out of Finit into /libexec/finit/,
reducing the size of the Finit binary and simplifying the code.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 11:26:41 +02:00
Joachim Wiberg 1e795d4e16 Fix #175: Ensure finit does not acquire 'dev' as controlling TTY
When starting a getty Finit checks first that the configured TTY device
actually exists and is a TTY.  This patch, by Tobias Waldekranz, ensures
Finit (PID 1) doesn't acquire the TTY device as a controlling TTY.  If
that happens PID 1 will get all signals sent to the process actually
started with the device as its controlling TTY.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-30 00:33:31 +02:00
Joachim Wiberg 93a027ca23 plugins: netlink: fix gcc signed vs unsigned comparsion warning
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-27 11:18:06 +02:00
Joachim Wiberg 5f3958fab4 getty: max username is 32 chars, according to useradd(1)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-27 11:18:06 +02:00
Joachim Wiberg 1351b708fe Fix parse error for detecting external getty
When an external getty is used, and an absolute path is not given, the
parser tried to use access() to determine built-in vs external getty.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-27 11:18:06 +02:00
Joachim Wiberg e867e039bb Follow-up, document SIGINT/SIGPWR in comment, add missing include
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-27 11:18:06 +02:00
Joachim Wiberg 1d1087a3b3 Merge pull request #174 from troglobit/fix-kmsg-log-level
logging: Disregard logging facility when comparing log levels
2021-05-20 19:00:08 +02:00
Jacques de Laval e91f1ea1b2 logging: Disregard logging facility when comparing log levels
If we don't extract the level (disregarding facility), statements such as
"logit(LOG_CONSOLE | LOG_NOTICE, ...)" would never reach the kernel log.

Signed-off-by: Jacques de Laval <Jacques.De.Laval@westermo.com>
2021-05-20 17:19:53 +02:00
Joachim Wiberg 55d16edadc contrib: update /etc/finit.conf examples
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-18 09:02:58 +02:00
Joachim Wiberg b79245ddb3 Add support for sys/pwr/fail and sys/key/ctrlaltdel conditions
This patch drops the default signal handlers for SIGPWR and SIGINT with
optional tasks in /etc/finit.conf, triggered by two new conditions:
sys/pwr/fail and sys/key/ctrlaltdel, respectively.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-18 08:58:11 +02:00
Joachim Wiberg e706300b6d keventd: rename fgetln() -> fgetline()
Apparently fgetln() is available in musl libc, but not glibc.  This is a
funciton that first appeared in 4.4BSD.  We take a risk that fgetline()
is free in all libc's, getline() is not.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-17 00:44:39 +02:00
Joachim Wiberg d08cbd77aa keventd: use poll.h, not sys/poll.h, fix warning on musl libc
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-17 00:41:35 +02:00
Joachim Wiberg b070ae73a4 Revert "Travis-CI: disable clang temporarily for Coverity Scan run"
This reverts commit f52c141062.
2021-05-17 00:33:30 +02:00
Joachim Wiberg 2c30eef9a1 Update changelog for v4.1 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-17 00:32:43 +02:00
Joachim Wiberg 31cdc113fc doc: update build instructions and examples
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-17 00:32:21 +02:00
Joachim Wiberg f6f813498b doc: add some info about keventd, what it does
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-17 00:32:11 +02:00
Joachim Wiberg 4c8baaf7c0 Make kevent a configure option, disbled by default
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-17 00:26:57 +02:00
Joachim Wiberg 57ca937f27 New function to create onshot conds without updating
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-16 23:37:41 +02:00
Joachim Wiberg d13e39e345 keventd ftbfs: add missing include path to libite
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-16 23:35:39 +02:00
Joachim Wiberg f52c141062 Travis-CI: disable clang temporarily for Coverity Scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-16 23:21:31 +02:00
Joachim Wiberg 40042da8ff contrib: debian: add anacron and cron services
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-15 10:36:05 +02:00
Joachim Wiberg c251304146 Refactor sys condition plugin into a standalone keventd
This patch is a refactor of the prototype sys condition plugin.  It
moves most of the logic to monitor kernel events into a keventd that,
currently only, sets and clears the sys/pwr/ac condition.  The sys
plugin itself is now only a monitor of conditions and ensures Finit
follows them.  This is a lot more secure and moves (at least one piece
of) netlink processing out from PID 1.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-15 10:31:08 +02:00
Joachim Wiberg c047e37a79 cgroup: ensure all services in init group remain as leaf nodes
The top-level cgroup init is a leaf group and should be treated as such,
even for user setup tasks/services.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-15 10:29:29 +02:00
Joachim Wiberg d2c57447f0 initctl: no error if failing to remove non-existing usr condition
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-15 10:29:01 +02:00
Joachim Wiberg 79e9dabc11 Fix bug: re-registering a former service as task does not work
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-15 10:28:29 +02:00
Joachim Wiberg b04dc4d457 Ensure services in plugins and from finit.c belong to a cgroup
The udevd, dbus, bundled watchdog, and others were started without a
valid cgroup.  This is a workaround to ensure they are assigned one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-15 10:27:59 +02:00
Joachim Wiberg f86e7810be sig.c: disable kernel default ctrl-alt-delete handler
This fixes a long-standanding issue with finit not controlling the
reboot when the user presses ctrl-alt-delete (PC systems).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-14 10:34:54 +02:00
Joachim Wiberg 2018c82ea1 plugins: sys: watch uevent to prevent feedback loop
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-13 21:20:08 +02:00
Joachim Wiberg c27f3603e6 plugins: sys: use counting semaphores to handle >1 AC supply
- Track number of ac and ac online
 - Use systemd logic to assert sys/pwr/ac also when no supply

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-13 08:45:49 +02:00
Joachim Wiberg 6f82b806ad plugins: new sys condition event monitor (wip)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-11 07:02:49 +02:00
Joachim Wiberg cbb8935660 New functions: fnread() and fngetint(), companions to fnwrite()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-11 07:02:30 +02:00
Joachim Wiberg 21ebbb942f plugins: bootmisc: minor, whitespace
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg 988ecd95e3 plugins: bootmisc: only create /run/lock if missing
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg 3f3e70c686 Mount /dev/pts with gid of tty group and set nosuid, noexec flags
Note, this code only runs if /dev/pts was not mounted in /etc/fstab

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg 073b040981 Prevent user DoS by mounting /run/lock as separate tmpfs
This patch does several things related to /run and system reliability.

 - Mount /run with MAX 10% of usable RAM
 - Create and mount /run/lock as a separate tmpfs with max 5 MiB

As a spin-off, this patch also fixes permisions on /run/lock to 0777
so regular users can create lock files.

Note: none of this code runs if /run is mounted alread in /etc/fstab

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg b1a058ccdd doc: update TODO a bit, remember -s for initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg cbc7b8c3c7 plugins: bootmisc: add S02sudo setup for Debian systems
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg 13340e4200 contrib: debian: start tty's on tty1-tty6 clear 2-6
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg 0076c1f218 contrib: debian: add apparmor, avahi, and bluetooth services
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg 6fc71b7528 Follow-up to a1af8e8: mount /tmp with perms for all users
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-09 14:38:16 +02:00
Joachim Wiberg b42f1e99e2 README: use absolute path in sshd example, it requires that
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 22:29:23 +02:00
Joachim Wiberg afd6ad06a6 README: drop urls from initctl help text to sync with app
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 22:28:50 +02:00
Joachim Wiberg ea0bfaa2f3 Revert "Travis-CI: disable clang temporarily for Coverity Scan run"
This reverts commit 40425ee9ec.
2021-05-07 21:15:37 +02:00
Joachim Wiberg 5c3ec176c2 Update changelog, issue #173
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 20:19:31 +02:00
Joachim Wiberg 40425ee9ec Travis-CI: disable clang temporarily for Coverity Scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 19:45:28 +02:00
Joachim Wiberg 424db825a3 plugins: netlink: error handling fixes
Handle EAGAIN properly, for both regular and resync flow, on any error
in the regular flow (unless ENOBUFS) we want to check for nl_ifdown on
any of the successfully parsed messages.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 17:02:09 +02:00
Joachim Wiberg b9cc4cd629 Revert "plugins: fix #173, increase size of netlink socket receive buffer"
This reverts commit add55cfc2a.
2021-05-07 16:50:04 +02:00
Joachim Wiberg 243b8f025b plugins: netlink: refactor and reduce recv() buffer
This patch adds support for calling recv() repeatedly to get the netlink
response from the kernel.  As a result, the recv() buffer can be reduced
down to 4k again.

Both the regular flow and the resync flow now follow the exact same code
path, except for the ENOBUFS handling.  If we get ENOBUFS in resync, we
are screwed anyway.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 16:42:42 +02:00
Joachim Wiberg 6c60b67588 plugins: netlink: fix resync request size alignment with kernel
For RTM_GETLINK we need a `struct ifinfomsg`, not `struct rtmsg`,
otherwise the kernel will get 8 extra bytes and complain about it.

This patch makes sure to set the correct iface change mask as well, and
increases the debug logs a bit to get a fix on sizes used.  We increase
the recv() buffer 8k -> 64k to make sure we can get all data in one big
swoop.  Plan is to refactor this mess in a later commit.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 15:20:25 +02:00
Joachim Wiberg 910bb13711 plugins: netlink: redesign to handle ENOBUFS with kernel resync
This is a major redesign of the netlink plugin to be able to handle
ENOBUFS¹ properly.  Pending verification, this change replaces the patch
to increase socket buffer size, which in real life turned out to be
insufficient.

When nl_callback() calls recv() and it fails with ENOBUFS, we consider
our cache of the kernel state invalid and thus:

  1. deassert all net/ conditions
  2. open a new (temporary) netlink socket
  3. send RTM_GETLINK  and re-assert all interfaces using nl_link()
  4. send RTM_GETROUTE and re-assert all routes with nl_route()

Like before, the kernel will not send us a RTM_DELROUTE when it removes
the default route, so we still have to track this ourselves.  This patch
also refactors that functionality to only resync routes when the ifindex
associated previosly with the default route goes down or is removed.

The previous change that added nl_default() to recheck, has been dropped
to instead reuse the standard nl_route() callback.
___
¹ see netlink(7) for details.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-07 13:06:47 +02:00
Joachim Wiberg add55cfc2a plugins: fix #173, increase size of netlink socket receive buffer
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-04 13:19:54 +02:00
Joachim Wiberg 565820325b Follow-up to a1af8e8: nodev is a mount flag as well
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-04 07:36:41 +02:00
Joachim Wiberg 6bb4d67d92 Follow-up to a1af8e8: fix mount options vs mount flags
The nosuid, noexec, and relatime arguments are not mount options, but flags.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-04 07:34:39 +02:00
Joachim Wiberg 534d50c03a Fix diff link
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 16:09:27 +02:00
Joachim Wiberg 9a42883a96 Bump version to 4.1-rc1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 16:09:21 +02:00
Joachim Wiberg 7c77e2c2b6 Update with major bug fixes for 4.1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 15:25:03 +02:00
Joachim Wiberg ea8c46cd30 Fix #170: check for loss of default route when interfaces go down
This patch fixes the problem with Linux not sending netlink route change
notifications when interfaces for these routes goes down.  When an iface
goes down we now send a route request to the kernel and check the return
message, if no default route is found we deassert net/default/route.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 15:18:25 +02:00
Joachim Wiberg fead3b0671 configure.ac: drop grub Makefile.in generation
Not needed anymore.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 09:34:27 +02:00
Joachim Wiberg 081990b49e Update for upcoming v4.1 bug fix release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 03:50:12 +02:00
Joachim Wiberg 6b89f8c6db contrib: debian: update README with new grub setup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 03:39:08 +02:00
Joachim Wiberg 373097040a contrib: debian: update install legend
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 03:03:30 +02:00
Joachim Wiberg a4ab75172c contrib: debian: use SUPPORTED_INITS instead of custom entry
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-03 01:53:09 +02:00
Joachim Wiberg 5cf9958957 contrib: debian: read parameters from /etc/default/grub
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-02 15:43:27 +02:00
Joachim Wiberg b137e08e84 contrib: fix install script to be able to run from tarball
The file autogen.sh is not included in tarballs.  Use configure.ac
instead to detect topdir.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-02 15:30:13 +02:00
Joachim Wiberg a1af8e8687 Follow-up to 4febd28: restore mount of /dev/shm et al for Debian
This patch restores parts of 4febd28, but in a more orderly fashion, in
order to get a standard Debian system to boot properly with X and tools.

The patch adds fs_finalize() which checks if /dev/sh/, /dev/pts, /run,
and /tmp have been mounted properly from /etc/fstab.  If not, then the
function makes sure to mount tmfps (or devpts) file systems as expected
by most modern systems.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-02 15:21:50 +02:00
Joachim Wiberg 53c7ddcb22 Change SIGUSR1 to be compatible with systemd and SysV init
This patch changes the behavior of SIGUSR1.  Previously USR1 could be
used to halt a running Finit system, similar to BusyBox init.  However,
compatibility with sysvinit and systemd has been deemed more important.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-05-02 14:48:49 +02:00
Joachim Wiberg 3872077ff1 plugins: netlink: stricter interface name validation
Coverity suggests validating against only a set of known characters.
However, the kernel allows just about all characters in an interface
name.  This version of valdiate_ifname() is blatantly stolen, more
or less, from linux/net/core/dev.c

 https://code.woboq.org/linux/linux/net/core/dev.c.html#1020

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-29 17:19:19 +02:00
Joachim Wiberg 9e85c4f3d1 Bump version for v4.0 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-26 01:01:20 +02:00
Joachim Wiberg 2531102623 sulogin: ensure Ctrl-D returns OK(0) also for pwd login prompt
sulogin should return OK (exit code 0) when the user presses Ctrl-D,
regardless of the prompt shown.  Otherwise Finit may look for another
sulogin to run straight after this one.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-26 00:59:01 +02:00
Joachim Wiberg 33deada6f0 README: mention new rescue mode in feature list overview
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-26 00:52:40 +02:00
Joachim Wiberg 9d1506bb7e Revert "Travis-CI: disable clang for coverity scan run"
This reverts commit e011dac98b.
2021-04-26 00:45:57 +02:00
Joachim Wiberg c3f115c9ec sulogin: fix build issue
Keyboard suddenly lost CapsLock -> Ctrl remapping ...

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-26 00:39:39 +02:00
Joachim Wiberg 430d402b14 sulogin: check for Ctrl-D also if no pwd to abort and continue boot
Signed-off-by: Joachim Wiberg <joachim.nilsson@westermo.se>
2021-04-26 00:25:24 +02:00
Joachim Wiberg e011dac98b Travis-CI: disable clang for coverity scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 23:57:41 +02:00
Joachim Wiberg 42b84d1ccb Update ChangeLog for v4.0 GA
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 23:57:02 +02:00
Joachim Wiberg 288105eac7 sulogin: must fflush() prompt on Alpine Linux (musl libc)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 23:14:05 +02:00
Joachim Wiberg 842b522e68 Drop --disable-logit configure option, no longer in $PATH
Simplify build system.

The logit tool is, as of v4.0, installed into /libexec/finit/logit and
thus not part of the system $PATH.  If a sysadmin or distro wants to
remove it from the system it's entirely possible since Finit always
checks for logit availability before attempting to use it.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 22:53:34 +02:00
Joachim Wiberg e6f36974c8 Document all facets of rescue mode; traditional and fallback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 22:46:43 +02:00
Joachim Wiberg 679b4df881 Fallback rescue mode handling
Before 4e5d06b the only way to go into rescue mode was to skip certain
steps and then attempt to load /lib/finit/rescue.conf.  After 4e5d06b
we keep the old handling as a fallback in case early sulogin fails.

The new tty option 'rescue' is added, which recue.conf is updated with.
This option implies notty mode and will try sulogin (again) before it
falls back to start /bin/sh as a login shell.

The reason we keep this is to be able to handle all possible use-cases
and also allow sysadmins to set up the behavior that fits their needs.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 22:10:42 +02:00
Joachim Wiberg 666cae6f49 service_start(): allow notty TTYs without device to start
A notty TTY can be declared with or without a device, it requires none.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 22:09:07 +02:00
Joachim Wiberg be2ac1d1b1 sulogin: handle no password and locked account (treated as no pwd)
This patch does two things:

 1. A system with a root account that has no password is now
    allowed to login without password, as one expects.
 2. A systems with a locked root account, is treated as (1).

The latter of the two may very well turn out to be a really bad idea.
Much angst have been poured into it, yet the end decision is to allow
access.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 21:43:39 +02:00
Joachim Wiberg 266e5b30eb Drop all mention of old fallback shell from comments
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 21:43:16 +02:00
Joachim Wiberg 4e5d06b580 Replace experimental emergency shell with actual rescue mode
Most major init systems have a way to start a rescue shell.  This is
usally started when the string `rescue` is read from the kernel's
command line.

The traditional Finit way of handling this has been to skip certain
phases of the standard boot, skip /etc/finit.conf et al, and go for a
/lib/finit/rescue.conf instead.  This pratice has been imroved over
the last few commits with a sulogin.  However, there was no way to
resume boot, like most other init systems offer.

This patch implements a very simple rescue mode, utilizing the new
sulogin, replacing the old (and experimental) emergency shell.  If
Ctrl-D is pressed at the maintenance login prompt the boot is now
resumed.  The same goes for exit/Ctrl-D from the maintenace shell.

The preferred sulogin is the bundled /libexec/finit/sulogin, but
if that isn't installed, the first one in $PATH is used.  If no
sulogin at all is found, Finit proceeds as before this patch, to
skip certains steps and go for a /lib/finit/rescue.conf.  Hence,
al steps can be controlled by an administrator.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 21:32:35 +02:00
Joachim Wiberg fe334135ce Fix small memory leak, use whichp() to query, not which()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 19:47:15 +02:00
Joachim Wiberg aef10fb5e7 Revert "Travis-CI: disable clang for coverity scan run"
This reverts commit 550ae9c784.
2021-04-25 19:47:04 +02:00
Joachim Wiberg 86707c1f0b sulogin: minor refactor, splice out sh() as separate function
- splice out sh() as a separate function
 - make sh() session leader and set controlling TTY (TIOCSCTTY)
   to make it a proper login shell with Ctrl-C functionality
 - simplify call to execl()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 19:28:03 +02:00
Joachim Wiberg a28d5b3c09 sulogin: fix minor issue found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-25 19:27:42 +02:00
Joachim Wiberg 550ae9c784 Travis-CI: disable clang for coverity scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 20:45:44 +02:00
Joachim Wiberg cd5b91680a sulogin: home cooked version, can be built -static
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 20:43:54 +02:00
Joachim Wiberg 221ab20898 tty: add basic security, call sulogin in rescue mode (notty)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 20:27:26 +02:00
Joachim Wiberg 96534789db Minor, rename LOGIT_PATH -> _PATH_LOGIT for consistency
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 20:26:52 +02:00
Joachim Wiberg 26128dd788 plugins: skip plugin in rescue mode
These plugins should not run in rescue mode, because the system may be
in a very bad state and we do not want to make the situation any worse
than it already is.

Essentially, only services in rescue.conf should run in rescue mode.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 19:46:43 +02:00
Joachim Wiberg 799e992542 tty: minor, rename local variables for consistency
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 10:33:58 +02:00
Joachim Wiberg fa524eec60 contrib: debian: add elogind.conf and update recommendations
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 10:33:57 +02:00
Joachim Wiberg 6dced29b49 Add another constraint for the built-in watchdog, device exists
- Check if watchdogd *and* `WDT_DEVNODE` exists before registering the
   built-in watchdogd at boot
 - Update bootstrap.md with this additional constraint
 - Update config.md with references to bootstrap and the new constraint

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 10:33:57 +02:00
Joachim Wiberg 2ea613a42b Make sure built-in watchdog is disabled by default
Omitting --without-watchdog caused the watchdog to be enabled.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 09:43:27 +02:00
Joachim Wiberg 985df20519 cgroup: don't warn on cgroup.events EINVAL for top-level groups
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 07:42:31 +02:00
Joachim Wiberg f6161b9be9 doc: Add blurb on bundled vs external watchdog, handover and reset
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-24 07:41:46 +02:00
Joachim Wiberg 25c5014d3c Also check env: file for changes to detect svc->args_dirty
This patch fixes an issue where services that support SIGHUP are not
properly stop/started on changes to their command line arguments.

A change to a service's env: file, e.g. /etc/default/foo for service
foo, must also be counted as a change to the foo args.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-23 17:12:59 +02:00
Joachim Wiberg b8b7b53d96 External plugins require exporting cgroup.h, svc.h needs it
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-20 01:48:03 +02:00
Joachim Wiberg 7707c4b8e6 initctl: only show key capture in debug mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 15:56:39 +02:00
Joachim Wiberg 437f95f00f Bump version for final (?) release candidate, v4.0-rc4
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 15:40:26 +02:00
Joachim Wiberg 099672fabb configure: change --enable-redirect -> --disable-redirect
This changes the default to redirect output from run/task/services to
/dev/null.  Use --disable-redirect to get the old pre v4.0 behavior.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 15:25:57 +02:00
Joachim Wiberg 860515a716 contrib: load softdog module on Alpine/Void Linux for finit-watchdog
We need at least the softdog watchdog driver loaded for proper watchdog
reset at reboot.  This can safely be replaced with a hardware specific
module that provides /dev/watchdog ... without one Finit will try to
restart the built-in finit-watchdog service 10 times to no avail.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 14:52:28 +02:00
Joachim Wiberg c85551a42e watchdog: wait for WDT reset only if watchdogd is running
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 14:41:48 +02:00
Joachim Wiberg 79dc6e7472 Update Travis, Alpine, and Void build options
- Fallback shell has been removed
 - Built-in watchdog has been renamed

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 13:55:24 +02:00
Joachim Wiberg 06e456384c watchdog: Enable --with-watchdog[=DEV] and improve log messages
This patch changes the configure option to enable the built-in watchdog
from --enable-watchdog to --with-watchdog[=DEV].  This is the convention
for features that take arguments.

Also, improve log messages to aid debugging when finit-watchdogd does
not start properly.  This means flushing logs to syslogd with closelog()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 13:41:31 +02:00
Joachim Wiberg 38f7d24a80 tty: clean up developer debug messages
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 11:05:07 +02:00
Joachim Wiberg 145c78ef3e Follow-up to 7f76202: Remove fallback-shell from configure summary
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 11:05:07 +02:00
Joachim Wiberg dd437bf0a5 Follow-up to 18ab7d3: restore start of built-in watchdogd
This patch restores the start of the built-in/bundled watchdogd.  It is
tracked in the `wdog` variable and handled as an exception at shutdown.

This is also a follow-up to 7b74c99, ensuring that we only kill/stop the
built-in watchdog, not any external.  External ones can register to be
the controlling watchdogd in the system -- Finit is not the arbiter for
singletons, this is up to the system engineer.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 11:05:07 +02:00
Joachim Wiberg d82d119729 plugins: handle corner case when PID file doesn't exist
If we get a notification and the service dies immediately, and also
removes its pid file, we need to take corrective action.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-19 09:45:57 +02:00
Joachim Wiberg 7f76202865 Simplify, drop --enable-fallback-shell from configure script
Recommend using `notty` option in tty stanza instead.  See the updated
docs for details.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 23:13:19 +02:00
Joachim Wiberg aee92751ac Minor, add env: and sysv examples to first example .conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 16:24:19 +02:00
Joachim Wiberg 2ea7236d45 Add feature list immediately after screenshot
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 14:52:50 +02:00
Joachim Wiberg cedc04e1e3 Revert "Travis-CI: disable clang for coverity scan run"
This reverts commit 0168b765c1.
2021-04-18 12:37:21 +02:00
Joachim Wiberg edc6eb1747 initctl: fix too small destination buffer (unlikely)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 12:24:49 +02:00
Joachim Wiberg be5ec94fdf Fix GCC warnings for unhandled return value
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 12:24:32 +02:00
Joachim Wiberg 23a13fe1b6 initctl: add hidden command line option -d,--debug
For developer use only.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 12:23:58 +02:00
Joachim Wiberg 0168b765c1 Travis-CI: disable clang for coverity scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 11:55:25 +02:00
Joachim Wiberg 01358a5a45 doc: update service with pre:script and post:script actions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 11:37:01 +02:00
Joachim Wiberg 106516d12d doc: update tty config, detail <COND> and @console vs console
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 11:34:57 +02:00
Joachim Wiberg ba858743e5 Fix #129: add pre:script and post:script action support
This patch updates the service state machine with two new states: SETUP
and CLEANUP.  If an executable pre:/path/to/script is defined for a
service, it is called every time the task goes to READY state.  If an
executable post:/path/to/script is defined for a service, it is called
when the task goes to HALTED state.

Each of these two scripts default to a three (3) second execution time
before they are SIGKILLed.  This can be adjusted with the `kill:SEC`
option for the service.  There are no execution guarantees, nor are
there any way of detecting if the script was killed before completion or
not -- except for running Finit in debug mode and inspecting the result
printed by system_monitor().

Note: the post:script MUST be idempotent since transitions between READY
      and HALTED can take place any number of times before a task goes
      to its RUNNING state.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 11:33:38 +02:00
Joachim Wiberg 9fd860ef3c initctl: cgroup and status commands should show mem.min numeric
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 10:37:38 +02:00
Joachim Wiberg 46ccdc3820 Fix ordering issue, pid is unset for kill(-pid, SIGKILL) op
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 09:52:48 +02:00
Joachim Wiberg 242fe54afd initctl: standardize on code=signal for signaled/killed cause
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 09:51:53 +02:00
Joachim Wiberg df5d296cd9 initctl: fix too small buffer for extended status
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 09:51:33 +02:00
Joachim Wiberg dc4630f214 contrib: consistent naming across distro examples
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 06:21:25 +02:00
Joachim Wiberg ac07d3bac7 contrib: run klogd in same cgroup as syslogd (same .conf file)
These two BusyBox daemon's run in concert so it makes sense they also
share the same cgroup.  In Finit that means sharing the same .conf file.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 06:17:40 +02:00
Joachim Wiberg f641eef8f7 Adjust command length for built-in getty
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 06:08:14 +02:00
Joachim Wiberg f17b5b3cd3 init: move bug report+homepage from -h to -v
Also, detect progname to improve usage text slightly.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 05:52:36 +02:00
Joachim Wiberg d945f4960b initctl: move bug report+homepage from help to version
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 05:51:45 +02:00
Joachim Wiberg 6a5a6ac62f Fix tty command line recomposition for initctl -v
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 05:50:49 +02:00
Joachim Wiberg a9ba4300ec contrib: add ttyS0 to list of ttys to start in Alpine Linux
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 05:03:23 +02:00
Joachim Wiberg 7bb649f11a tty: don't block SIGHUP, needed to exit getty gracefully
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 04:57:37 +02:00
Joachim Wiberg 85ada0ac99 initctl: minor, add linefeed at end of top session
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 04:47:22 +02:00
Joachim Wiberg be343a3b34 plugins: call bootmisc:bootclean() in HOOK_MOUNT_POST
Before this patch bootclean() ran first in setup() which caused to to
remove the entire /var/run/finit directory, and other files as well,
created earlier.  Only possible fix is to split clean and setup in
two and make sure to call clean as soon as we've mounted everything.

Note: this introduces a new behavior, and anyone hooking into the
      same point to do good-stuff(tm) may be affected by this.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 04:34:48 +02:00
Joachim Wiberg 0ac0e5c7d3 plugins: create /var/run/finit/cond/pid directory
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 04:34:29 +02:00
Joachim Wiberg 7f272768e4 Log error if reconf cannot be written
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-18 04:31:56 +02:00
Jacques de Laval 7b74c9900f Revert "Only track built-in watchdogd, not external ones"
This reverts commit 9eb8e8dd99.
2021-04-15 11:34:07 +02:00
Joachim Wiberg 36f1a39b31 Revert "Travis-CI: disable clang for coverity scan run"
This reverts commit 8d3917e9fa.
2021-04-15 10:30:05 +02:00
Joachim Wiberg 6d380082eb ttinit: check retun value from tcgetattr(), only restore if OK
Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-15 10:11:06 +02:00
Joachim Wiberg 8d3917e9fa Travis-CI: disable clang for coverity scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-15 09:35:42 +02:00
Joachim Wiberg c3cd1a5bfa Merge pull request #166 from troglobit/tty-refactor
Tty refactor
2021-04-15 09:28:41 +02:00
Joachim Wiberg eaeddc36c2 Restore tty plugin after tty refactor
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-15 09:02:28 +02:00
Joachim Wiberg 4f40b65f0c svc_find_by_tty(): fix finder fn, check svc->dev, not name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-15 08:46:21 +02:00
Joachim Wiberg f958aa504e cond_set_path(): minor, improve debug, 'new' -> 'next'
- Avoid using reserved C++ keyword 'new'
 - Rename new -> next
 - Rename old -> prev
 - Add debug for value being set to cond path

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-15 08:44:03 +02:00
Joachim Wiberg 3d1b95aa7a tty: export tty_exists() to rest of finit (for plugins)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-15 08:43:32 +02:00
Joachim Wiberg 4bb67bc06f Restore @console handling and support for external getty
- Drop vhangup(), how did things ever work *with* this in?!
 - setsid() + TIOCSCTTY are best buds, see notty code
 - Allow storing any non-NULL string as tty->dev, expand in service_register()
 - Reorder parse_cmdline_args(), we need to expand @console to current dev
 - Fix tty arg parser, swapparoo for external getty
 - Refactor tty_atcon(), iterated over by service_register()
 - New arg format, need to translate for old run_getty2()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 23:41:22 +02:00
Joachim Wiberg 0929c93caf Misc. cleanup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 23:41:02 +02:00
Joachim Wiberg c0368d2b16 Refactor fallback shell handling, run as regular service
This patch re-enables the fallback shell handling after the big TTY
refactor.  We do this by allowing the fallback shell to run as a
regular service.

Note: this also adds the "hidden" support for 'notty' option for
      tty configurations stanzas.  This is just to pick up from
      where the kernel left us, reusing stdin + stdout.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 16:29:19 +02:00
Joachim Wiberg 85a212ef93 service_monitor(): cancel any pending SIGKILL timers
As soon as we collect a PID we should cancel any outstanding timer
actions.   Because we may very soon svc_del() it ...

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 16:29:19 +02:00
Joachim Wiberg 12c3cb3dc0 service_stop(): improve debug, show rc of kill(), and it's args.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 16:29:19 +02:00
Joachim Wiberg 16710e7ab5 Fix possible NULL pointer deref.
Some C-lib, like GLIBC, convert NULL to <nil> when printing %p,
which we shouldn't rely on since others just bite the dust.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 16:29:19 +02:00
Joachim Wiberg b652aaf0cb Rename nologin shell: finit-sh -> finitsh, as fallback shell
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 16:29:19 +02:00
Joachim Wiberg 30020263ba Refactor tty handling to use service backend enabling conditions etc.
Initial refactor of the tty implementation to use the service/run/task
general backend.  This enables all the features of services also for
ttys, except logging because it makes no sense.

Work in progress:

 - plugins/tty.c does not work anymore, could possibly be removed in
   favor of usinga (a new) condition instead (if-tty-exists)
 - fallback tty does not work anymore, should we remove it, or can we
   handle it as an optional built-in with (a new) condition?
 - @console does not work anymore, needs to generate N cloned services

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-14 16:29:19 +02:00
Joachim Wiberg 3cf5d36972 doc: example of timed shutdown
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 16:45:33 +02:00
Joachim Wiberg c9ae96bcf7 doc: status of processes now shown in initctl status foo
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 16:31:25 +02:00
Joachim Wiberg 5955110e67 Revert "Travis-CI: disable gcc for coverity scan run"
This reverts commit 4cfc8fec0e.
2021-04-10 16:26:56 +02:00
Joachim Wiberg 4191e15c77 Travis-CI: adjust install dir, plain /tmp gets crowded
Calling `tree /tmp` causes too long execution time and Travis timing out
the job.  So let's install to a sane directory.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 16:25:39 +02:00
Joachim Wiberg d60baa2b80 initctl: logically dead code, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 15:59:13 +02:00
Joachim Wiberg a50bc331db Fix possible string truncation, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 15:56:44 +02:00
Joachim Wiberg eff4453de9 initctl: add missing comma in signames[], found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 15:54:11 +02:00
Joachim Wiberg 4cfc8fec0e Travis-CI: disable gcc for coverity scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 12:06:46 +02:00
Joachim Wiberg c9e1c2f80f initctl: show exit status/signaled like systemctl
- Show if exited/signaled
 - Show status code and the std /NAME
 - Show signal value and the std /NAME

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 11:51:29 +02:00
Joachim Wiberg 93039e40cc initctl: usability improvements to ls/edit family of commands
- List /etc/finit.conf
 - Allow edit of /etc/finit.conf, using finit/finit.conf or NULL
 - Add helpful question to edit /etc/finit.conf if no edit arg.
 - Show available files if delete has no arg, like disable

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-10 08:56:26 +02:00
Joachim Wiberg 015a52a20d sample.conf: update with cgroup help and examples
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 19:52:12 +02:00
Joachim Wiberg d53cc8bfe7 doc: Fix run/task/service cgroup config syntax
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 19:51:47 +02:00
Joachim Wiberg 3c4eca60b7 initctl: fix restart of run/tasks, stuck in DONE state
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 19:51:03 +02:00
Joachim Wiberg c85e28b971 Yield execution in forked children back to PID 1
- Speeds up start-up a bit
 - Ensures the child is moved to its cgroup as soon as possible

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:59:33 +02:00
Joachim Wiberg d373068619 exec: only log when starting getty, not before
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:58:53 +02:00
Joachim Wiberg 997f3d7862 cgroup: fix possible NULL pointer deref.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:58:32 +02:00
Joachim Wiberg f12f53692e cgroup: allow adding self (PID 0) to a leaf group
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:58:11 +02:00
Joachim Wiberg b921b8cf0f cgroup: run all ttys, except rescue sh, in getty cgroup until login
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:32:31 +02:00
Joachim Wiberg 61781c72fe cgroup: Call ifupdown in system cgroup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:21:04 +02:00
Joachim Wiberg 3b5cfc5ecf test: drop checksef.sh from EXTRA_DIST, generated now
Also, silence generation of checkself.sh

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 18:05:02 +02:00
Joachim Wiberg a42a789d29 Refactor, clean up removed top-level cgroups
The main purpose of this patch is to remove top-level cgroups when they
are remvoed from finit.conf.  However, this is tricky, becasue there may
still be supervised services (and children of them) running.  We must
postpone removal until a cgroup.events change.  To make matters worse,
events may arrive out-of-order, i.e. the last-child event for the parent
cgroup before the sub-group.

A spin-off from this patch is that we can now support arbitrarily long
group names and group config.  (Only applies to top-level cgroups, not
run/task/services.)

Limitations:
 - Processes in "removed" cgroups are not migrated/orphaned, the reasons
   are several: overhead and complexity and the fact that memory cannot
   be migrated
 - A lingering child of a moved service may prevent an old top-level
   cgroup from being removed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-09 17:49:55 +02:00
Joachim Wiberg d77c014723 Add example of initctl status foo
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 17:11:35 +02:00
Joachim Wiberg 23fca9c067 Update initctl usage text, three new commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 17:04:13 +02:00
Joachim Wiberg 37eb1901f9 initctl: handle ~ECHONL properly in top command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 14:36:15 +02:00
Joachim Wiberg 98c4e7764f initctl: fix boolean logic bug in -p top command option
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 14:27:36 +02:00
Joachim Wiberg d3e4463612 initctl: add missing signal.h include, required for musl libc
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 14:20:48 +02:00
Joachim Wiberg b812045d82 doc: add cgroup documentation
First draft of the new cgroup documentation.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 14:16:25 +02:00
Joachim Wiberg b1bcdc88e0 initctl: fix ordering issue for root task in ps/top/cgroup commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 13:17:40 +02:00
Joachim Wiberg 62c5a9d06d cgroup: add support for reserved cgroup 'root', for RT tasks
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-08 13:17:10 +02:00
Joachim Wiberg dcdc842336 Revert "Travis-CI: disable gcc for coverity scan run"
This reverts commit 73629944c0.
2021-04-08 12:15:08 +02:00
Joachim Wiberg 12eaa3073a fnwrite(): call fclose() separately, found by Coverity Scan
If any of the fputs() calls fails we will not call fclose() and thus
cause resource loss.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 14:32:12 +02:00
Joachim Wiberg 34875f57a5 Fix uninitialized stack variable, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 14:00:08 +02:00
Joachim Wiberg f0bf1343b0 initctl: skip return value for uev_*_init(), optional
We have these neat extras for added value, if they should fail, for
whatever reason, we still want to present 'top' to the user, which may
have to use 'reset' if exited improperly and lost cooked/cursor.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 13:57:43 +02:00
Joachim Wiberg 4e6b9514d5 cgroup: check return value from fnwrite(), found by Coverity Scan
We check it everywhere else, and a log message for failing to move PID 1
to the init cgroup is useful as well.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 13:55:07 +02:00
Joachim Wiberg 3b495d7518 cgroup: fix too small buffer for strlcpy(), found by Coverity Scan
Off by one, of course.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 13:54:34 +02:00
Joachim Wiberg badf8701bf cgroup: fix use before NULL check, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 13:53:56 +02:00
Joachim Wiberg 85fa0d4926 cgroup: fix resource leak, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 13:53:25 +02:00
Joachim Wiberg 3de9643893 fnwrite(): fix resource leak, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 13:26:56 +02:00
Joachim Wiberg 73629944c0 Travis-CI: disable gcc for coverity scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 12:06:07 +02:00
Joachim Wiberg c97c83bfb6 cgroup: basic instrumentation of critical functions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 11:58:48 +02:00
Joachim Wiberg 19b18afac9 cgroup: Skip mkdir() and subtree control if group already exists
- No point in doing it twice
 - Don't anger the gods (possible kernel bugs)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 11:58:48 +02:00
Joachim Wiberg e3c424e129 Minor, rename internal variable
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 11:58:48 +02:00
Joachim Wiberg c0716d7f63 Minor optimization, drop expensive memset() ops
No need to zero out whole buffer for strlcat(), or other string check
ops.  Also drop a few completely useless memset() calls.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 11:58:41 +02:00
Joachim Wiberg d43af8c9c1 Minor optimization, use strdupa() for small alloc ops.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 10:31:59 +02:00
Joachim Wiberg 2825100f77 initctl: add support for 'q' to quit from top (also signals)
- Set TTY in raw mode to be able read a single char at a time
 - Hide cursor
 - Trap 'q', Ctrl-C, Ctrl-\ and SIGTERM to restore TTY and cursor

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 10:08:13 +02:00
Joachim Wiberg b1bee31d61 Helper functions for setting TTY in raw and cooked mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 10:07:26 +02:00
Joachim Wiberg 522276b80d Minor, rename internal functions/variables screen_* -> tt*
- Shorter
 - Follows old UNIX tradition
 - Lines up with next commit

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-07 10:06:01 +02:00
Joachim Wiberg 7bc1470a1e Minor, rearrange functions in mode order
Only moved functions around.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-06 14:38:24 +02:00
Joachim Wiberg ca32cb0dfc cgroup: 'init' is a reserved leaf group with Finit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-06 13:16:58 +02:00
Joachim Wiberg d59f55b90c initctl: new command 'cgroup' to show cgroup config
This is intended to be used with the 'top' command to aid in setting up
and verifying proper limits for services.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-06 12:03:20 +02:00
Joachim Wiberg 02936de993 initctl: initical conversion to use libuEv for top command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-05 23:56:39 +02:00
Joachim Wiberg 8ed223343d getty: fix regression introduced in 5342881
Replacing write() with dprint() without thinking leads to duplicate
output in getty.  In particular '\n login: foo login: ".

Must check if length is > 0, or dprint() will calculate it on its own.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-04 12:54:35 +02:00
Joachim Wiberg 90f7ff1c23 initctl: new command 'reload NAME:ID' and new semantics for restart
This patch corrects a logical glitch, or design flaw, in initctl.  The
'restart FOO' command did not stop+start FOO only send SIGHUP (provided
FOO supports SIGHUP).  Hence, a new command 'reload FOO' is introduced,
which does exactly that, and 'restart FOO' now stops and restarts FOO.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-04 12:35:35 +02:00
Joachim Wiberg a56220f158 Mark result of chown() as don't-care for now
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-04 12:35:35 +02:00
Joachim Wiberg d40b426c1b Refactor, check return value from fgets()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-04 12:35:35 +02:00
Joachim Wiberg 5342881bf4 Refactor, wrap write() syscall in new dprint() function
Fixes the GCC warning for unchecked return value from write():

  ... ignoring return value of ‘write’, declared with attribute warn_unused_result

The new dprint() function wraps write() in a bounded retry-loop that
catches EINTR.  The length argument is optional computed with strlen()
if omitted (zero).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-04 12:35:35 +02:00
Joachim Wiberg c84c17ea8c initctl: initial support for -q,--quiet mode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-04-04 12:35:35 +02:00
Joachim Wiberg f976b8261f Merge pull request #165 from troglobit/nohup-on-cmd-line-changed
Do a full restart rather than HUP if command line of a service has changed
2021-04-02 11:31:57 +02:00
Jacques de Laval 10f4c7fa18 Do a full restart rather than HUP if command line of a service has changed
By keeping track of when a full restart is needed, Finit can relieve
the user of having to track modifications to service configuration. This
also makes initctl reload easier to explain and reason about as the effect
of a reload should now be that any configuration updates to services will
be fully "commited" by initctl reload.

Signed-off-by: Jacques de Laval <Jacques.De.Laval@westermo.com>
2021-04-01 16:18:54 +02:00
Joachim Wiberg 665d212bd6 Add support for configuring cgroups and their settings on services
This patch adds support for modifying settings for the default cgroups;
init, user, and system, as well as adding up to a total of eight groups
for the system.

Services can now be assigned to a cgroup, with optional extra settings
for that particular process group.  The syntax is slightly contrivied
but follows the overall Finit syntax of prop:value,prop':value', e.g.

   cgroup maint cpu.weight:123,mem.max:10000

Starting with the introduction of rlimits, a group of services sharing
the same .conf file can share the same (locally "global") rlimits, and
now also the same cgroup, e.g.

    cgroup.maint
    service foo
    service bar cgroup:mem.max:1000

This puts foo and bar in the same top-level cgroup 'maint', with an
extra memory restriction on bar for max 1000 bytes memory.

NOTE: 'mem.' is a Finit extension, a shorthand for cgroups2 'memory.'

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-30 10:21:01 +02:00
Joachim Wiberg 9e6e653c57 plugins: pidfile: fix subtle memory leak
Since the introduction of the iwatch framework we can now safely free
the memory allocated by realpath() and prevent leaks in a more elegant
way than before.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-29 23:20:00 +02:00
Joachim Wiberg bda4da71a6 Fix touch-reload regression from 3bb1e41
When reloading we check if service .conf files have been modified since
the last time we read them.  In 3bb1e41 we changed it so we load only
the enabled/*.conf files, which led to our no longer properly detecting
changed files since we monitor changes in what the symlinks point to.

This patch fixes that by checking the target for changes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-29 23:15:36 +02:00
Joachim Wiberg a24fc941a6 telinit: call initctl with '-b' to prevent screen size probing
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-29 22:23:34 +02:00
Joachim Wiberg f307ad060b Follow-up to 0641b1a, prevent hang regression in bootstrap
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-28 16:38:07 +02:00
Joachim Wiberg 1845b7be54 The unix(7) man page recommends using SOCK_SEQPACKET
Since Linux 2.6.4 the SOCK_SEQPACKET socket type is available for UNIX
domain sockets on Linux.  It is intended for; "a sequenced-packet socket
that is connection-oriented, preserves message boundaries, and delivers
messages in the order that they were sent." which sounds like us.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-25 17:26:55 +01:00
Joachim Wiberg a260e157eb Move external getty and sh to user cgroup
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-25 17:26:31 +01:00
Joachim Wiberg 0641b1a73e Split finalize() in two separate tasks
The finalize() function is a bit too long, which means it may block the
API socket initctl (from the final runlevel switch at the beginning) use
to contact os via.

We should perhaps break it up even more, but at least once like this to
give the event loop a chance to interleave with an API callback.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-25 17:24:32 +01:00
Joachim Wiberg 9ba57f0c9d iwatch: ignore EEXIST errors, we're already watching it
In particular this can happen from cgroup.c when multiple services map
to the same cgroup.events (due to being in the same cgroup)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-25 17:22:42 +01:00
Joachim Wiberg 9c2f0b2dc8 initctl: finit may be busy, wait for it ...
When calling initctl early in the boot process, e.g. just when Finit is
switching to the final runlevel, it may take a few milliseconds for it
to actually be ready to process our request.

This patch adds poll() to both the write(REQ) and the read(RSP) steps
to prevent from getting weird errors when Finit is busy.  The timeout
is currently 2 sec in both directions, which should be enough.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-25 17:18:50 +01:00
Joachim Wiberg d4bbebeb93 plugins: hotplug: ensure we always call setup() *after* bootmisc
The bootmisc plugin creates lots of required system directories which
udev, and possibly also mdev, need to operate.  E.g., a system which
has an empty tmpfs for /var need to populate that before we run.

The plugin loader handled this dependency implicitly before, loading all
plugins in alphabetical order.  We should not rely on that for proper
operation.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-24 13:16:12 +01:00
Joachim Wiberg 1a22b4f0aa plugins: dbus: allow in all runlevels and start already in 'S'
This plugin should be able to start much earlier than on network UP,
it uses a UNIX domain socket to communicate so loopback should not be
needed.

Also, Finit supports runvels up to 9 (0 and 6 are special), so allow
dbus to run in all these runlevels.  It is up to the user/OS to set
any policy for what runlevels to use.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-24 13:13:35 +01:00
Joachim Wiberg 9c4d5341ae No env file, or optional ('-'), are both OK results
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-23 16:24:12 +01:00
Joachim Wiberg b9d498e01c initctl: fall back to .conf in /etc/finit.d if not in available/
For commands like `initctl show foo`, initctl looks in the available/
subdirectory for `foo.conf`.  This patch adds support for falling back
to return `/etc/finit.d/foo.conf` if the service doesn't exist in the
`/etc/finit.d/available/` subdirectory.

Static services, outside of the `enabled/` handling, live in the base
dirctory and this is what you expect from the tool.  "Do what I mean"

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-22 18:57:43 +01:00
Joachim Wiberg a1e38a3e40 cgroup: add missing pointer and result of fopen()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-22 14:28:25 +01:00
Joachim Wiberg c0ae7763a6 initctl: ignore possibly missing cpu.stat in cgroup2 root
Older kernels (4.19) don't have the summary cpu.stat in the cgroup2
root, so let's ignore that problem and return zero.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-22 10:47:52 +01:00
Joachim Wiberg 9f98b1d3d1 Merge pull request #161 from yangfl/upstream
Fix build for some non-x86 archs
2021-03-20 19:45:54 +01:00
yangfl a7e2224f05 Fix build for some non-x86 archs
Ref:
https://buildd.debian.org/status/fetch.php?pkg=finit&arch=mips64el&ver=3.2%7Erc3-2&stamp=1609910244&raw=0
https://buildd.debian.org/status/fetch.php?pkg=finit&arch=sparc64&ver=3.2%7Erc3-2&stamp=1609869348&raw=0
2021-03-20 23:57:08 +08:00
Joachim Wiberg 3bb1e41394 Only check for dangling symlinks, load enabled/*.conf file
In debug mode it's highly confusing to see Finit load available/*.conf
files when you expect it to only load finit.conf and enabled/*.conf,
so let's keep the dangling symlink check to itself and actually load
and parse from enabled/ as it was intended :)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-20 14:40:11 +01:00
Joachim Wiberg e437379939 Minor, style/clarify debug messages
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-20 14:39:49 +01:00
Joachim Wiberg 3ad4f6ef4b In garbage collect, don't clear conditions provided by new instances
Sneaky bug, when switching between different sets of configurations, a
new instance of a previously removed svc can have its condition removed
by svc_gc() of the old instance.  This patch prevents such accidents.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-20 14:27:01 +01:00
Joachim Wiberg 4170a61d0b Merge pull request #160 from troglobit/release
Forward port dirty vs enabled fixes from release branch
2021-03-19 17:23:36 +01:00
Joachim Wiberg b3c5ab41e7 Merge pull request #159 from troglobit/fix-dirty-removed-svc-restarting
Store removal status separate from dirty
2021-03-19 17:11:55 +01:00
Jacques de Laval b3fad1077e Store removal status separate from dirty
Having removal status stored in the dirty status resulted in removal
status being forgotten when a service was marked as dirty, for instance
when a dependency was updated. This side effect of marke_dirty seems a bit
unexpected and instead of adding exceptions to the logic for when marking
a service dirty - let's separate the two things (dirty and removed) from each
other.

Signed-off-by: Jacques de Laval <Jacques.De.Laval@westermo.com>
2021-03-19 16:53:04 +01:00
Joachim Wiberg 522e1f57d7 Merge branch 'release' 2021-03-19 10:01:55 +01:00
Joachim Wiberg d00a53dfbf Bump version for v4.0-rc3
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:53:26 +01:00
Joachim Wiberg ff86f29f41 initctl: add Memory: and CGroup: to process status command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:33:52 +01:00
Joachim Wiberg 3107027132 cgutil: new functions to query a cgroup from pid and get memory use
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:33:42 +01:00
Joachim Wiberg 728db73b09 cgutil: export more functions to initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:32:36 +01:00
Joachim Wiberg fcb8ec9967 Refactor, factor out and export memsz() util function
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:30:52 +01:00
Joachim Wiberg 5b8fe12502 cgroup: error handling for critical operations
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-19 09:29:27 +01:00
Joachim Wiberg 6e24f2ff13 echo(): refactor and rename helper function -> fnwrite()
More often than not, the file to write to in sysfs changes rather than
the value.  This patch changes echo() into a fnwrite(), flipping what
is vsnprintf()'ed, and adds a stupid str() function that converts any
value (float/int/double/uint64_t) to a static string buffer.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-18 18:25:11 +01:00
Joachim Wiberg 74d715243c sanitize(): avoid strlen() to check string for NUL termination
The strlen() function can easiliy go out of bounds.  Use memchr()
instead, we have the max buffer len as argument anyway.

Also fix call to sanitize() which used wrong length.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-18 18:23:50 +01:00
Joachim Wiberg d9993860cb cgroup: add inotify support for cgroup.events
Replaces previous cgreaper.sh functionality for release notification and
cleanup of service groups.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-18 18:23:38 +01:00
Joachim Wiberg 6a6f3a8291 cgroup: refactor for cgroups v2, much cleaner + unified hieararchy
Since the cgroups support in Finit is not yet officially released, we
decided to change the back-end to use cgroups v2 instead of the aging
and rather clumsy cgroups v1.  Even this initial refactor is a lot
easier to read and understand, more can still be done since there's
a lot of concepts, data values and the ilk that can now be shared
between different controllers.

Still ToDo: inotify for cgroup.events to clean up leaf nodes, which
            in cgroups v1 was handled by cgreaper.sh.  This is fixed
	    in the next commit in the series.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-18 18:23:35 +01:00
Joachim Wiberg 99a8cf3eb7 initctl: add -1,--once flag for top command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-16 23:09:01 +01:00
Joachim Wiberg da95c7d80e initctl: ensure lines don't overflow in top command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-16 23:07:14 +01:00
Joachim Wiberg a9f7f692a9 initctl: add more columns to top command; VmSize, RSS, VmLib, %MEM
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-16 16:49:08 +01:00
Joachim Wiberg ce55f88a00 cgroup: add symlinks for traditional split controller world
Even systemd have collapsed a few of the cgroup controllers into a
semi-unified hierarchy and uses this approach.  We just take it to
the extreme and have collapsed all of them (like cgroup v2).

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-16 16:47:08 +01:00
Joachim Wiberg 74a26f559d initctl: refactor, split into multiple files
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-16 09:23:04 +01:00
Joachim Wiberg 08144df5ea initctl: fix %CPU listing bug and use hash table for faster lookup
Two major bugs: `if (!cg)` and missing `strdup(path)`.

Also convert to use std hash table for lookup of previous cpu load value
for a given cgroup path.  The hash table is sized after the current num.
rows on the screen -- resize currently not supported.  The value given
to hcreate() should be 25% greater than the estimated num of entries,
but we take a wild guess just to make sure we don't run out of space at
runtime.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-15 13:43:37 +01:00
Joachim Wiberg 230c64927b initctl: add very bare-bones cgroup based top command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-15 02:21:43 +01:00
Joachim Wiberg d1e56f300d initctl: show cgroup cpu.shares and memory.usage in ps command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-14 22:16:20 +01:00
Joachim Wiberg 9842786453 cgroups: fix cpu.shares assignment and set memory hierarchy
- Fix obvious refactor mistake in cpu.shares assignment
- For unified memory hierarchy we need to set .use_hierarch=1

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-14 12:27:46 +01:00
Joachim Wiberg 6d0c679e05 initctl: show comm and cmdline in ps output
The ps command currently only lists processes in the three main control
groups: init, system, user.  Kernel threads are not show at all.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-14 11:12:42 +01:00
Joachim Wiberg 5428dea5bf cgroup: refactor, use a unified hierarchy for finit
As of now, the default finit cgroup behavior is to use a unified
hierarchy of controllers under /sys/fs/cgroup/finit.

We mount cpu,cpuacct,cpuset,memory (if available) and gain the
ability to control our three major groups: init, system, user.

The default CPU share setup is ~10% for init and user, and 90% for
system.  These are guaranteed CPU shares to ensure we do not starve
PID 1 or user processes.  Support for configuring these limits will
be added in a later commit.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-14 11:07:13 +01:00
Joachim Wiberg 4e84ecae89 Set umask(022) early, in fs_init(), and no place else
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-14 11:05:12 +01:00
Joachim Wiberg 959c9fe5aa plugins: restore previous umask() after plugin ops
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-14 11:04:29 +01:00
Joachim Wiberg 03d8ef9c8f doc: drop malplaced comment
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-13 09:45:37 +01:00
Joachim Wiberg 084b4ce8d3 cgroup: minor refactor/simplify
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-13 09:40:52 +01:00
Joachim Wiberg 31cae6a56d plugins: dbus: simplify, use mksubsys(), run as messagebus user
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-13 09:26:14 +01:00
Joachim Wiberg 1fd45c6f2e plugins: bootmisc: refactor, use mksubys() and simplify
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-13 09:26:14 +01:00
Joachim Wiberg 46995fe446 Add mksusbys() to helpers.c, a kind-of tmpfiles.d in C
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-13 00:37:47 +01:00
Joachim Wiberg 600b2874e6 initctl: add bug report address to usage text, like finit -h
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 17:08:36 +01:00
Joachim Wiberg b080b970b7 initctl: don't warn on missing env file if it's optional
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 17:08:12 +01:00
Joachim Wiberg 6106574e13 initctl: minor refactor, use systemf() instead of snprintf+system
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 16:49:01 +01:00
Joachim Wiberg 2385a1209b initctl: don't fall back to default command for wrong commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 16:48:58 +01:00
Joachim Wiberg e8b942cf95 Fix regression in starting built-in services, introduced in 5b9d990
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 16:28:16 +01:00
Joachim Wiberg ac17d7f5a7 Silence output from gzip in logrotate()
- system may not have gzip (we're opportunistic)
- system may not have the log file (yet)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 13:26:50 +01:00
Joachim Wiberg 1edc4356a6 initctl: improve error message for unprivileged users
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 13:26:16 +01:00
Joachim Wiberg 9f06a2db99 Silence developer API debug message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 13:25:50 +01:00
Joachim Wiberg cfb3a9f2b9 plugins: pidfile: reduce log noise
With the new practise of keeping record of process pid files, we no
longer need to log/update when reading back the same PID we already
have on file.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 00:35:13 +01:00
Joachim Wiberg 8aba63a9e3 Track oldpid of services to fix empty pid in restart message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-12 00:13:15 +01:00
Joachim Wiberg 3d98ad293b Restore telinit symlink to finit, compat only
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 23:59:39 +01:00
Joachim Wiberg 156e86f395 Revert "Travis-CI: disable clang temporarily for Coverity Scan run"
This reverts commit d859ecd21d.
2021-03-11 22:28:41 +01:00
Joachim Wiberg d859ecd21d Travis-CI: disable clang temporarily for Coverity Scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 22:04:56 +01:00
Joachim Wiberg cbec78dbbc initctl: show pid file and condition for foo in 'status foo' command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 22:01:42 +01:00
Joachim Wiberg 572291a1d9 Don't guess pid file name, either there's one declared or not
The previous patch just added dynamic tracking of non-declared pid
files, so we no longer need to make stuff up.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 22:00:29 +01:00
Joachim Wiberg 280608f30e plugins: pidfile: track PID file in svc, if svc has none declared
Services that create their own PID files usually don't declare one with
Finit.  This patch adds support to track those PID files anywayt at
runtime for the purpose of identifying match svc_t when a PID file is
removed, i.e. when a service exits.

 - On IN_CREATE the pidfile.so plugin saves the pid file name in svc_t
 - On ON_DELETE the pidfile.so plugin finds svc_t based on pid file

Quicker tracking and less dead code, win-win.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 21:56:49 +01:00
Joachim Wiberg 5c4146cfe4 Export pid_file_set() function, useful to other subsystems as well
Rename, refactor, and export.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 21:52:44 +01:00
Joachim Wiberg 30e3f5a33c Wait only one second at shutdown/reboot for lingering processes
Transitioning to runlevel 0 or 6 handles graceful shutdown of any
managed run/task/sysv/services.  So we can replace the old 2 sec delay
with a shorter one for any non-managed still lingering process.

Also, some minor cleanup.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 21:48:49 +01:00
Joachim Wiberg 2c12379a30 Only reload .conf files when not going to shutdown or reboot
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 21:47:22 +01:00
Joachim Wiberg 5f026c8149 initctl: when svc has status missing, highlight what is missing
To aid with debugging, highlight if env file, binary, or both are the
missing component(s) and causing status 'missing'.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 15:58:36 +01:00
Joachim Wiberg 90005235e8 initctl: minor, rename local variable
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 15:11:16 +01:00
Joachim Wiberg 6b688c4211 Refactor, share env helper fns with initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 15:10:10 +01:00
Joachim Wiberg bdf5f8fc90 initctl: show halted state status reason in bold everywhere
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 14:35:09 +01:00
Joachim Wiberg 79f7a8ccfb Reclaim 900 msec in boot time from final_worker() at bootstrap
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 14:03:15 +01:00
Joachim Wiberg 3b19db04e3 initctl: add cond, user, group and visual hints for status command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 12:52:05 +01:00
Joachim Wiberg 93402b81d7 initctl: disable ctrl chars also in runlevel_string() when -p
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 12:51:23 +01:00
Joachim Wiberg 6dec4c9ca0 Set default user/group for services that don't specify any
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 12:49:14 +01:00
Joachim Wiberg 548acf27cf Minor refactor, rename RESPAWN_MAX -> SVC_RESPAWN_MAX
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 12:48:44 +01:00
Joachim Wiberg cd0bc57ca8 Clear stale PID conditions when a service stops
Protect against corner cases where pid conditions are not cleaned up.
We don't want such conditions to remain asserted when the process has
terminated.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 11a3318c02 Properly set status 'missing' for missing binaries and/or env files
When we try to start a service/run/task we call whichp() to see if the
binary exists, either tha absolute path given in the .conf file, or in
the $PATH we run with.  If binary, or the env: file, doesn't exist we
now set svc_missing() state.

On `initctl reload` we unblock the service to be able to check again.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 2711b27971 plugins: pidfile: tricky zebra doesn't close its pid file
This patch fixes a few really hard problems wrt PID files:

 1. Listening for IN_CREATE events means we get notified immediately by
    the kernel when someone calls open()/fopen() on a PID file.  Reading
    the contents returns 0, thank you atoi() ... so we drop IN_CREATE
    and instead look for IN_CLOSE_WRITE, there fixed it!  Not quite ...

 2. Some programs, like Zebra, and other Quagga/Frr daemons, don't
    close() their PID files after creation.  Instead they ftruncate()
    and keep them open, and locked.  Presumably to get a mechanism to
    detect already running instances -- messes life up a bit for the
    rest of us though.  So we need to read files after IN_MODIFY too.

 3. We also want to track IN_DELETE so we can deassert conditions when
    services exit gracefully and clean up their PID files

The rest fo the commit is debug instrumentation changes.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 05ac9c18c9 Update changelog, new inictcl cond set|clear commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 1a7092f545 doc: update with new 'initctl cond set|clear foo' commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 8000d361b3 initctl: restore 'cond [set|clr] foo' for user-defined conditions
In 7447192 we dropped support for 'cond set' and 'cond clear' commands
with the motivation they were unsafe and sent the wrong message to the
user.  That was true, but mostly because it was too generic and required
the user to call `initctl reload` to apply the changes.

This patch restores the behavior, albeit in a very reduced and simple
format.  All conditions set with this command are constrained to the
'usr/...' namespace.  No subdirectories are allowed.  The argument to
the 'cond set|clear' command is disallowed if it contains '/' or '.'
but anything else is supported, for example:

    initctl cond set foo:2

creates a static/oneshot condition in /run/finit/cond/usr/foo:2

These conditions are static and are fully handled by the user.  The
initctl command is the recommended, and only supported, way of setting
and clearing usr conditions.

This patch also includes a new plugin, usr.so, which is a very simple
inotify plugin for the /run/finit/cond/usr/ directory.  When files are
created or removed here the plugin tells the Finit condition engine to
update and trigger service changes.

For instance, the following service is not started by default at boot:

    service <usr/foo> myservice -- MyService

However, as soon as `initctl cond set foo` is called, myservice starts.
Consequently, it is stopped when `initctl cond clr foo` is called.

Another major difference from the original is that this implementation
doesn't send IPC commands to create/delete the conditions.  This makes
calling these new commands non-blocking so they can be used very early
in the bootstrap, by plugins, if needed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg e3c8febe3b Refactor; common nomenclature, ordering, possib. security fix
- Use _PATH_foo for all condition paths, *with* trailing /
- Read condition file first, may not exist, in which case we save time
- Change from libte makepath() to mkpath(), this changes from hard-coded
  0777 perms on all cond dirs to 0755 -- possible security fix

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg 32ca117949 initctl: refactor command line parser, use concept from mroutectl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-11 11:44:23 +01:00
Joachim Wiberg b966d031c8 initctl: enable plain mode for ls and utmp commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-09 21:30:11 +01:00
Joachim Wiberg 905c2678a3 Fix path to fallback console and handle leading /dev from cmdline
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-08 09:33:16 +01:00
Joachim Wiberg 7d429bdbb1 initctl: restore -p,--plain output for headings and ps listing
This is the same output style as used in the mroutectl and pimctl tools.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 23:30:13 +01:00
Joachim Wiberg ccfea59cb3 Bump version for Finit v4.0-rc2 release
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 18:50:50 +01:00
Joachim Wiberg 7b315364ca Update initctl help text, and output, relocate screenshot
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 15:38:23 +01:00
Joachim Wiberg e9e28ece1c Add Finit4 + Alpine screenshot
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 15:28:32 +01:00
Joachim Wiberg c1f9b4e1f6 Use .svg for Travis-CI status badge
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 15:17:26 +01:00
Joachim Wiberg 6ebb23e0f0 Travis-CI: Minor, adjust configure line for Coverity
- Drop commented-out sudo:true
- Drop unnecessary configure option

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 15:16:26 +01:00
Joachim Wiberg 026c229005 Revert "Travis-CI: disable clang and unit tests for Coverity Scan run"
This reverts commit c71bafd495.
2021-03-07 15:14:47 +01:00
Joachim Wiberg 4d05bf9359 Mark affected services as dirty if their rdeps are dirty
Provided a configuration that looks like this:

ospfd.conf:
    service [2345] <!pid/zebra> log ospfd -A 127.0.0.1 -u root -g root -- OSPF daemon

zebra.conf:
    service [2345] <!> log zebra -A 127.0.0.1 -u root -g root -- Zebra Routing daemon

If zebra.conf is changed, we restart it when `initctl reload` is issued.

This change ensures that ospfd is also restarted, because ospfd depends
on zebra, we must restart it too.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 14:52:19 +01:00
Joachim Wiberg 289247dab9 plugins: netlink: slightly stricter ifname validation
Check if ifname contains double periods, this should *not* be a valid
name, though eth0.10 is, et0..10 is not.  Should protect better against
directory traversal attacks.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 13:25:40 +01:00
Joachim Wiberg e44dfde54e plugins: tty: validate against read() length, not buffer size
Fix ev->len validation; must check against sz read(), not total buffer
size.  Also, fix off-by-one in comparison.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 12:55:12 +01:00
Joachim Wiberg 35b200d3a9 Validate inotify event against read() length, not buffer size
Fix ev->len validation; must check against sz read(), not total buffer
size.  Also, fix off-by-one in comparison.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 12:55:12 +01:00
Joachim Wiberg 5badf4d376 plugins: pidfile: validate against read() length, not buffer size
Fix ev->len validation; must check against sz read(), not total buffer
size.  Also, fix off-by-one in comparison.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 12:48:42 +01:00
Joachim Wiberg 24f274c126 plugins: netlink: validate interface name
Check for spaces and slashes in interface name to prevent path based
attacks.  Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 12:23:24 +01:00
Joachim Wiberg 1abd43384b plugins: netlink: minor refactor, collapse for-loop
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 12:20:59 +01:00
Joachim Wiberg 70a1acc210 Highly unlikekly, but chdir() needs to be checked
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 11:40:25 +01:00
Joachim Wiberg 6af0446490 plugins: netlink: fix untrusted loop bound, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 11:28:39 +01:00
Joachim Wiberg ecaf111a4b plugins: tty: possible out-of-bounds read in inotify_event parser
This is a major refactor to use the same construct as in the pidfile.so
plugin to parse kernel inotify events for when TTYs are added removed
from the system.

Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 10:58:55 +01:00
Joachim Wiberg 32ec25b070 Check return value from remove(), found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 10:34:23 +01:00
Joachim Wiberg 305ad302f2 Refactor, reduce code duplication
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 10:28:54 +01:00
Joachim Wiberg d6390244ad Fix possible out-of-bounds read in inotify_event parser
Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 09:57:07 +01:00
Joachim Wiberg 790a316607 Log rotate: improved handling of return values from syscalls
- Align the two implementations in logit.c and utmp-api.c
 - Use libite APIs to handle common constructs
 - If gzip fails, don't remove rotated-to file
 - Don't try gzip if rename fails
 - Issues found by Coverity Scan

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 09:57:07 +01:00
Joachim Wiberg 77aa941e84 Mounting devtmpfs may fail if already mounted
Ignore EBUSY errors, the kernel has the ability to automount /dev as
soon as the rootfs has been mounted.  This may be added to procfs and
sysfs later, so we make this a general change in fs_init().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-07 09:48:02 +01:00
Joachim Wiberg e0a65f67c9 Minor, staticify, reduce includes and allow debug to kmsg
The loglevel setting should control all logging, regardless of
where we target it.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-06 23:55:54 +01:00
Joachim Wiberg 3ed291789c Fix GCC warnings with _FORTIFY_SOURCE=2
- Decleare some return values with (void)fn(), for cases where
  we don't care (dropping table headers), or best effor
- Check return value from fgets() and chdir() in some cases that
  are valid, i.e., continuing execution is pointless

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 12:36:48 +01:00
Joachim Wiberg 774a24cdd8 Allow building with -D_FORTIFY_SOURCE[=1,2]
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 11:17:59 +01:00
Joachim Wiberg 6011f91f22 Fix possible out-of-bounds read in inotify_event parser
Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 11:16:37 +01:00
Joachim Wiberg 07a364e570 initctl: fix use of possibly unterminated string, found by Coverity
No point in using rq.data, which could have been modified, instead use
the input argument to the function in the error message.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:51:25 +01:00
Joachim Wiberg 5b9d99011b Fix long-standing bug in reset of rlimits between reconf
While skimming through the results of the latest Coverity Scan, I
discovered that that the reset logic of global rlimits was broken.
This it seems to have been since its first introduction in Finit.

We fix this by reading initial rlimits at bootstrap, then for each
reconf, including the first, we seed global rlimits with the initial
ones -- thus resetting between each reconf.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:44:01 +01:00
Joachim Wiberg f4f773b4c7 Initialize fallback svc_t in client comms, found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:35:12 +01:00
Joachim Wiberg 9d949c4186 Fix possible NULL ptr deref in cmdline option parser
Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:21:58 +01:00
Joachim Wiberg 1434561a46 initctl: fix cut-and-paste error in new 'show' command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:17:52 +01:00
Joachim Wiberg cf3d3f6f8e Properly check return value from mount(2) and display error message
Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:15:46 +01:00
Joachim Wiberg 621da582c2 Fix obvious bug in ismnt() found by Coverity Scan
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 10:10:45 +01:00
Joachim Wiberg 9167d9255d Work around weird finding from Coverity Scan
The utmp_set() function allows id==NULL, so default the line to NULL and
avoid parsing empty lines.  Which is better code anyway.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 09:59:58 +01:00
Joachim Wiberg c71bafd495 Travis-CI: disable clang and unit tests for Coverity Scan run
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 08:25:32 +01:00
Joachim Wiberg b3b7a33252 initctl: developer mode, hidden command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 08:22:38 +01:00
Joachim Wiberg d1efc60c84 initctl: add show command to cat foo.conf, default finit.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 08:06:01 +01:00
Joachim Wiberg 9a24dfd98d initctl: refactor command composition for status command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 00:13:01 +01:00
Joachim Wiberg 0e3fe5e3bf initctl: fix too long args list to status command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-05 00:06:36 +01:00
Joachim Wiberg 224f42c344 cgreaper.sh: drop log message when cleaning up
Mostly used during development, doesn't really provide any value to the
user at normal runtime.  Leave it commented out though so user can do
debug themselves if needed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:57:48 +01:00
Joachim Wiberg e60eb94810 initctl: complete rewrite of cgroup dumper in 'ps' command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:49:42 +01:00
Joachim Wiberg 464bc831a5 Minor refactor, create FINIT_CGPATH in finit.h to reduce duplicaiton
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:48:57 +01:00
Joachim Wiberg e84911fe52 cgroup: create 'name' or 'name:id' entries, not 'name:'
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:46:25 +01:00
Joachim Wiberg 4bcfd606b4 Refactor screen_init(), use methods developed in pimd project
- Refactor screen_init()
  - use native impl. of TTY probing from pimd project
    - check if TIOCWINSZ works
    - check if we're running in watch(1), for initctl
  - check if ANSI goto(999,999) escape seq. works (invasive)
  - fallback to 80x24
- Drop screen_exit()
- Rename screen_init() to get_width(), for now, matching pimd
- Relocate call in main() to banner(), first fn to write to TTY

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 23:23:31 +01:00
Joachim Wiberg fe27ed17eb initctl: status command formatting updates, add origin .conf file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 07:27:06 +01:00
Joachim Wiberg b3ea23ed26 initctl: drop old 'job:id' format support, canonical is 'name:id'
With the recent changes to the condition handling it has become more and
more evident that the canonical reference for a task/run/service is the
NAME:ID representation.  Up until now we've kept the older JOB:ID for
some sort of compatibility fallback.

This patch removes the support to simplify maintenance going forward.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-04 07:23:19 +01:00
Joachim Wiberg 439699ef52 configure: improve --with-sysconfig help text slightly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-03 07:06:17 +01:00
Joachim Wiberg f20936dae0 configure: slight reorder; first enable -> then disable options
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-03 07:05:55 +01:00
Joachim Wiberg d5bea7eeeb Re-concatenate string arguments to commands, ugly patch
This is quite possibly the ugliest pieces of code in this project.

It is a quick fix to the problem with strtok() to split up the cmd into
cmd + args[].  Without it wordexp() will later get very cranky about
trying to expand `"Partial` strings from commands like this:

    /sbin/udhcpc-wrapper.sh -f -S -V "myOS v9.99" -t 8 -T 5 -A 10 -R -p \
        /var/run/udhcpc-vlan1.pid -i vlan1 -x hostname:myos-12-34-50 -o \
	-O 1 -O 3 -O 6 -O 7 -O 12 -O 15 -O 42 -O 121 -a

Yes really.

It's an obviously far from perfect solution.  One might even start to
question why we have an args[64[64] per svc_t and not just a cmd + arg?

Well, there's a lot of improvement potential here, let's talk!

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 22:33:41 +01:00
Joachim Wiberg 5da0a460fe initctl: fix runlevel and start/stop/restart segfault regression
Introduced in e2f6ac0.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:31:34 +01:00
Joachim Wiberg 63033d7dcf Drop developer debug message
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:23:43 +01:00
Joachim Wiberg 2857dafaf4 plugins: pidfile: Fall back to /run if _PATH_VARRUN doesn't exist
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-02 20:22:56 +01:00
Joachim Wiberg 8355c37285 initctl: fix edit command fallback handling
If mg doesn't exist, command doesn't evaluate the second argument (vi),
so we need to use `... || command -v vi` instead.  Found during demo,
because why not.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-01 17:36:06 +01:00
Joachim Wiberg dc49b523d1 initctl: fix cond segfault, regression introduced in e2f6ac0
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-03-01 11:13:02 +01:00
Magnus Malm bf863673c8 Update list of contributors
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-03-01 09:26:31 +01:00
Joachim Wiberg ecc8b2dcf9 Bump version for v4.0-rc1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 23:23:55 +01:00
Joachim Wiberg 3b64b155d4 Update build deps, need libite (-lite) at least v2.2.0 for systemf()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 23:17:47 +01:00
Joachim Wiberg 1b05220376 initctl: fix reload segfault regression introduced in e2f6ac0
Found thanks to the new unit test suite \o/

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 22:57:14 +01:00
Joachim Wiberg 7f6ccfabb2 Merge pull request #158 from troglobit/wip-tests
Test framework and a small set of basic tests

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 22:40:55 +01:00
Joachim Wiberg c5083c4bbc Move sync files to temporary storage
We don't want these files to exist while starting up, it wrecks all
sorts of havoc to a system.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 22:31:07 +01:00
Joachim Wiberg 1020695ebd Skip termios setup of TTY in rescue mode
This patch fixes an issue with rescue mode on Alpine Linux where the
rescue shell was never properly started.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 21:27:16 +01:00
Joachim Wiberg 3d50a28fe3 Make sure to _exit() TTY child also on error
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 21:25:54 +01:00
Joachim Wiberg 460add3cae initctl: introduce -f,--force option, for delete command
Never prompt, for scripting.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:20:29 +01:00
Joachim Wiberg 5dcf7be3c9 .gitignore: ignore also aux/ and config.cache
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:14:39 +01:00
Joachim Wiberg 89be90cade initctl: fix compilation warning
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:13:32 +01:00
Joachim Wiberg 93f9856da8 initctl: ignore missing files to delete command, simplify yorn() str
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:12:03 +01:00
Joachim Wiberg e2f6ac0ece initctl: iterate command over all args, e.g. delete foo bar baz
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 12:06:59 +01:00
Joachim Wiberg 84be93e013 build: Put all GNU autotools support files in aux/
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:54:17 +01:00
Joachim Wiberg c5db989bed initctl: skip errors from disable while deleting services
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:51:37 +01:00
Joachim Wiberg 928110b19e Minor whitespace in sample.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:43:16 +01:00
Joachim Wiberg c204724353 Follow-up, fix variable expansion if unset
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:42:48 +01:00
Joachim Wiberg 2ac39e1917 initctl: restore Andreas' clever $(command ...) eval, it works
Turns out that on some systems, that has none of the first two, and
neither of the two environment variables set in ${VISUAL:-${EDITOR}},
they evaluate to 'sh /etc/finit.d/file.conf', which is true, so we
wouldn't even try mg or vi ...

This patch reverts to the spirit of Andreas Egebergs initial commit,
which turns out to be a better solution anyway :)

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:35:22 +01:00
Joachim Wiberg 49582c70c5 initctl: add companion delete command
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 11:15:36 +01:00
Joachim Wiberg 4c2bbf7d93 doc: drop lots of fixed or outdated ideas
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 10:36:32 +01:00
Joachim Wiberg 2bfede2cfe Add /lib/finit/sample.conf for initctl create
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 10:26:39 +01:00
Joachim Wiberg 544180aa0b contrib: update example configs
- check command removed
- disable modules by default (void)
- OpenSSH requires absolute path (void)
- Read keymap from env (alpine)
- minor cleanup/reordering for consistency

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 10:23:15 +01:00
Joachim Wiberg 6862d7cd5f Refactor --with-sysconfig, default to /etc/default and /etc/conf.d
Both Debian and Builroot based systems use /etc/default and
Alpine Linux use /etc/conf.d, so let's just put both in by
default.  If the directories exist we monitor them.

The --with-syconfig configure option is now disabled by default.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:53:48 +01:00
Joachim Wiberg 7e3b18a38d Refactor install/uninstall of rescue.conf
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:34:36 +01:00
Joachim Wiberg 70c884816e doc: update config.md, no more limitations
Also, mark some settings as bootstrap only.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:24:04 +01:00
Joachim Wiberg f8c07e81ff Reclassify module as BOOTSTRAP only, including minor refactor
The module setting is deprecated, other mechanisms exist.  This change
is to ensure we don't try to (re)load any modules at runtime, only at
bootstrap.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 09:24:04 +01:00
Joachim Wiberg 270512bc97 Refactor, collapse parse_conf() and parse_conf_dynamic()
This patch collapses the two similar functions parse_conf() and
parse_conf_dynamic() into a single function.  It also lifts old
restrictions on what config stanzas are allowed in /etc/finit.d

The only remaining restriction is the global rlimits, they remain
as the last setting only possible to define /etc/finit.conf which
then applies to all other services.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 08:38:41 +01:00
Joachim Wiberg c001349dd3 Wrapper for init q and init -t sec 0, used by sysvnit shutdown
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-28 07:54:16 +01:00
Jacques de Laval 8a063e665d Update list of contributors
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 23:36:23 +01:00
Jacques de Laval 9b3aca9846 Merge branch 'master' into wip-tests 2021-02-27 23:24:34 +01:00
Jacques de Laval e06e4175d3 test: Add license and copyright to test framework
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 23:23:03 +01:00
Joachim Wiberg 510bd1ac0b initctl: if edit cannot find the file, list available ones
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 20:13:57 +01:00
Joachim Wiberg 0d52583624 initctl: return correct path if -c is given
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 20:13:32 +01:00
Joachim Wiberg aa998583a7 Update example ASCII graphic a bit, add log and env commands
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:29:38 +01:00
Joachim Wiberg f9532d11ba initctl: only show enable/disable commands on compat systems
The enable/disable commands require either both the available/ and
enabled/ subdirectories in /etc/finit.d, or at least available/

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:27:58 +01:00
Joachim Wiberg c7d189f199 initctl: refactor list command slightly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:27:22 +01:00
Joachim Wiberg 83cdb884d9 initctl: extend semantics for enable/disable cmd
A system may, or may not, have the available/ and enabled/
subdirectories in /etc/finit.d.  This is up to distros but
we support the following, example uses /etc/finit.d as the
FINIT_RCSD base directory:

 1. No subdirectories
    - enable: nop
    - disable: nop
 2. Only available/
    - enable: checks if there's a service in available/
      then symlinks to /etc/finit.d/
    - disable: checks if service in /etc/finit.d is a
      symlink, then removes it
 3. Both available/ and enabled/
    - enable: relative symlink in enabled/ is created if
      service is available in available/
    - disable: symlink in enabled/ is removed if exists

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:22:50 +01:00
Joachim Wiberg e9ed90cb34 initctl: let touch command handle both rcsd and available dirs
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:22:16 +01:00
Joachim Wiberg 689e6cd52a initctl: add -c create flag, to force creation at edit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 19:21:18 +01:00
Jacques de Laval 0cb99d5c00 Merge branch 'master' into wip-tests
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 18:40:25 +01:00
Jacques de Laval aa096cde19 test: Only copy /tmp contents if there are any
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 18:27:26 +01:00
Jacques de Laval 7c45fd451e test: Remove some redundant exports
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 18:27:02 +01:00
Jacques de Laval acf886f483 test: Document how to run the test suite
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 18:03:00 +01:00
Joachim Wiberg 2fd4418371 initctl: add support for reading config to 'create' from stdin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-27 17:02:37 +01:00
Jacques de Laval 7fe1189f7b test: Move test support files to separate dir and keep tests in /test
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 14:50:49 +01:00
Jacques de Laval 4aa17a84ab test: Minor clean up
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 13:53:55 +01:00
Jacques de Laval 255d90cee9 test: Mount /tmp as tmpfs again, but copy any existing files in /tmp back into it
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-27 13:45:05 +01:00
Jacques de Laval 8b680b1b14 test: ci: Add debug output for debugging Travis
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 16:55:20 +01:00
Joachim Wiberg 01cd9ec358 contrib: debian: rsyslogd provides syslogd cond
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 16:42:43 +01:00
Jacques de Laval f291c7ac9e test: ci: Fix syntax error in CI manifest
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 16:33:40 +01:00
Jacques de Laval 061de4ddf3 test: ci: Avoid shadowing failure with printing of test log
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 16:31:25 +01:00
Joachim Wiberg 6d4bc670e6 Relocate paste() from helpers.h to util.h, for sharing with initctl
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 16:21:53 +01:00
Jacques de Laval d258dcecd2 test: ci: Print test log if tests fail
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 16:19:03 +01:00
Jacques de Laval 2e0c658160 test: Utilize distcheck in CI; it tests pretty much everything we want to test
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 15:59:55 +01:00
Jacques de Laval 2f439194e5 test: Fix testenv-root lingering in build dir
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 15:35:07 +01:00
Joachim Wiberg 5e37f94775 Improve error messages for failing wordexp()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 15:06:02 +01:00
Joachim Wiberg 41319a8cf8 Work around forbidden chars in wordexp(): | < > & ;
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 14:54:34 +01:00
Joachim Wiberg 001e859a97 initctl: add create command, no template yet
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 12:47:47 +01:00
Joachim Wiberg 6cf8c7ade4 initctl: minor refactor, simplify edit command
- Gamble a bit by redirecting stderr to /dev/null instead of command -v
- Drop vi from VISUAL/EDITOR expansion alternatives, tested later anyway

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 11:45:04 +01:00
Jacques de Laval 6b7ae50fbb test: Let Make generate shellcheck test from the list of test sources
Not very readable yet, so it needs clean up!

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-26 11:24:12 +01:00
Joachim Wiberg 7439fa0c2a initctl: fix logic in edit command fallback handling
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 11:08:03 +01:00
Joachim Wiberg 6b1ba37438 doc: bump required versions of libuEv and libite
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:57:30 +01:00
Joachim Wiberg a579e0e8ae travis-ci: bump libuEv and libite versions, for systemf()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:57:30 +01:00
Joachim Wiberg 8077169ea9 Merge pull request #157 from troglobit/usr/kandeg/initctl-edit
initctl: add edit command, fix #154 

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:54:00 +01:00
Andreas Egeberg bf2272c6b3 Beautify code 2021-02-26 10:51:30 +01:00
Joachim Wiberg 4e035f77f6 Fix regression introduced in 7ef25ab, global rlimits not initialized
Services that are instantiated by plugins, and thus don't have a .conf
file, tried to use uninitialized rlimits.  This caused the kernel to
immediately kill those services for violating their own rlimits.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg 9df5e7664d flog: new helper function for debugging to file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg 41092095f5 configure: allow custom directory for --with-sysconfig
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg a758d3dddc contrib: alpine: update to use env: files for service arguments
- Check for env in /etc/conf.d on Alpine
- Update all services with their respective env: file
- Disable default modules, noew modprobe plugin should handle this
- Add watchdog service
- Rename syslogd -> syslog, in case we want to integrate sysklogd

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg e228174eb5 contrib: debian: update to use env: files for service arguments
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg a1f79e263a Refactor, add new helper fn paste() to concat directory compoents
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg 6f06c432ec Minor, insert '/' only if pasting components require it
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:54 +01:00
Joachim Wiberg 3ae609c341 configure: minor refactor, simplify to reduce duplication
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:32:41 +01:00
Andreas Egeberg 60d0ca1075 Added Edit command
Command Edit <CONF>  opens file /etc/finit.d/available/<CONF>.conf in
the editor referenced by Linux environment variable $EDITOR
If $EDITOR is not set it will try to open emacs and if emacs is not
found it will try to open the file in vim.

Signed-off-by: Andreas Egeberg <andreas.egeberg@gmail.com>
2021-02-26 10:28:21 +01:00
Joachim Wiberg 435211765c Follow-up to f4a0b99: track modifications of service env: files
Add support for monitoring environment files for services declared with
the `env:[-]/path/to/file` option.  The default path to such files has
been chosen to follow Debian and Buildroot /etc/default/*

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:23:24 +01:00
Joachim Wiberg 92c6de2c09 test: tests use .sh extension, for .log/.trs transformation
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 10:13:44 +01:00
Joachim Wiberg e3b27d47bc Follow-up to dfd41a1: fix default finit.conf path regression
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:52:42 +01:00
Joachim Wiberg 6b7255fdeb Fix regression introduced in 7ef25ab, global rlimits not initialized
Services that are instantiated by plugins, and thus don't have a .conf
file, tried to use uninitialized rlimits.  This caused the kernel to
immediately kill those services for violating their own rlimits.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:11:56 +01:00
Joachim Wiberg 80e4f025d3 flog: new helper function for debugging to file
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-26 09:09:34 +01:00
Joachim Wiberg 45a374b50a configure: allow custom directory for --with-sysconfig
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 18:28:11 +01:00
Joachim Wiberg ea9f88b9fb contrib: alpine: update to use env: files for service arguments
- Check for env in /etc/conf.d on Alpine
- Update all services with their respective env: file
- Disable default modules, noew modprobe plugin should handle this
- Add watchdog service
- Rename syslogd -> syslog, in case we want to integrate sysklogd

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 18:16:53 +01:00
Joachim Wiberg da2dde879e contrib: debian: update to use env: files for service arguments
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 18:16:53 +01:00
Joachim Wiberg 064d124e19 Refactor, add new helper fn paste() to concat directory compoents
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:41:39 +01:00
Jacques de Laval 0e0b2773eb Merge branch 'master' into wip-tests 2021-02-25 17:40:23 +01:00
Jacques de Laval ea4fe2045d test: Add sane default for TESTENV_ROOT; enable easier independent test runs
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-25 17:38:56 +01:00
Jacques de Laval 48b732e53d test: Let Autoconf generate env vars for tests
This simplifies the setup script a lot, and also makes it easier to
run tests independently.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-25 17:37:24 +01:00
Joachim Wiberg f8a989439b Minor, insert '/' only if pasting components require it
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:18:44 +01:00
Joachim Wiberg dfd41a1b37 configure: minor refactor, simplify to reduce duplication
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:17:30 +01:00
Joachim Wiberg 74d3194775 Follow-up to f4a0b99: track modifications of service env: files
Add support for monitoring environment files for services declared with
the `env:[-]/path/to/file` option.  The default path to such files has
been chosen to follow Debian and Buildroot /etc/default/*

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 17:14:26 +01:00
Joachim Wiberg 7ef25abecf Refactor, use new iwatch module for inotify of Finit *.conf files
- Use iwatch, modeled after pidfile plugin
- Use one .conf watcher for all *.conf paths/files
- Use full path of conf file for changes, from realpath().
  This fixes a long-standing limitation on unique filenames
  for services, that absolutely nobody knew about

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:28:03 +01:00
Joachim Wiberg ea278a6370 plugins: pidfile: simplify, use constructs from src/conf.c
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:27:28 +01:00
Joachim Wiberg 8790fcabf3 iwatch: minor, check if file/dir exists before trying to add
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:27:01 +01:00
Joachim Wiberg 3d9ee49759 Follow-up to 6cdcacf, fix minor regression, premature clear of pid
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 14:23:45 +01:00
Jacques de Laval cde580ffce test: Unify setup-root.sh for make check and make distcheck
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-25 11:18:12 +01:00
Jacques de Laval 3c32cbfd9e test: Make /var/lock readable in test teardown, so that it can be removed later
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-25 11:14:49 +01:00
Jacques de Laval 691bc58f0e test: Add support for starting Finit in debug mode
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-25 00:53:30 +01:00
Joachim Wiberg cafbb18626 plugins: hotplug: log output from udevd/systemd-udevd to syslog
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 00:27:29 +01:00
Joachim Wiberg 939c6f2f67 Fix regression in displaying progress at runtime
We don't want to show progress (starting/stopping/restaring) at
runtime, since Finit v3.  Many systems hooked up to a console
get confused by sudden output, or even ansi escape sequences.

This patch drops code added recently which caused a regression
in this policy.  The resulting code is even more readable.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-25 00:22:01 +01:00
Joachim Wiberg 477b50b7a6 Check return value from kill(pid, SIGHUP), maybe lost pid
This patch handles a corner case when Finit may not have detected a
supervised process has died.  When a user calls `initctl restart foo`
we now send such lost PIDs to the service_monitor() for restart.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 23:58:25 +01:00
Joachim Wiberg 6cdcacf20b Refactor, shared cleanup fn for service_kill() and service_monitor()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 23:45:14 +01:00
Joachim Wiberg d37c20f467 Terminate children in the same process group when monitored PID dies
Really kill them, our monitored process may be about to restart, so we
don't want any unintended side effects from lingering children in prior
instances.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 23:43:03 +01:00
Jacques de Laval 70964ccb35 test: Only mess with PATH inside test environment 2021-02-24 23:28:47 +01:00
Joachim Wiberg 3ebac3dece Merge branch 'master' into wip-tests 2021-02-24 22:53:08 +01:00
Joachim Wiberg 14f0443bd7 Allow services to be added *and removed* from /etc/finit.conf
This patch fixes a long standing issue where removing a service from
/etc/finit.conf does not stop and unregister it.  The issue was caused
by the Finit support for "protected" services, e.g. services created
by plugins like hotplug.so

To reproduce issue before this fix:

    cat /etc/finit.d/available/ntpd.conf >> /etc/finit.conf
    initctl reload

The NTP service now runs smoothly, as expected.  Later on, we decide to
drop it from our system:

    sed -i 1,2d /etc/finit.conf
    initctl reload

... and the NTP service continues to run unaffected.  Not what most sane
users expect.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Joachim Wiberg 81d8f3cccc Drop unnecessary service_step() in cond_reload()
The cond_reload() fn is called on `initctl reload`, thus we don't need
to call service_step(), since we call service_step_all() later in that
cycle.  So we can drop cond_update(NULL), which calls service_step().

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Joachim Wiberg d27b3948af Drop unnecessary and confusing debug message in mkcond()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Joachim Wiberg f906bb357a plugins: pidfile: only scan directory if watch added successfully
Also, update condition example in comment.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Joachim Wiberg e0d3aa8e06 iwatch: handle watching paths for same inode
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 22:12:05 +01:00
Jacques de Laval 91ffda154d Merge branch 'master' into wip-tests 2021-02-24 22:03:20 +01:00
Joachim Wiberg 84248e1c56 Merge pull request #156 from troglobit/fix-hard-coded-rcsd
Use FINIT_RCSD instead of hard coded value
2021-02-24 21:09:12 +01:00
Jacques de Laval 51fe974ee5 Use FINIT_RCSD instead of hard coded value
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-24 18:58:05 +01:00
Jacques de Laval 1efdbeda16 Merge branch 'wip-tests' into wip-tests-build-refactor
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-24 18:48:26 +01:00
Jacques de Laval 827f826201 test: Remove commented code
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-24 16:34:00 +01:00
Jacques de Laval a5ef5f3104 test: Fix make check
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-24 16:01:43 +01:00
Magnus Malm 76b2a846a2 test: Slightly improve names of test directories
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-24 14:54:45 +01:00
Magnus Malm e77f3f4d74 test: Use initctl in favor of kill -SIGHUP when reloading finit
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-24 14:31:18 +01:00
Magnus Malm 2c055cb954 test: Minor adjustments to improve consistency between test code structure
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-24 13:20:13 +01:00
Magnus Malm f214098560 test: Minor refactor to reduce test code duplication
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-24 13:13:38 +01:00
Magnus Malm 6027e94c65 Merge remote-tracking branch 'upstream/master' into wip-tests 2021-02-24 10:22:57 +01:00
Joachim Wiberg bc4d4b7f35 plugins: pidfile: set up I/O callback on successful iwatch_init()
In case of trouble, make sure we don't have a callback set up w/o
a valid file descriptor.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 09:52:34 +01:00
Joachim Wiberg e067f23ef2 iwatch: add license+copyright header and initialized guard
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-24 09:49:39 +01:00
Jacques de Laval 05901a90aa test: Fix distcheck
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-23 23:20:39 +01:00
Joachim Wiberg dd6ebc3b65 Drop svc pidfile matching, only match against PID in pidfile
With the redesign from <svc/path/to/pidfile> to <pid/name:id> in d1fac6f
we moved to matching svc_t only against their PID, which could pop up in
any *.pid or */pid in /var/run.  This patch drops the (hopefully) last
remnants of the old <svc/> legacy.

To ensure we don't try reading the PID value from socket files, like
/var/run/initctl, we add simple fnmatch() of the inotified file.  Two
calls to fnmatch(), for portability reasons, not every system has GNU
libc extensions like FNM_EXTMATCH.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-23 20:26:57 +01:00
Joachim Wiberg 8dc1ad00d5 plugins: refactor, break out inotify watcher to src/iwatch.[ch]
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-23 20:26:38 +01:00
Joachim Wiberg f72e0a646e test: fix make warning 'etc' given more than once
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-23 15:45:50 +01:00
Joachim Wiberg 47dcd1cb8a test: silence make in-out directory
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-23 15:45:21 +01:00
Magnus Malm 25ffc3192f test: Add two new tests
* test_start_stop_service

  Test that we can start/stop (via initctl) a service configured in
  finit.conf

* test_start_stop_service_sub_config

  Test that we can start/stop (via initctl) a service configured in
  finit.d/ files

Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 15:30:42 +01:00
Magnus Malm 51fe6a15e9 test: Improve add/remove sub config test
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 15:27:33 +01:00
Joachim Wiberg 8381976f05 plugins: boilerplate for made-easy integration with FRR
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-23 15:03:03 +01:00
Magnus Malm 6bcb9e9030 test: Populate/cleanup /etc "manually" via Makefile/tests
For now, do not mount /etc as tmpfs, but instead create the dir when
building the rootfs via test/test_root/Makefile.

Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:24:54 +01:00
Magnus Malm b364fd7d6a test: Add test for dynamically add/remove service in finit.d/ files
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:24:54 +01:00
Magnus Malm 27ad3b5a7f test: Minor cleanup in lib.sh
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm eda9ae4c3e test: Rename start/stop service test to add/remove dynamic service
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm bb095bfd5d test: Minor tweak on test's output
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm 8a2cc2aeb8 test: Move service.sh to test/common/
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm 6d9374590f test: Add test start timestamp
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm 3ec788a6cf test: Minor tweaks of how/when to print testenv stuff
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm 5e20abef8d test: Print running test name with log()
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Magnus Malm 3d01728d2e test: Add testenv_enter.sh to ease debugging testenv
The script testenv_enter.sh, by default, runs /bin/sh in the environment
currently setup.

A bit easier than copy pasting the old hint text printed before test run.

Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 11:19:57 +01:00
Joachim Wiberg c0bbb0fc51 plugins: pidfile: rename variables and local fns
- new namespace before breaking out to shared object
- use inotify naming fd -> wd

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-23 09:04:53 +01:00
Magnus Malm 4480010d4a test: Add support for teardown in tests
If a test defines a function 'test_teardown(), that function will be
called before the test env teardown is run.

Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-23 08:55:11 +01:00
Jacques de Laval 70773105ac test: Tell Finit to shut down rather than reboot in teardown
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-23 01:09:46 +01:00
Jacques de Laval 17d0835d63 test: Only echo last output of command in retry
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-23 00:32:36 +01:00
Jacques de Laval cda90fe5ee Merge branch 'master' into wip-tests 2021-02-22 23:54:18 +01:00
Jacques de Laval 07521e043a test: Add standard dir for test assets
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 22:30:10 +01:00
Jacques de Laval 2c56e20941 test: Name test-lib appropriately
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 22:12:34 +01:00
Jacques de Laval 11841ceb5d test: Clean up Automake integration of tests
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 22:07:17 +01:00
Jacques de Laval e44d348f09 test: Add test suite to Automake
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 20:33:30 +01:00
Jacques de Laval ee31c8551f test: Remove unnecessary mkdir
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 17:21:55 +01:00
Jacques de Laval c2bb46f18c test: Run shellcheck on test scripts before running them
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 17:16:32 +01:00
Jacques de Laval df66d1efd8 Merge branch 'wip-tests' of github.com:troglobit/finit into wip-tests 2021-02-22 16:51:31 +01:00
Jacques de Laval 6f8c24a8d3 test: Only grep for specific child
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 16:48:53 +01:00
Magnus Malm cd2fcac4cf test: Handle finit's default conf dirs/files better in test env
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-22 16:46:25 +01:00
Magnus Malm adc9c40fe1 test: Include initctl in test run env
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-22 16:45:39 +01:00
Jacques de Laval 914955341d test: Remove debug print
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 16:39:06 +01:00
Jacques de Laval 0ef17f55ff test: Retry asserting number of Finit children for a while
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 16:32:49 +01:00
Joachim Wiberg f4a0b99df8 Fix #155: add support for env:/a/bc to service/run/task
This patch makes it possible to create a service with optional
arguments, similar to the systemd EnvironmentFile= setting.

The major difference to systemd, is that Finit does not attempt
to start a service if it cannot find the env. file, unless it
is prefixed with '-'.

Example:

    /etc/default/syslogd:
    SYSLOGD_OPTS="-m0 -r 128k:10 -s"

    /etc/finit.d/enabled/syslogd.conf
    service env:-/etc/default/syslogd syslogd -F $SYSLOGD_OPTS

Only downside, right now, is that changing the contents of the file
/etc/default/syslogd does not mark the syslogd.conf as modified and
a subsequent `initctl reload` will *not* restart syslogd.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-22 16:18:22 +01:00
Magnus Malm 644273fc5c test: Add 2 convenience shell functions for test development
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-22 15:47:59 +01:00
Jacques de Laval a28bb6f951 test: Create FINIT_CONF dir before writing to the file
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 15:23:06 +01:00
Jacques de Laval 9d3d211b6b test: Fix waiting for Finit PID
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 15:22:32 +01:00
Jacques de Laval 8f55bf140e test: Add xtrace flag for debugging
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 14:52:01 +01:00
Jacques de Laval b73998d7c6 test: Reset PS env vars in test environment
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 14:35:12 +01:00
Jacques de Laval 407c524088 test: Use FINIT_CONF from autoconf instead of hardcoded /etc/finit.conf
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-22 14:34:22 +01:00
Joachim Wiberg fc82f0242c doc: another reformat of cmdline tips
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 22:57:21 +01:00
Joachim Wiberg 8c7a3bc476 contrib: add sysklogd to available services on debian
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 17:12:10 +01:00
Jacques de Laval 765e1eb640 Merge branch 'master' into wip-tests 2021-02-21 12:52:30 +01:00
Jacques de Laval a8f562a7f5 test: Minor clean up
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-21 12:51:49 +01:00
Joachim Wiberg 7e42203627 Fix #147: refactor reboot as multi-call to initctl
This patch drops the stand-alone reboot binary and folds it into the
initctl tool, which now becomes a multi-call binary.

With this change the reboot/shutdown/poweroff/halt/suspend commands also
no longer default to sending signals to PID 1, instead it now uses the
initctl <--> finit UNIX domain socket API.  Signals are only used as a
fallback in case of non-working domain socket.  The -f,--force mode of
operation still works, where `reboot(2)` is called directly.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 10:59:08 +01:00
Joachim Wiberg 649a269526 Add reboot/halt/poweroff/suspend commands to Finit API
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 10:49:13 +01:00
Joachim Wiberg e80edbb401 If Finit API call fails (NACK), return non-zero to client
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 10:47:48 +01:00
Joachim Wiberg 1cb37a3ee7 plugins: update conditions for udevd and udevadm commands
On systems with udevd, or systemd-udevd, we must wait for udevd to start
before calling udevadm.  This patch updates service and runtask stanzas
to the new condition system naming and adds 'log' to the udevadm cmds.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 01:12:26 +01:00
Joachim Wiberg 27a4c8cd9a Follow-up to 70ca64a, handle missing bool argument to cmdnline opts
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 01:06:02 +01:00
Joachim Wiberg 97a0baaf93 Fix regression introduced in 13893b9
The refactor in 13893b9 caused a regression in composing service
arguments.  This patch should rectify that.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 00:57:21 +01:00
Joachim Wiberg 7b561044a9 doc: slight refactor of signals document 2021-02-21 00:57:12 +01:00
Joachim Wiberg 346320f669 doc: update text on conditions to reflect new world 2021-02-21 00:57:12 +01:00
Joachim Wiberg e941a510c1 doc: document new cmdline options
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-21 00:57:03 +01:00
Jacques de Laval 835f6a45d3 test: Re-enable teardown
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 14:30:12 +01:00
Jacques de Laval ee71378dfd test: Fix hardcoded Finit TTY pipe
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 14:20:09 +01:00
Jacques de Laval 0161958603 test: Avoid shadwoing /tmp/lib in Travis CI
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 14:08:37 +01:00
Jacques de Laval dd6af87d6e test: Print Environment and FS for debugging 2021-02-20 13:49:12 +01:00
Jacques de Laval 7965dbd13f test: Fix chroot not in PATH
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 13:06:28 +01:00
Jacques de Laval 99ad26236e test: Fix unshare/nsenter not in PATH
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 12:39:29 +01:00
Jacques de Laval ba621502ae .travis.yml: Print unshare/nsenter/chroot version for debugging
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 11:53:20 +01:00
Jacques de Laval 061702b6e4 .travis.yml: Run check after build
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 11:09:22 +01:00
Jacques de Laval e72fd5a271 test: Fix and clean up dynamic library setup
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-20 11:05:41 +01:00
Jacques de Laval c80a755dc6 test: Clean up Makefile
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-18 22:49:01 +01:00
Jacques de Laval 5a4cb74493 test: Fix shellcheck warnings
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-18 21:29:51 +01:00
Jacques de Laval 5775a20eff test: Copy dynamic libraries into chroot
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-18 20:54:35 +01:00
Jacques de Laval cdd504622d test: Print test status after each test
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-18 15:05:45 +01:00
Jacques de Laval 39edf52792 test: Add shellcheck
Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-18 14:39:55 +01:00
Jacques de Laval 4224c2e8fe test: New test: test_start_stop_service
Add a new test that verifies that Finit will:
- Start a service that's been added to the config
- Stop the service once it's removed from the config

The second step is currently failing.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-18 13:55:47 +01:00
Jacques de Laval 4f82cb8261 WIP: test makefile 2021-02-18 00:47:55 +01:00
Jacques de Laval aa9a5fbb99 WIP: Unshare/Chroot test wrapper script 2021-02-17 16:20:17 +01:00
Joachim Wiberg dda59503ac Refactor, drop #ifdefs and logger fallback, probe for logit
Simplify log redirection, probe for logit early and fall back to
use a while-loop of syslog() instead.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 13:00:58 +01:00
Joachim Wiberg 549aeda1fd Set process name of finit fallback shell, when active
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 13:00:22 +01:00
Joachim Wiberg 5903ebeb62 cgreaper.sh: update path to logit after relocation
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 13:00:22 +01:00
Magnus Malm 4d4fd40286 Follow-up to 72a892e, Add missing '/'
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-17 11:46:39 +01:00
Joachim Wiberg 27aa7ad1e1 Follow-up to 72a892e, fix string concatenation
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:41:49 +01:00
Magnus Malm 72a892ef55 Fix #151: Install logit in libexec
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-17 11:33:48 +01:00
Joachim Wiberg 4ff6f6a1f1 doc: minor, pid condition syntax has changed
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:32:47 +01:00
Joachim Wiberg 07da8aecac doc: some helpful pointers
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:32:13 +01:00
Joachim Wiberg 352ffb1582 doc: Major refactor, change layout
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:26:49 +01:00
Joachim Wiberg ad08f30b31 doc: Simplify and update with new cond format
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:06:46 +01:00
Joachim Wiberg 13893b9f32 Refactor, simplify command + args composition for readability
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:06:46 +01:00
Joachim Wiberg e5a53c175a initctl: fix too long cmd arglist with 'initctl -v show'
Only append args that have length, MAX number of args are many.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-17 11:06:46 +01:00
Joachim Wiberg 224fbedbf4 Merge pull request #153 from troglobit/logit-post-signal
Logit post SIGTERM, SIGINT etc.
2021-02-17 10:56:20 +01:00
Magnus Malm 97196d6520 contrib: alpine: Add finit builtin watchdog daemon
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-17 10:34:10 +01:00
Jacques de Laval 06aea7d3f3 Keep logit alive until stdin is closed
By not putting logit in the same process group as the service whose
output is consumed by logit, we can send signals to the service,
and it's group, without affecting logit. This means that logit will
continue to log away until it's stdin is closed, which will happen
when the service is reaped.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-17 00:00:50 +01:00
Jacques de Laval 703ae0caf3 Avoid lingering stdout fd logit process
Delay duplication of stdout/stderr until after forking a logit
process, otherwise we'd have a ligering reference to stdout/stderr.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-17 00:00:37 +01:00
Magnus Malm 20c5788430 contrib: debian: Change sshd config to use absolute path
Signed-off-by: Magnus Malm <magnusmalm@gmail.com>
2021-02-15 13:53:22 +01:00
Joachim Wiberg d449329d3d Merge pull request #152 from troglobit/fix#139-set-system-timezone
Fix #139: System timezone changes does not 'take' in Finit
2021-02-15 13:43:16 +01:00
Andreas Egeberg 65f25756bf Fix #139: System timezone changes does not 'take' in Finit
The tzset() function sets the global variables 'daylight', 'timezone' and 'tzname'
according to the value of the TZ environment variable, or to the value of the
_CS_TIMEZONE configuration string if TZ isn't set, or to UTC0 if neither is set.

Signed-off-by: Andreas Egeberg <andreas.egeberg@gmail.com>
2021-02-15 12:38:20 +00:00
Joachim Wiberg 272db0d41d Use fallback to syslog if logit tool is not installed
In the case of redirect to a logfile, if logit tool is not enabled,
then log to syslog instead.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-15 08:00:24 +01:00
Joachim Wiberg 47d89ba2f6 contrib: Drop --enable-progress, enabled by default now
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 20:53:52 +01:00
Joachim Wiberg 6dd65d33ca Fix formatting of banner in classic style progress
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 20:14:18 +01:00
Joachim Wiberg 70ca64a392 New cmdline options to control debug and progress/status
Modeled after systemd.show_status, currently without the 'auto' setting.

- finit.debug[=bool]
- finit.show_status[=bool]
- finit.status_style[=old,classic,new,modern]

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 20:11:45 +01:00
Joachim Wiberg 35e4e0d073 Drop confusing splash cmdline and --enable-progress configure option
This patch reverts back to the progress/status behavior of Finit < v3.0
because this is what most users expect, including the maintainer.  The
resulting code and configure script is a lot simpler to understand and
maintain:

- No more --enable-progress or --enable-progress-classic configure
  flags.  Instead a progress_style variable in helpers.c that can
  be changed at compile time for those that really need it.
- No more 'splash' kernel commnand line option.  This turned out to
  be *very* confusing to many users who believed it was some sort of
  graphical splash screen à la Plymouth.

Also, when Finit debug is enabled we now have a global 'debug' flag
which now alo controls if klogctl() should be called to prevent the
kernel logs to the console or not.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 20:11:08 +01:00
Joachim Wiberg 13a33d345b plugins: bootmisc: add missing include
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 14:18:08 +01:00
Joachim Wiberg e30e6ad6c9 plugins: bootmisc: skip UTMP/WTMP/BTMP on non-utmp systems (musl)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:35:26 +01:00
Joachim Wiberg e9a89248ec Minor refactor
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:31:51 +01:00
Joachim Wiberg 46bb09c331 Fix #145: default to power-off system, fix -h for shutdown command
- Default to power-off the system, even for shutdown command
- Fix -h switch for SysV init shutdown command compatibility
- Add -P switch for systemd shutdown command compatibility

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:20:42 +01:00
Joachim Wiberg 89a57054f5 initctl: drop utmp/wtmp functionality on systems w/o it (musl)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:18:34 +01:00
Joachim Wiberg c1e4c24136 Skip UTMP/WTMP update on systems w/o support for it (musl)
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:17:39 +01:00
Joachim Wiberg d9b705ab98 Runtime detection of working UTMP/WTMP support in system
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 04:17:15 +01:00
Joachim Wiberg 87f6769c51 Revert "Workaround for _PATH_UTMP and _PATH_WTMP defines on musl libc"
This reverts commit 8a71f2d323 because
if no other application has a working utmp then there's no poit for
Finit to have one.  Instead we'll be disabling all utmp support when
running on a musl based system.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 03:59:52 +01:00
Joachim Wiberg 8a71f2d323 Workaround for _PATH_UTMP and _PATH_WTMP defines on musl libc
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-14 03:52:56 +01:00
Joachim Wiberg 5fbcf6814c Warn if a new service asserts the same condition as an existing one
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-13 12:07:20 +01:00
Joachim Wiberg b175b4a2ae initctl: add PID and IDENT to 'cond dump' command
Instead of just walking /run/finit/cond, also show the source of each
condition.  The hook and net conditions are hard-coded to init[1] atm.
and unknown conditions are shown as unknown[0].

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-13 12:07:20 +01:00
Joachim Wiberg 3aeb150eef initctl: minor refactor and set min column width
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-13 12:07:20 +01:00
Joachim Wiberg 260288a184 configure: restore tar.xz dists, be nice to downstream
In the v4 bump we removed tar.xz archives in favor of bringing back
tar.gz.  This was a bit premature and could easily cause unnecessary
headaches downstream.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-13 12:07:20 +01:00
Joachim Wiberg fec8530486 Merge pull request #146 from troglobit/show-runparts-progogress
Fix #127: communicate run-parts progress/status
2021-02-12 17:00:12 +01:00
Jacques de Laval 0557c83d40 Fix #127: communicate run-parts progress/status
Printing the progress of run-parts script just like for `rc.local`
seems reasonable. Also log a warning if any script exits abnormally.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-12 16:33:18 +01:00
Joachim Wiberg fe969b64a0 contrib: alpine: fix symbolic link loop
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-12 00:36:18 +01:00
Joachim Wiberg 27bd9423bc initctl: add job number to "show foo"
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:32:37 +01:00
Joachim Wiberg 72a0ba6a55 initctl: primarily check for /var/log/syslog, fallback to messages
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:32:12 +01:00
Joachim Wiberg 56eb2c6b21 initctl: slight adjustment to whitespace between columns
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:31:35 +01:00
Joachim Wiberg 02d7c6747b initctl: minor refactor, keep related functions together
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 22:17:54 +01:00
Joachim Wiberg cac321c16e Minor, simplify
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 21:50:45 +01:00
Joachim Wiberg 10d4964106 Remove last traces of inetd support
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 21:50:17 +01:00
Joachim Wiberg e843be4540 doc: update section on pidfile.so plugin
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 21:23:09 +01:00
Joachim Wiberg 782da9d091 contrib: alpine: fix reboot/shutdown/halt/suspend symlinks
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 21:05:01 +01:00
Joachim Wiberg a45e2c6831 contrib: alpine: remove all plugins as well on uninstall
Old plugins can cause Finit to misbehave.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 20:56:23 +01:00
Joachim Wiberg 111f5b163a contrib: alpine: first draft uninstall script
Purpose of script is to restore an Alpine Linux install to its default
state.  Some trace elements of Finit may remain, but critical parts like
reverting back to /bin/busybox as /sbin/init are in place at least.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 20:12:04 +01:00
Joachim Wiberg ed0e65e5bb contrib: alpine: enable acpid, crond, ntpd by default
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 20:11:33 +01:00
Joachim Wiberg a43f54f960 Merge pull request #144 from troglobit/drop-old-init-client
Fix #136: drop old init client tool

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 19:10:21 +01:00
Jacques de Laval cb64c068e3 Fix #136: drop old init client tool
The SysV API compatibility layer gives too little value to be worth
the effort of maintaining it. Users are encouraged to use the
`initctl` tool instead.

Signed-off-by: Jacques de Laval <jacques@de-laval.se>
2021-02-11 17:52:08 +01:00
Joachim Wiberg eb6ac5ee22 Fix service state transition regression introduced in e88a9b1
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 17:01:08 +01:00
Joachim Wiberg e8561b7f90 initctl: add '-n, --numeric' mode to prefer JOB:ID over NAME:ID
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 16:16:43 +01:00
Joachim Wiberg 815454c065 initctl: fix missing '--no-heading' longopt in getopt()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 16:16:07 +01:00
Joachim Wiberg d1afc705ab initctl: refactor, reduce code duplication
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 16:14:28 +01:00
Joachim Wiberg ab8e813c7a initctl: name:id also for conditions and adjust column widths
Slight reshuffle of columns so status and condition listings are more
similar.  Also, calculate and adjust necessary column widths.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 15:37:43 +01:00
Joachim Wiberg 99d22a7c21 initctl: add '-t' switch to hide table headings
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 14:11:47 +01:00
Joachim Wiberg a226c93539 initctl: change layout to put (name,id) tuple in focus
With the recent change in the condition handling we've decided to put
the (name,id) tuple in focus for everything Finit.

This patch changes from job:id in the status listing to name:id instead.
In verbose mode we change to show the job:id and the command + args.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 14:07:43 +01:00
Joachim Wiberg e88a9b14ff Fix #101: remove built-in inetd from finit
This patch removes the built-in inetd support from Finit.  We recommend
using an external inetd instead, e.g. xinetd.

If you liked the feature set our inetd provided; filtering per interface
and port redirection, then please let us know or use the code in this
patch (MIT licensed) to recreate it.  We are open to reintroducing it,
but then as a stand-alone daemon like the bundled watchdogd and getty.

So long for now, old friend.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 12:46:40 +01:00
Joachim Wiberg 673a9a55a2 Updates for upcoming v4 release, including planned release date
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 11:12:29 +01:00
Joachim Wiberg d1fac6f5b3 Fix #143: redesign condition subsystem
Change service conditions from the non-obvious <svc/path/to/foo> to
<pid/foo:id>, utilizing the unique name of the service instead of the
weird composition of paths from /run and PID file names.  Hopefully
making it more clear that one service's pidfile is another service's
`<pid/foo>` condition.

Note: this is an incompatible change to the condition system!
      The Finit major version will be stepped to indicate this.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 07:58:06 +01:00
Joachim Wiberg 3e9c170e6b Refactor syslog output from ca210f5 to new canonical format
From, e.g.,

	Starting foo:, PID: 123
to
	Starting foo[123]

or, when an ID has been given

	Starting foo:id[123]

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 07:55:25 +01:00
Joachim Wiberg 59d5601f8f svc_ident(): new function, returns service's unique identifier
A service is identifier using the (name,id) tuple on the form 'name:id'

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-11 07:53:51 +01:00
Joachim Wiberg 46c028f58c contrib: drop local symlinks, created by Makefile on install
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 13:50:52 +01:00
Joachim Wiberg 5105ff91d9 contrib: install .conf files from installed (fixed) services
This fixes the problem with lingering Makefile's in /etc/finit.d/ on the
target systems.  We also get the new enabled services properly set up.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 13:46:32 +01:00
Joachim Wiberg 91750fd1da contrib: use "new" enabled/ directory for pre-enabled services
The initctl tool's enable/disable command can then be used to manage
these services after install.  This is what most users expect.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 13:45:06 +01:00
Joachim Wiberg 4ca5204acb contrib: drop absolute paths => simpler conditions
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 13:26:08 +01:00
Joachim Wiberg 43d73e3c01 plugins: Use len field from inotify_event to calc dest buffer
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 12:14:51 +01:00
Joachim Wiberg f6b6ed211c Fix gcc warning, too small destination buffer may be truncated
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 11:56:34 +01:00
Joachim Wiberg 1fb78742c7 Fix gcc warning, prevlevel may be used uninitialized
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 11:56:16 +01:00
Joachim Wiberg c93e9a30cd Scrap v3.2 release cycle and move to v4.0 directly
Planned changes will directly change the behavior of conditions, and
instead of having to implement compatibility wrappers and further
complicate the code, we've taken the decision to go for v4 directly.
This allows us to also rip out the complex inetd support.

Other changes in this commit:

- Revert back to .tar.gz distribution archives, by popular demand
- Add .sha256 checksum for .tar.gz archive

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-10 11:47:26 +01:00
Joachim Wiberg 4b54ae46ea Update changelog, so many changes and fixes ...
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:31:36 +01:00
Joachim Wiberg e147cf7a8c Relocate IPC socket file from /run/finit.sock -> /run/finit/socket
We have our own subdirectory alread in /run, for conditions, and the FHS
recommends services maintain their own subdirectory if they have >1 file
for runtime storage.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:07:03 +01:00
Joachim Wiberg 36de18ec55 Clarify PID conditions and non-standard PID file locations a bit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:07:03 +01:00
Joachim Wiberg a5714a058c Update copyright years
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:07:03 +01:00
Joachim Wiberg a8b113185d Major change, rename <svc/...> conditions to <pid/...> conditions
The <svc/foo> condition was created to synchronize starting services,
hence the abbreviation.  Example: the Quagga ripd needs to start after
the zebra daemon to ensure its UNIX domain socket is active, otherwise
events may be lost.

However, considering that synchronization was implemented with UNIX PID
files, e.g. waiting for /var/run/quagga/zebra.pid to be created, the
condition abbreviation name <svc/foo> was hard to understand by most
newcomers to Finit.  To make matters worse, a new feature to track or
even create PID files for services that don't create one themselves,
using the syntax 'pid:/path/to/foo.pid' was added.

Connecting the dots between these wasn't obvious.

This patch renames service conditions pid conditions and also adds
a compatibility wrapper to the Finit .conf parser.  Any condition
given in old .conf files with 'svc/' prefix are internally renamed
'pid/', along with a LOG_INFO notice in syslog.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 22:07:03 +01:00
Joachim Wiberg ff41868b59 Reorder, call conf_init() *after* all cond_init()
This to ensure that services, and conditions they may create, actually
are recorded in the condition subsystem.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 15:27:29 +01:00
Joachim Wiberg d068684154 plugins: fix possible ordering bug; pidfile --> bootmisc
The recently updated pidfile plugin now also watches the subdirectories
in /var/run, but for that to work it must witness the creation of these
subdirectories.  The bootmisc plugin creates several, e.g., /run/quagga/
in which PID files like zebra.pid are created.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 15:25:35 +01:00
Joachim Wiberg 4a83c95d2b contrib: simplify example service stanzas; skip path, reduce conds
- Absolut paths are only necessary in case of ambiguities
- Without absulute paths conditions are shorter, e.g. <svc/syslogd>
- Drop <net/lo/up> condition for SSH daemons, not necessary

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-09 15:07:09 +01:00
Joachim Wiberg 5d7ce3a92b configure: drop remaining --with-console, auto-probed now
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 20:20:08 +01:00
Joachim Wiberg 82664396d6 Refactor 3e8d63c: use consoles from /sys/class/tty/console/active
As documented in the kernel docs and systemd[1], the default system
console is the first listed in /sys/class/tty/console/active, which
is the reverse order of console= given on the kernel cmdline.

Some distros don't have console= on their default command line in
their bootloader, e.g. Alpine Linux, some multiple, e.g Buildroot.
Instead of relying on the value given at configure time we probe
sysfs and open all (at most three) consoles listed.  This way we
at least get the default console for our progress output.

- drop old --with-console from configure script
- drop /proc/cmdline fishing in favor of sysfs
- replace CONSOLE from configure with new console()

[1]: http://0pointer.de/blog/projects/serial-console.html

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 20:09:49 +01:00
Joachim Wiberg 3fb700c17d Deprecation warning: inetd removal, update TODO accordingly
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 17:39:13 +01:00
Joachim Wiberg 1a5aabc034 Update configure examples and build scripts with correct paths
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 17:27:05 +01:00
Joachim Wiberg aa4addfa86 configure: drop note at bottom, we use std gnu defaults now
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 09:28:36 +01:00
Joachim Wiberg 06fdcf51b9 configure: revert to using GNU defaults, update summary
- Changing the GNU defaults is messy.  The best way is to leave them
  alone and let the user set their install locations themselves.
- Show --exec-prefix in config Summary, that's where the binaries go

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 07:58:25 +01:00
Joachim Wiberg 7d6eb2b59b initctl: use same headings for ls as show
From the start, the output from the 'list' command has been different
from the output of the 'show' command.  No longer.

Also, drop the 'AVAILABLE', 'ENABLED', and 'STATIC' prefixes.  They were
a bit screamy and superfluous.  'STATIC' wasn't even a good name for the
locally administered ones.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-08 07:29:05 +01:00
Joachim Wiberg 5c2ba8ef3a Adapt ifupdown support to new world, run 'ifup -a' in the background
All Debian based distros are moving towards a /etc/network/interfaces.d/
world.  Adding support for that is too complex, so we're reverting back
to calling 'ifup -a' or 'ifdown -a'.  We still guard this by checking
both for 'ifup' and the existence of /etc/network/interfaces (which in
the new world only contains a line to source per-interface files).

By popular demand, this patch also changes to bring up/down networking
in the background.  Useful for embedded system bringup and containers.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-07 14:54:53 +01:00
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
Joachim Wiberg 254d7e0238 Merge pull request #142 from jackuess/sigpwr-handling
Follow-up to eeb59eb: handle SIGPWR like SIGUSR2

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2021-02-02 16:10:00 +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
Joachim Wiberg 378456b6bd Merge pull request #138 from wkz/boot-refactor
Bootstrap refactor
2020-10-20 19:21:15 +02:00
Tobias Waldekranz adcc78039e Bring back the hotplug-daemon-heuristic as a plugin
This way, the default behavior stays the same, but users can opt out
by disabling the plugin.
2020-10-20 14:57:10 +02: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 2ce1a003d5 Add notice about default paths to configure summary
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2020-09-16 06:39:47 +02:00
Joachim Wiberg 8a8a51e23c Merge pull request #132 from firasuke/patch-1
Fix styling
2020-09-13 08:31:33 +02:00
Firas Khalil Khana c3e0a205f9 Fix styling 2020-09-12 16:21:13 +03: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 Wiberg 31f6362e2e Update author (my) last name
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2020-09-02 23:38:11 +02:00
Joachim Nilsson 946ca09c54 Merge pull request #130 from roycyt/fix-typo
doc/distro.md: fix typo
2020-07-10 11:07:47 +02:00
Roy Chen 552f52e061 doc/distro.md: fix typo 2020-07-10 14:49:16 +08: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 df54f5a59c plugins: modprobe: Skip for systems without modules
Skip for systems without modules, e.g. small embedded or containers

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-07-01 13:07:57 +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
Joachim Nilsson 0d41ff77be Minor, adjust heading
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-06-26 07:01:35 +02:00
Joachim Nilsson 76c2054fa6 Merge pull request #128 from liuming50/dont-hard-code-etc-hostname
Dont hard code etc hostname
2020-06-09 11:30:37 +02:00
Ming Liu 1fa6a98e79 modules-load.c: allow MODULES_LOAD_PATH to be overridden
Define MODULES_LOAD_PATH only when it's unset, this allows it to be
overridden, for instance, by passing CFLAGS.

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
2020-06-09 10:54:09 +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 af6f71abe4 Create SECURITY.md 2020-05-22 09:39:16 +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 2a4052bd8d plugins: modprobe: Never follow symlinks in /sys/devices
Unlike find(1), nftw(3) defaults to follow symlinks.  For some kernel
configurations this turned out to be detrimental and caused the plugin
to loop forever scanning modalias files.

Also, check if /sys is mounted before even calling nftw().

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 9d9b6b5201 Update ChangeLog and bump version for v3.2-rc3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 18:06:25 +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 2b2c6aaf4e docs: Relocate GitHub specific files to .github/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-23 17:46:22 +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
Joachim Nilsson 217df432d6 Add support for 'console' as compat alias to '@console'
This patch makes it possible to declare tty's using the magic keyword 'console',
an alias for the already existing '@console' keyword, which automatically detect
valid console(s) from the console=foo kernel command line.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 22:35:32 +02:00
Joachim Nilsson cfa97253be Fix missing signal.h, required when building for uClibc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 22:34:19 +02:00
Joachim Nilsson 6462bac249 finit: /run: Follow-up to 7c8b0df7, use MS_ mount flags instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:28:48 +02:00
Joachim Nilsson b0a1d6bd61 Fix warning message when service doesn't exist: !. -> .
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson ee4768ba53 contrib: Let tty1 be available in runlevel 1 on Void and Alpine
The default runlevels are otherwise 2-5.  Usually, however, when
debugging a system you may want to have runlevel 1 (single user
level) available to log in.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson c7c0c723d6 Update TTY speed recommendations in README.md and Debian defaults
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson b7c1a2a198 Change tty default baud rate: 38400 -> 0, i.e. keep kernel default
This is a more sane default, and also what systems expect, and what
other getty implementations support.  I.e., unless specified, or set
to 0, the tty baud rate is zero -- which means do not change speed
at all.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson af45166814 src: Add critical debug messages for debugging condition handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson 1a881389b2 plugins: pidfile: Handle conditions for PID files in sub-directories
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson 6306c757a2 src: svc: Use realpath() to check if untangled file exists
The svc_find_by_pidfile() function may be called with "/run/./foo.pid",
or similar, which must be sanitized before being compared to the PID
file of each svc_t.

This patch introduce realpath() to untangle the paths and check if the
file actually exists.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson 3865ce765e src: svc: Handle case where multiple services have same PID file
Services may exist in multiple runlevels, i.e. one behavior at bootstrap
and another at runtime.  If the user does not set a specific PID file to
be used as condition finit can match the wrong svc.

This patch extends svc_find_by_pidfile() to also compare the contents of
the PID file with the PID of the registered svc_t.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 21:15:48 +02:00
Joachim Nilsson aa08221666 configure: Remove --enable-rw-rootfs detect using /etc/fstab instead
This patch removes the --enable-rw-rootfs build flag.  Like OpenRC we
now check /etc/fstab instad; if `/` is listed *and* doesn't have the
`ro` flag set, we remount / read-write.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-22 20:08:52 +02:00
Joachim Nilsson 7c8b0df720 finit: /run: Mount with nosuid,nodev,noexec for added security
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-15 19:28:23 +02:00
Joachim Nilsson cb802cd54e finit: devpts: Mount with recommended ptmxmode=0666
For details https://www.kernel.org/doc/Documentation/filesystems/devpts.txt

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-15 19:28:13 +02:00
Joachim Nilsson 8379b4927b Fix GCC truncation warnings, too small buffers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-12 00:33:52 +02:00
Joachim Nilsson 6a7f48970c Add cgreaper.sh to dist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-12 00:29:39 +02:00
Joachim Nilsson d797754ca8 Update ChangeLog and bump version for v3.2-rc2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 23:54:26 +02:00
Joachim Nilsson 770a79fa89 Fix #120: Redirect stdin to /dev/null for services by default
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 22:24:33 +02:00
Joachim Nilsson ff24ee3553 Fix #124: reap all children in same process group of dying parent
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 21:55:40 +02:00
Joachim Nilsson 25c194ef93 Create unique service cgroup based on name:id
We want to have unique cgroups per instance.  I.e., a DHCP client for
eth0 should have its own cgroup separate from a DHCP client for eth1.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-11 21:50:38 +02:00
Joachim Nilsson 91a9c83928 Send signal to every process in the same process group
When stopping a run/task/service we must send SIGTERM/KILL to all every
process in the same process group.  Otherwise we may end up with stray
processes like 'logit' when log redirection is enabled.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-04-08 18:00:48 +02:00
Joachim Nilsson 9b022ed7a4 Create FUNDING.yml 2020-04-04 13:56:36 +02:00
Joachim Nilsson ca3fc057f2 configure: Change semantics of 33bb6ed, logit enabled by default
The logit tool is not just used by scripts and such, when logger is
absent.  It is also used by Finit internally to redirect logging of
services to syslog and/or log file, with log rotation.

This patch reverts the default to enabled.  Someone explicitly has
to disable logit now to get less functionality.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-30 11:56:39 +02:00
Joachim Nilsson bf6e599584 Handle log redirect to syslog when logit is disabled
`--disable-logit` at configure time means redirecting stdout from a
service to a file is completely disabled.  Fallback to `logger` can
not be guaranteed to provide log file rotation, so all logs will be
sent to syslog instead.  In case logger is also missing, a simple
redirect using fork() + syslog() is used as fallback.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-30 11:53:43 +02:00
Joachim Nilsson 89c7171223 Refactor run/task/service stdout redirection after setsid() addition
This patch refactors redirect_null() and adds support for redirecting
stdout to console when 'log:console' is enabled.  This was previously
sort of the default, but with the addition of the long-sought-after
setsid() call we needed to change things.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-30 10:11:29 +02:00
Joachim Nilsson c41f3f4a06 Call setsid() by default to detach from controlling terminal
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-29 17:39:35 +02:00
Yaroslav Syrytsia 0a54a9624a Fix #123: Regression in sysv start/stop scripts
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-26 05:16:52 +01:00
Joachim Nilsson 1e238eec61 Increase MAX number of arguments to a service 32 -> 64
Usually a wrapper script is recommended, but for some use-cases it
is more efficient to just be able to use more command line args.

Example application that needs this; udhcpc

Note, we should refactor this to use a dynamically allocated array
instead of this static one.  We relied heavily on static arrays in
Finit 1, when everything had to fit i shm.  This is just legacy.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-19 07:50:36 +01:00
Joachim Nilsson 4163527006 Fix run-parts regression introduced in 9a98bff2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-09 14:29:04 +01:00
Joachim Nilsson f06e17ccc6 initctl: Widen status column a bit to fit 'stopping' state
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-03-05 17:51:52 +01:00
Joachim Nilsson fe41b9c4b8 Revert "plugins: pidfile: Simplify and clean up developer debug messages"
This reverts commit 69016bb8f5.
2020-03-02 07:22:15 +01:00
Joachim Nilsson 7cf3ef80db Revert "Travic-CI: Disable clang temporarily for Coverity run"
This reverts commit 27c839bc92.
2020-02-29 17:10:28 +01:00
Joachim Nilsson 69016bb8f5 plugins: pidfile: Simplify and clean up developer debug messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 17:04:27 +01:00
Joachim Nilsson f7d5b588c9 plugins: pidfile: Factor out directory handling from callback
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:52:51 +01:00
Joachim Nilsson 0ad99ce054 Fix use-after-close in service.c:redirect(), found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:42:53 +01:00
Joachim Nilsson 1176961e7b plugins: pidfile: Fix memory leak in pidfile_callback()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:40:06 +01:00
Joachim Nilsson 27c839bc92 Travic-CI: Disable clang temporarily for Coverity run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-29 16:32:05 +01:00
Joachim Nilsson 6149e93aca docs: Update documentation on svc conditions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 17:16:24 +01:00
Joachim Nilsson 4e7baa807e Fix #109: Declare PID file path to dbus-daemon in dbus plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 16:50:57 +01:00
Joachim Nilsson 54cfa74042 Fix #109: Support PID files in subdirectories to /var/run
Services, like dbus and teamd for instance, may create their PID files
in a subdirectory of /var/run (today often /run). E.g.,

   - /var/run/teamd/a1.pid    -- For aggregate A1
   - /var/run/dbus/pid
   - /var/run/lxc/foo.pid     -- For container foo

This patch adds support for dynamically adding inotify watchers to any
new subdirectory created in /var/run (discarding too deep directories).

To match services in this directory the run/task/service/sysv stanza
must contain the pid:!/path/to/pidfile.pid syntax.  This pid file name
is also used to create the condition this service asserts using the
following formula:

   svc/ + <dirname of service> + <subdir and file without .pid>

E.g., the case of teamd (above) gives condition 'svc/usr/bin/teamd/a1'

The special case of dbus is interesting, since it may not be a special
case, but rather the norm for services using a subdirectory.  It is
handled as follows; when a new subdirectory is detected, the directory
is scanned for files matching *.pid.  Matching files follow the teamd
case.  The directory is also scanned for 'pid', which then gives us the
condition 'svc/usr/bin/dbus'

One last example, illustrated by lxc-start, where we want to track the
condition for the LXC container foo.  The service stanza:

   service pid:!/run/lxc/foo.pid lxc-start -n foo -F -p /run/lxc/foo.pid -- Container foo

This command has no leading path so the condition is composed entirely
from the PID file location:

   svc/  + '' + lxc/foo => svc/lxc/foo

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 16:39:53 +01:00
Joachim Nilsson 97ce0aa519 Rename local variable shadowing variable in outer scope
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-28 14:36:14 +01:00
Joachim Nilsson e72b61c9c9 Minor, fix dead EeePC fastinit link and adjust distro ordering
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-27 23:08:20 +01:00
Joachim Nilsson b66069278f Support for a custom kill:DELAY, default 3 sec
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 18:49:47 +01:00
Joachim Nilsson 1192506d43 Support for custom halt:signal, default SIGTERM
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 18:28:02 +01:00
Joachim Nilsson decdc1560a Support for monitoring forking services/sysv daemons
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 14:10:47 +01:00
Joachim Nilsson f6372de6a9 New function pid_file_read(), returns PID from a pid file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:40:44 +01:00
Joachim Nilsson 9052248127 Check for an actual /proc file, not directory, in pid_alive()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:40:18 +01:00
Joachim Nilsson 6ab9c8fad6 Allow services to be started without absolute path, trust $PATH
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:39:17 +01:00
Joachim Nilsson 619bd03551 Drop old comment related to service plugins (now removed)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:38:50 +01:00
Joachim Nilsson e301877b16 Follow-up to 12d14aa, configurable auto-reload of .conf files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-26 11:13:06 +01:00
Joachim Nilsson 3b67afe480 Change semantics for SysV start/stop scripts
If a start/stop script returns OK we classify it as 'started' and leave
it in running state, despite having collected its PID.  This way we can
track what scripts need to be called with 'stop' when changing to a
runlevel they are not declared for.

Also, clean up related debug messages from earlier commit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:35:15 +01:00
Joachim Nilsson 9a9a9f4bfe Remove old blocking (!) waitpid() call in service_start()
Remnant from when processes were collected in service_start(), now all
handled by service_monitor() from SIGCHLD and service_step().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:32:04 +01:00
Joachim Nilsson f38299bfca Redirect stdout/stderr according to .conf when stopping SysV service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:31:21 +01:00
Joachim Nilsson 99901782ff Factor out stdout/stderr redirection to from service_start()
This new function can then be used also by service_stop(), e.g. for SysV
start/stop scripts.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 12:30:00 +01:00
Joachim Nilsson 912a336997 Only show [ OK ] startup/status if run tasks exit normally
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 07:52:36 +01:00
Joachim Nilsson c3eca9fe8f Save process exit status to svc_t
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-02-05 07:23:06 +01:00
Joachim Nilsson 225510a270 Remove gratuitous newline when finit stops its own log service
This patch fixes an annoying thing when typing reboot/shutdown/poweroff
that caused an extra newline to be printed before displaying services
stopping.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-30 18:29:45 +01:00
Joachim Nilsson 4389fbd8bc Merge pull request #122 from jackuess/fix-inaccurate-sleep
Switch to using nanosleep in favour of sleep
2020-01-30 18:01:46 +01:00
Jacques de Laval 920382518f Switch to using nanosleep in favour of sleep
The remaining sleep time returned by sleep is not accurate enough to be
used as a means to achieve "signal safe"-sleep. nanosleep can be used
in similar fashion instead and is granular enough for our purposes.

This issue was identified during reboot, when Finit is bombarded with
SIGCHLD, aborting the sleep that we do to give daemons a chance to shut
down gracefully. The total delay ended up being less than a second when
in fact two seconds were the intended delay.
2020-01-30 15:39:46 +01:00
Joachim Nilsson 997a699b7e Add more debug logs for /etc/finit.d*/ inotify and exec_runtask()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-22 15:48:56 +01:00
Joachim Nilsson 21db27ee75 Minor, coding style cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-22 15:48:42 +01:00
Joachim Nilsson fa0c63070c Add support for starting/stopping SysV init scripts
This patch adds initial support for starting a SysV init script in a
runlevel, and stopping it when leaving a runlevel.

    sysv [LVLS] <COND> /path/to/script.sh -- Optional Description

The SysV /etc/inittab file, which may use /etc/init.d, or /etc/rcN.d,
is still not supported.  A separate plugin would be required for this,
see the documentation for more information.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-22 15:45:08 +01:00
Joachim Nilsson 9bfc9092b8 Document new mdules-load and modprobe plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-15 22:53:24 +01:00
Joachim Nilsson 1c6464a7a8 Add support for cold plugging devices, auto-loading of modules
This patch adds a new plugin to Finit called modprobe.  It probes in
/sys/devices after modalias files and then calls 'modprobe -ab' for
each alias listed.

For hot-plugging we recommend adding the following to /etc/mdev.conf

  $MODALIAS=.*	root:root	0660	@modprobe -b "$MODALIAS"

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-12 20:00:47 +01:00
Joachim Nilsson 51adba4387 Slight update, we won't be releasing in 2018 ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-08 12:08:24 +01:00
Joachim Nilsson bb1aed1010 initctl: Follow-up to 6a5f439, don't fail if directory already exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-08 12:06:41 +01:00
Joachim Nilsson cf4a1332f9 Revert "Travis-CI: Disable clang for Coverity Scan run"
This reverts commit fc37b854ae.
2020-01-07 20:46:49 +01:00
Joachim Nilsson d70fb85aaf Make MIT badge more readable, teal is also a nice color
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 20:45:53 +01:00
Joachim Nilsson fc37b854ae Travis-CI: Disable clang for Coverity Scan run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:55:03 +01:00
Jonas Holmberg ca210f5431 Add support for logging security related events
This patch introduces the LOG_CONSOLE syslog facility for logging common
events.  In industrial applications aiming for IEC 62443 compliance the
following events are central for system observability:

- Change of runlevel - i.e., starting up, shutting down, upgrade, etc.
  Facility: console, severity: notice
- Service starting
  Facility: console, severity: notice
- Service restarting
  Facility: console, severity: notice
- Service stopping
  Facility: console, severity: notice
- Service failed to start
  Facility: console, severity: warning

The use of facility console for this makes it easier to filter out when
forwarding syslog messages from an embedded system to a remote log sink.
Otherwise messages of facility daemon would be used, which include a lot
more, and mostly irrelevant, information.

Signed-off-by: Jonas Holmberg <jonas.holmberg@westermo.se>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:38:21 +01:00
Jonas Holmberg a19a3c774e Fix issue where svc_find() finds the wrong service
This issue may arise in situations where the name of the service being
compared is a sub-string of the service we want to see if it exist.

Example:
  - Two different services: teamd, teamdagentd
  - They have the same id, 1 being the default if none is specified
  - The service with the shortest name is created first

While checking if the "teamdagentd" service exists we eventually compare
it to the "teamd" service.  Prior to this fix we only compare the names
names with the length of the existing service.  Hence, teamdagentd will
seem to be the same as teamd since the first part of the string is equal
to the existing.

Signed-off-by: Jonas Holmberg <jonas.holmberg@westermo.se>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:23:53 +01:00
Joachim Nilsson a4f1330eae Simplify, no need to check svc->id, is always a valid string
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:21:46 +01:00
Joachim Nilsson 38d768ac9e Travis-CI: Enable all -Wfoo CFLAGS globally and build logit in all
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:07:27 +01:00
Joachim Nilsson 36b14f9ff7 Travis-CI: Move environment variable PKG_CONFIG_PATH to env:->global:
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:06:55 +01:00
Joachim Nilsson bdbd2afc40 Travis-CI: Re-enable clang builds after Coverity Scan run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:05:26 +01:00
Joachim Nilsson 33bb6ed5ac Add --enable-logit to configure, disabled by default
Since sysklogd now ships an excellent enhanced logger tool there is no
need for Finit to provide its own tool for the same purpose by default.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 13:02:06 +01:00
Joachim Nilsson 212083b922 Introduce strterm(), hard-add terminating '\0' at end of buffer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 03:02:39 +01:00
Joachim Nilsson 55c49a0bf0 Sanitize job[:id] tuple read from UNIX socket using a regex
This is a really tight check for a single "job[:id]" tuple, not much
escapes it, Coverity should be a lot more happy about our addressing
CWE-20 with this one.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson b369e1cfa2 Refactor svc_parse_jobstr(), use tokstr() instead of strtok_r()
This is a safer version of strtok() that makes sure we do not step
outside of string bounds.  Coverity complained about this, but was
likely more concerned with the lacking sanitize() and trusting data
read from a UNIX domain socket ...

Note: not only is tokstr() not re-entrant, it is also hard-coded
      to only check for whitespace as token separator.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson cfefe23275 Fix another GCC 9 string truncation warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson 338c358a75 Defensive programming, check bounds of loop variable first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson fe017642de Refactor do_query() to same calling convention used elsewhere
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 02:51:15 +01:00
Joachim Nilsson 8d271ac5b8 Fix GCC 9 string trunction warning
- Increase size of resulting path buffer, unlikely a real problem
- Check return value from snprintf() to detect errors and truncation
- Add logit() function wrapper to initctl, maps to _e()/_d()/_pe()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 01:03:57 +01:00
Joachim Nilsson 744719219e initctl: Remove experimental cond set/clear commands
The commands are both unsafe (insecure) and send the wrong message,
that initctl can be used to script conditions.  Only plugins are
officially supported to manage conditions.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-07 00:35:13 +01:00
Joachim Nilsson 7bf2fcb6e3 Fix Coverity CID 265222, guard init_request::data member
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 23:56:59 +01:00
Joachim Nilsson ae9ed20d94 Revert "Attempt to fix Coverity CID 265222"
This reverts commit 238f63c0d3.
2020-01-06 23:54:32 +01:00
Joachim Nilsson a5c9d0a3f4 initctl: Fix file descriptor leak, found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 22:04:59 +01:00
Joachim Nilsson a8c071c5ef Fix memory leak, call strdup() as late as possible, found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 22:03:01 +01:00
Joachim Nilsson 238f63c0d3 Attempt to fix Coverity CID 265222
When reading data from (presumably) initctl over the UNIX domain socket
we might actually be receiving corrupt data from a malicious attacker.

This patch is an attempt at, the very least, guarding against C string
functions reading out of bounds due to non-NULL terminated strings.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:58:03 +01:00
Joachim Nilsson 41647a814c Handle improbable case were dev may be NULL, found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:46:44 +01:00
Joachim Nilsson 765ef63274 Handle mkdir() error in cgroups, don't fail if already exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:41:43 +01:00
Joachim Nilsson 6a5f4398a2 initctl: Check mkdir() for error and give helpful message on fail
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:37:07 +01:00
Joachim Nilsson 7fc515678f Check if svc ID is non-empty before strcmp(), found by Coverity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:31:04 +01:00
Joachim Nilsson e410a24d13 Fix %s i _d() message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 21:26:51 +01:00
Joachim Nilsson 397f67d03a Clear current line before starting built-in getty
When logging out from the shell, e.g. with Ctrl-D, artifacts from that
session may remain on the current line.  This patch makes sure to clear
up that line before issuing a newline and starting the built-in getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:37:00 +01:00
Joachim Nilsson b4b9111b33 Enable line wrap in TTY, in case was disabled previously
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:26:56 +01:00
Joachim Nilsson c19489d6c3 Add support for @console to external getty in tty_register()
- Refactor code to figure out device so it works for both the built-in
  and external getty code paths
- Fix memory leak when user edits an existing tty device
- Replace @console in argument list to external getty

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:05:20 +01:00
Joachim Nilsson 00a2840853 Allow Ctrl-U, Ctrl-D again in built-in getty
Many users found it very frustrating that it was impossible to use
standard commands like Ctrl-U and Ctrl-D at the login: prompt.  It
was never the intention to hamper users for no reason like that.

Also, compensate for cursor-up in "Please press Enter" wait-handler.
Curiously, this makes everything very neat looking also when having
'nowait' enabled for the tty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 19:01:53 +01:00
Joachim Nilsson d1718d338e Set proper RAW mode for "Please press Enter to activate ..."
Also, while leading with a \n for the activation text and clearing the
line before getty is called, some getty implementations, e.g. BusyBox,
write an extra \n before printing /etc/issue.  For perfectionists that
want a single newline separating started services and the first line
of /etc/issue we now not only clear the line, we also move the cursor
one line up before handing over to getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 18:58:08 +01:00
Joachim Nilsson 58ade5d74e Allow built-in getty to show in ps as 'tty DEV'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 18:52:40 +01:00
Joachim Nilsson c391e04983 Hide command line arguments from ps, for forked children like getty
The built-in gety in Finit forks but does not execv().  To prevent
confusion on the part of the user, this patch hides all command line
arguments to PID 1 so it won't show up in ps listings of children.

Finit currently reads its arguments from the kernel /proc/cmdline,
it has hard-coded paths to /etc/finit.conf etc.  A future version
of Finit may take command line params, in which case this patch
should be moved after any getopt() handling.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-06 18:49:14 +01:00
Joachim Nilsson 85fe613b30 Account for 3-4 byte wide unicode characters in heading
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-05 16:10:41 +01:00
Joachim Nilsson 880ad98dbe Workaround markdown parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-04 11:49:50 +01:00
Joachim Nilsson b1a88df9fc Pad heading in modern style using ═══════════════════
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-04 11:40:09 +01:00
Joachim Nilsson aaf7888411 Move badges to top row
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-03 14:27:45 +01:00
Joachim Nilsson 6edb01a72b Update ingress, time passes oh so quickly ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-03 14:27:41 +01:00
Joachim Nilsson 636f6678ed Introducing Finit progress 𝓜𝓸𝓭𝓮𝓻𝓷
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2020-01-02 14:59:32 +01:00
Joachim Nilsson 3b62f46599 TODO: Remember to collect siginfo_t on SIGCHLD
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-12-12 17:57:09 +01:00
Joachim Nilsson 49f0d94b95 Drop reference to non-existing site, refers to *good* example now
Also, drop the Emacs hint, not needed anymore.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-11-04 06:09:59 +01:00
Joachim Nilsson abccb26a83 Check for pkg-config in configure before looking for deps
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-07-04 22:26:08 +02:00
Joachim Nilsson 0848b9b07a Minor, replace cgroup hard-coded path with path from configure
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-05-14 10:15:10 +02:00
Joachim Nilsson c64188bfc5 plugins: rtc: Simplify failed restore from RTC warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-29 18:20:38 +02:00
Joachim Nilsson 5e789401d4 Rename hwclock.so plugin to rtc.so since it's now stand-alone
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-05 21:35:13 +02:00
Joachim Nilsson 744fdd654f plugins: hwclock: Native ioctl support for RTC, skip hwclock tool
The BusyBox hwclock is really bad at handling, or rather displaying,
errors properly.  When the kernel signals EINVAL, or ENOENT, it just
shows that message on stderr.

This patch implements proper RTC load/store at boot/halt with quite
some improved error handling suitable for embedded systems.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-04-05 21:27:39 +02:00
Joachim Nilsson f51fde4d46 Initial support for cgroups
Similar to how systemd creates cgroups for all services, for purposes of
tracking, Finit now does the same.  We also mount all available cgroups
in the /sys/fs/cgroup namespace.

This patch adds support for grouping processes in logical cgroups, like
systemd, and an `initctl ps` command to list the hieararchy.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 18:35:36 +01:00
Joachim Nilsson 85261c9acd initctl: Create 'enabled' services directory if it doesn't exist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 12:42:13 +01:00
Joachim Nilsson 6a1082a947 New helper function: echo(), like shell echo but for C
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 10:33:00 +01:00
Joachim Nilsson 2094d2a53a Warn if Finit fail to mount /proc and /sys
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-02-05 10:31:36 +01:00
Joachim Nilsson d7da177742 Relocate images to img/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-01-27 10:56:39 +01:00
Joachim Nilsson 170e5aa3fd docs: TODO: Drop simple conf item, contrib/finit.conf exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2019-01-27 10:54:47 +01:00
Joachim Nilsson f8ef8a1616 Merge pull request #115 from jonasj76/id-as-string
Add support to specify service ID as a string
2018-12-11 21:12:50 +01:00
Jonas Johansson f5f1a55747 Add support to specify service ID as a string
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2018-12-11 16:43:05 +01:00
Joachim Nilsson a36aade7f4 Merge pull request #113 from srand/master
Bugfixes and features
2018-10-23 07:15:20 +02:00
Robert Andersson 76fc72770e pidfile: monitor renamed files, e.g. rsyslogd.pid.tmp
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:53:57 +02:00
Robert Andersson b64dbbf8d0 fix condition string lengths
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson d371b85c47 fix C++ compilation issues
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson 053304012f Add option to log service/task output to the console
Example:
    service log:console [2] /usr/sbin/udhcpd -f -- DHCP Server

Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson 12d14aae84 fix service enable/disable support
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson 6a7f115781 Add config option for manually started services
Example:
    service manual:yes [2] /usr/sbin/lighttpd -- HTTP Server

Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson 423c8d41a7 modules-load: add task name config
Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson f2cab53e55 Add service/task name config option
Allows the service/task name derived from the binary to be
overridden with a custom name.

Example:
    service name:dhcpd [2] /usr/sbin/udhcpd -f -- DHCP Server

Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Robert Andersson 33fd6f0049 Add modules-load.d plugin
This plugin scans /etc/modules-load.d for modules to modprobe.

Signed-off-by: Robert Andersson <robert.m.andersson@se.atlascopco.com>
2018-10-22 12:51:58 +02:00
Joachim Nilsson e83dcafb02 stty(): Restore cursor as well, if it was hidden previously
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-19 17:52:00 +02:00
Joachim Nilsson 9a98bff23f Run all runparts scripts using /bin/sh -c foo
This patch is an attempt to address an issue with runparts scripts found
by Magnus Malm, @magnusmalm.  Any script in:

    runparts /foo/bar.d/

were required to have the #!/bin/sh she-bang, otherwise Finit would not
start them.  He tested with the standard run-parts tool, which had no
such restrictions.

The patch not only makes sure to start scripts using `/bin/sh -c`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-18 22:19:51 +02:00
Joachim Nilsson 1a2f7d162b Helpful symlink to config.md
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-17 14:12:04 +02:00
Joachim Nilsson 5579ba16b1 Bump version for v3.2-rc1 pre-release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-16 08:58:56 +02:00
Joachim Nilsson 510b36645b Fix potential buffer overruns found by GCC 8.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-15 22:56:23 +02:00
Joachim Nilsson 67cd88cd23 svc_status(): Fix potential fall-through in switch-case
Found by GCC 8.2

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-15 22:54:33 +02:00
Joachim Nilsson a04a6eda12 Update ChangeLog for upcoming v3.2 bug fix release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-13 21:32:56 +02:00
Joachim Nilsson 94525d6aae Update .gitignore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-13 20:16:29 +02:00
Joachim Nilsson 1d14806fd8 Never make promises about content in release versions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-13 20:14:45 +02:00
Joachim Nilsson 5e6f64eec9 Bump version for new v3.2 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-11 16:10:29 +02:00
Joachim Nilsson df22628183 Refactor end of bootstrap using new work queue helper
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-09 07:14:33 +02:00
Joachim Nilsson 4870cab898 Refactor, use new work queue helper
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-07 21:30:07 +02:00
Joachim Nilsson 859c216347 schedule: Add simple work queue helper
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-07 21:29:10 +02:00
Joachim Nilsson 931565c425 Simplify pidfile_reconf() thanks to the addition of schedule_wq()
We can now rely on service_step() to continue stepping run/taks/services
until no more state transitions are made.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-07 18:35:12 +02:00
Joachim Nilsson 3006caf670 Refactor dddd45e, schedule work to iterate over services again
Instead of changing the API of service_step(), and relying on all the
different callers to step again, we can schedule another event to do
this for us.

In addition to handling the cond_update() case this also handles all
other callers of service_step().  Ensuring that nested conditions do
trigger changes.

Also, reverting dddd45e fixes a minor regression in service_monitor()
which caused it to not clean up collected bootstrap tasks.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-07 18:34:42 +02:00
Joachim Nilsson 1269f082de service_unregister(): Refactor, simplify and set #ifdef correctly
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-05 08:57:01 +02:00
Joachim Nilsson 7d444e07a5 service_stop(): Nothing to do if svc is already stopping or halted
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-05 08:54:08 +02:00
Joachim Nilsson 6ec4dce5f9 Travis-CI: Fix download URL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-05 07:20:22 +02:00
Joachim Nilsson 8a0edbe801 Travis-CI: Update build requirements
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-05 07:14:43 +02:00
Joachim Nilsson 46683f8eb8 Remove service condition when service is deleted
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-04 21:56:01 +02:00
Joachim Nilsson fb16abd855 Require new libuEV API: uev_init1() to enforce a small event cache
In cases where you have multiple events pending in the cache and some
event may cause later ones, already sent by the kernel to userspace,
to be deleted the pointer returned to the event loop for this later
event may be deleted.

There are two ways around this (accessing deleted memory); 1) use this
function to initialize your event loop and set maxevents to 1, 2) use a
free list in you application that you garbage collect at intervals
relevant to your application.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-04 21:53:36 +02:00
Joachim Nilsson 060de93b5b Wait for all services to complete before changing runlevel
We allow all run/task/services to complete before changing runlevel.
This means stepping them all while we wait for their completion, since
services may depend on each other.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-03 08:40:23 +02:00
Joachim Nilsson 231b887b2a Follow-up to a5491b3, no need to restore svc state anymore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-03 08:40:23 +02:00
Jonas Johansson dddd45e3b5 Reassert condition when svc_t goes from WAITING --> RUNNING
Reassert condition when an unchanged/unmodified process goes from
WAITING state to RUNNING.  I.e. it had a condition that went to flux
during `initctl reload`, which drove it to WAITING and was then sent
SIGSTOP during reconf.

Also, on condition update, loop through all services until no more state
changes are observed.  This allows long dependency chains of services to
resolve and actually go back to RUNNING state as intended whenever any
condition changes at runtime.

Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-02 19:03:30 +02:00
Joachim Nilsson cb9f6213dc Instead of deleting svc_t, mark it for cleanup by garbage collector
When a process, that has been sent SIGTERM by us, takes a full 3 sec to
terminate, the event loop may have both the SIGCHLD event (where we do
the svc_del()) and the 3 sec timeout event to send SIGKILL in its event
cache.

When we call svc_del() it releases the svc_t memory, which can then be
dereferenced by the SIGKILL timer callback and we're doomed.

There are two fixes to this; 1) the event loop, that uses epoll_wait(),
can set maxevents=1 (instead of today's 10).  The kernel will then drop
the SIGKILL timer event before it's delivered to the userspace process.
2) we can postpone deleting the svc_t to a "later stage" when all events
in the event cache have been processed.

This patch implements (2).  A later patch will use uev_init1(ctx, 1) to
ensure the event cache handles only one event at a time.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-02 13:22:21 +02:00
Joachim Nilsson f33ed869e4 Minor, remove unused/malplaced declaration
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-02 13:18:33 +02:00
Joachim Nilsson 4790344fbe Minor, refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-10-02 13:18:15 +02:00
Joachim Nilsson a40858f162 Fix #103: Register multiple getty if @console resolves to >1 TTY
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-30 16:32:48 +02:00
Joachim Nilsson 682e80fed5 Remove HOOK_SVC_LOST, recommend using accounting instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-30 11:28:27 +02:00
Joachim Nilsson cd91e2c66c Skip "Restarting ... " progress for bootstrap processes
Reduce the noise: we don't need to notify the user if a process started
in bootstrap is simply SIGHUPed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-29 15:16:59 +02:00
Joachim Nilsson 470549badb Add debug message to finit.d directory watcher callback
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-28 23:41:42 +02:00
Joachim Nilsson a85c3628b8 Wait for runlevel S to complete before deleting bootstrap tasks
If we delete bootstrap (only) run tasks in service_start() when they
complete they may be found and run again if *.conf reload takes place.

Instead, mark them as having been run, like regular runtasks, and set
their state directly to STOPPING.  The once flag ensures the svc is not
restarted if its .conf file is reloaded.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-28 23:37:02 +02:00
Joachim Nilsson 53ac0ffdfb Merge branch 'master' of ssh://git.troglobit.com:222/srv/git/finit 2018-09-28 06:57:26 +02:00
Joachim Nilsson eee6ffe95c Refactor end of service_start() to prevent deref freed svc
An SVC_TYPE_RUN may be deleted by svc_clean_bootstrap() as soon as it's
been collected.  We must not try to dereference that pointer afterwards,
e.g. in svc_is_daemon().

Refactor the whole of it to make the code easier to follow.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-28 06:50:33 +02:00
Joachim Nilsson a5491b3ded Remove HOOK_SVC_START, caused more problems than it was worth
An operator wanting to monitor processes started by Finit could use the
kernel ftrace framework.  E.g. execsnoop in perf-tools.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-28 06:49:49 +02:00
Petrus Hellgren a1ea8ff564 Bug fix: update inetd service args on config change
If an inetd service is changed, finit must update the command line
arguments associated with the service.

Signed-off-by: Petrus Hellgren <petrus.hellgren@westermo.se>
Signed-off-by: Petrus Hellgren <petrus.hellgren@gmail.com>
2018-09-27 14:55:01 +02:00
Joachim Nilsson 0dffa731d2 Extend bootrap timeout: 10 --> 120 sec
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-09-26 18:49:05 +02:00
Joachim Nilsson 9516c28a8a Add support for disabling (build+)install of docs and contrib section
In massively parallel builds we've seen finit fail in the install phase
of the contrib section with:

ln: failed to create symbolic link '/home/bob/jenkins/workspace/WeOS-feature_5.x_igmp-mld-snooping/staging/share/doc/finit/contrib/alpine/finit.d/getty.conf': No such file or directory
ln: failed to create symbolic link '/home/bob/jenkins/workspace/WeOS-feature_5.x_igmp-mld-snooping/staging/share/doc/finit/contrib/alpine/finit.d/keymap.conf': No such file or directory
ln: failed to create symbolic link '/home/bob/jenkins/workspace/WeOS-feature_5.x_igmp-mld-snooping/staging/share/doc/finit/contrib/alpine/finit.d/modules.conf': No such file or directory
ln: failed to create symbolic link '/home/bob/jenkins/workspace/WeOS-feature_5.x_igmp-mld-snooping/staging/share/doc/finit/contrib/alpine/finit.d/klogd.conf': No such file or directory
ln: failed to create symbolic link '/home/bob/jenkins/workspace/WeOS-feature_5.x_igmp-mld-snooping/staging/share/doc/finit/contrib/alpine/finit.d/syslogd.conf': No such file or directory

This patch is a countermeasure since fixing the root cause may take a
while (to be prioritized).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-08-28 11:25:52 +02:00
Joachim Nilsson fa0a4e8579 Merge branch 'dev' 2018-07-10 22:38:45 +02:00
Joachim Nilsson a487a30814 Refactor wdog tracking and hand-over to use svc_t instead of PID
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-09 23:49:04 +02:00
Joachim Nilsson 40db4f4f58 Minor, refactor to avoid namespace confusion with service.c API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-09 23:49:04 +02:00
Joachim Nilsson 3a1ad67e92 Convert built-in watchdog to a standalone mini watchdogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-09 23:49:04 +02:00
Joachim Nilsson 43942ab513 watchdog.c: Update copyright years and reflow license header
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-07-08 19:21:26 +02:00
Joachim Nilsson 3b2f2690e7 initctl: start and restart should behave the same if svc has crashed
Found by Mattias Walström, Westermo.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-06-18 18:33:49 +02:00
Joachim Nilsson 5684b761da Merge pull request #111 from jonasj76/inetd-stop-childen-v2
Only restart inetd services when neccessary
2018-05-07 10:06:33 +02:00
Jonas Johansson 59f22c7d27 fixup! inetd: only restart inetd services when neccessary
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2018-05-07 09:25:55 +02:00
Jonas Johansson f522a26125 inetd: only restart inetd services when neccessary
Do not restart a inetd service if the listening interface is changed.
Only bring down established connection which are no longer allowed,
i.e. do not touch already allowed established connections.

Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2018-05-03 08:57:19 +02:00
Joachim Nilsson efb1d40ffd Merge pull request #107 from jonasj76/inetd-stop-children
Stop inetd spawned child processes when stopping inetd service
2018-03-23 15:48:02 +01:00
Joachim Nilsson ea591c7580 Merge pull request #106 from jonasj76/inetd-dont-mark
Do not mark inetd connections for deletion when reloading services
2018-03-23 15:47:11 +01:00
Jonas Johansson af9a06466c inetd: stop inetd spawned child processes when stopping inetd service
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2018-03-23 15:40:42 +01:00
Jonas Johansson 7ed9f2ad05 inetd: do not mark inetd connections for deletion when reloading services
Signed-off-by: Jonas Johansson <jonasj76@gmail.com>
2018-03-23 15:32:41 +01:00
Joachim Nilsson 65ccc407fa Follow-up #100: Remove buggy "optimization", caught by Coverity Scan
We cannot allow pid_runpath() to return its 'file' argument because that
may be a stack variable in a helper function.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-22 08:08:48 +01:00
Joachim Nilsson 7fe9f3c4b6 Travis-CI: Disable CLANG build temporarily for Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-22 08:06:57 +01:00
Joachim Nilsson 24299ab5d9 Fix #105: Only remove /etc/nologin when moving from runlevel 0, 1, 6
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-21 08:44:14 +01:00
Joachim Nilsson e9670b87b3 Refactor, convert struct tty members to static strings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-18 19:19:45 +01:00
Joachim Nilsson 406339e755 Refactor, unify finit_tty_t + tty_node_t --> struct tty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-18 18:19:31 +01:00
Joachim Nilsson dc7039b8d8 Fix #100: Adjust path to COND_RECONF /var/run symlink may be missing
On systems with the new /run hierarchy the compat symlink from /var/run
may be missing, or not yet be set up by bootmisc.so.  This patch adds a
layer of safety to the condition layer, both set and get cond ops now
perform an adjustmed of the condition path if needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-18 11:49:27 +01:00
Joachim Nilsson 90249e50ef initctl: Show available services if none given
In case a user forgets to type in the service to enable, disable, or
touch, we try to be helpful and list available services instead of
bugging out.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-06 18:41:36 +01:00
Joachim Nilsson b8e6954c46 Issue #96: Remember to track run commands having run once as well
All service/task commands are tracked by the state machine, but run
commands are a bit special since they must run in sequence.  Hence,
we must increment their 'once' counter in service_start() instead.

This should fix the issue mentioned in #96 "took a long time before
the next line" -- because Finit was waiting for udevadm to reach a
once count > 0, which we didn't increment.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 23:57:50 +01:00
Joachim Nilsson 4585aa0fb4 Issue #96: Add udevd condition to udevadm trigger commands
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>
2018-03-01 23:57:27 +01:00
Joachim Nilsson f2655d14c8 Bootstrap condition subsystem as soon as possible
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 23:57:27 +01:00
Joachim Nilsson 6d1d51b28c Remove duplicate 'services' in debug message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 23:57:27 +01:00
Joachim Nilsson b9d233d19e Issue #96: Register two unique (!) udev triggers, run device trig 1st
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 08:43:15 +01:00
Joachim Nilsson 2ec132c75a Fix #96: Start udevd as a proper service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 01:06:32 +01:00
Joachim Nilsson 3092d55ec5 dbus: Fix too short buffer for dbus-daemon command line
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 00:40:54 +01:00
Joachim Nilsson cd791afea5 Revert "dbus: Use --syslog-only instead of Finit built-in log redirect"
This reverts commit df89cc79b9.  Not all
distros (Debian, Alpine) have a dbus-daemon that supports --syslog-only

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-03-01 00:22:01 +01:00
Joachim Nilsson 829405f966 watchdog: Do not emit error message if user has no /dev/watchdog
Running Finit on a kernel or system without WDT support built-in should
not trigger an error message from Finit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-26 23:05:24 +01:00
Joachim Nilsson 72526d9e88 Revert #52: don't reload .conf files after run-parts and rc.local
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>
2018-02-26 22:13:02 +01:00
Joachim Nilsson f704eab6d7 Increase debug level when starting a TTY
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-26 22:11:32 +01:00
Joachim Nilsson a50bfc016e Set $SHELL to a sane default value, used by BusyBox
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>
2018-02-26 22:07:31 +01:00
Joachim Nilsson 396c1b491f Document default prio + tag for log redirect option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-17 17:31:16 +01:00
Joachim Nilsson df89cc79b9 dbus: Use --syslog-only instead of Finit built-in log redirect
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-17 17:28:57 +01:00
Joachim Nilsson 3429901d83 dbus: Silence dbus daemon, redirect stdout/stderr to syslog
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-17 17:26:39 +01:00
Joachim Nilsson dedf885b92 Prefer udev to handle /dev if mdev is also available on the system
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>
2018-02-17 16:06:22 +01:00
Joachim Nilsson 93a21197ab Fix artefact bug with missing OS/Finit title in banner
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-17 16:06:22 +01:00
Joachim Nilsson 8a0fffb00d Minor, whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-17 16:06:22 +01:00
Joachim Nilsson 7fdb280712 initctl: Introduce -b[atch] mode for non-interactive use
This patch introduces a new option to initctl; -b, --batch skips
screen_init(), which might otherwise leak ANSI screen resize codes
to the console.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-16 10:06:37 +01:00
Joachim Nilsson 0a643953c0 Merge pull request #99 from westermo/usr/wkz/inetd-timer-crash
Do not try to SIGKILL inetd services, they are not backed by a pid
2018-02-09 14:44:17 +01:00
Tobias Waldekranz fd837a4242 Do not try to SIGKILL inetd services, they are not backed by a pid
As a precaution, services who are being stopped are automatically sent
a SIGKILL after 3 seconds if they refuse to go away willingly.

Unfortunately this backup mechanism was also enabled for inetd
services which are not backed by a real process. When the service was
freed the timer was not stopped, since it was not expected to be
armed. The timer would then trigger, causing a use-after-free on the
timer watcher containing a bogus callback pointer.
2018-02-09 14:11:48 +01:00
Joachim Nilsson 2759992dd2 contrib/: Fix parallell build, mkdir -p *all* the things
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-02-06 17:30:33 +01:00
Joachim Nilsson d880cd75ae Update TODO, add uredir to list of features for v3.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-30 20:32:26 +01:00
Joachim Nilsson 29fe8cc73d Move run/tasks to stopping state when they exit, like services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-29 18:40:41 +01:00
Joachim Nilsson 2b6f00f126 Minor, whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-27 17:53:23 +01:00
Joachim Nilsson 86e534095d Always check svc_t pointer before dereferencing it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-26 12:47:45 +01:00
Joachim Nilsson 865a3a7a4a Regression, unblock (UDP) parent for terminating inetd connections
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-26 12:46:15 +01:00
Joachim Nilsson 2dc7de3aa2 Make sure to unblock inetd UDP svc when connection terminates
When an UDP inetd connection terminates we must make sure to unblock the
parent, which is (currently) blocked during the transaction.

This patch is a fix to a regression introduced in 2c904b5, for v3.1

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-25 19:14:59 +01:00
Joachim Nilsson 06a5b43005 Outline plans for Finit 3.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 18:28:28 +01:00
Joachim Nilsson 38939cc57e Travis-CI: Add static + disabled inetd build step
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 15:59:42 +01:00
Joachim Nilsson a3eadb72a7 Fix #98, handle --disable-inetd case in service_unregister()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 15:48:41 +01:00
Joachim Nilsson 6d41725387 Bump version for v3.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 14:51:55 +01:00
Joachim Nilsson ceb91f746c Revert "Disable clang build during Coverity Scan run"
This reverts commit 22a69d8cca.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 14:45:24 +01:00
Joachim Nilsson a8802ab0d2 Mention Void Linux tutorial in README, change to bullet list
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 14:31:03 +01:00
Joachim Nilsson ad98f69560 Ignore return value from rename(), ofile may not exist yet.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 14:03:07 +01:00
Joachim Nilsson 5953090688 Document some relevant cmdline options
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 13:45:22 +01:00
Joachim Nilsson 22a69d8cca Disable clang build during Coverity Scan run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 11:45:55 +01:00
Joachim Nilsson 710a3d2c8f Fix Coverity warning, array cannot be NULL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 11:45:15 +01:00
Joachim Nilsson 658fb9b037 Check return value from rename(), fall back to truncate() on error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 11:39:50 +01:00
Joachim Nilsson a84bb9042f Update and add ignore for WeOS build system files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 09:51:39 +01:00
Joachim Nilsson eeb13dba74 Toggle silent mode (progress) when toggling debug mode
Starting in debug mode and disabling debug at runtime did not exhibit
the same behavior as if starting in normal mode and toggling debug mode
at runtime.  This patch adds toggling of silent mode (progress output)
to runtime debug toggling.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 09:44:44 +01:00
Joachim Nilsson 3d20237959 Follow-up to f858d94, only reinitialize screen when toggling debug mode
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>
2018-01-23 09:33:24 +01:00
Joachim Nilsson ddf1bce642 Add screen_exit() fn to restore screen defaults in debug mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 09:31:44 +01:00
Joachim Nilsson 93cd4116db Update ChangeLog and prepare for v3.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 01:21:37 +01:00
Joachim Nilsson 1df6a91a94 Document sufficiently complex, yet deceptively simple, function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 00:44:40 +01:00
Joachim Nilsson c64a71ff30 Follow-up to ba2ab4b, crashing services may not have a PID rn
- Don't warn of missing PID, even if only _d(), perfectly normal
- Allow stopping restart timer of non-services (e.g. task/run)
- Allow stopping services with no PID rn, i.e. stop libuEv timer

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-23 00:17:02 +01:00
Joachim Nilsson b2b6fd25d8 Relocate service helper script to contrib/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 22:28:18 +01:00
Joachim Nilsson 3ca548b681 Add list of major contributors, from Westermo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 21:31:05 +01:00
Joachim Nilsson ba2ab4b446 Follow-up to 2683049, only stop running, non-inet, services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 20:52:37 +01:00
Joachim Nilsson a8183b0559 Check if symlink exists before trying to create symlink
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 20:45:05 +01:00
Joachim Nilsson 227e4fa097 Create destination contrib/*/finit.d dir if missing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 19:03:06 +01:00
Joachim Nilsson 3d68ebbf54 Fix off-by-one in condition reassert()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 15:24:11 +01:00
Joachim Nilsson 6e017025aa Fix bad string pointer arithmetic in condition reassert
On `initctl reload` we reassert conditions, i.e. bring each still viable
condition back in sync with the new reconf generation.  This patch fixes
an assumption in the reassert() callback that caused the following nasty
transformation:

	/run/finit/cond/net/lo/up --> /run/finit/cond/lo/up

The transformation was caused by the reassert() code assuming a /var/run
prefix rather than /run.  We must check the actual runpath, or like this
patch does, use a path neutral way to find the base condition string.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 15:17:07 +01:00
Joachim Nilsson 5f818f917e cond_init(): Create correct condition path, /var/run might not exist
The cond_init() function is called before the bootmisc.so plugin has
run.  It is responsble for setting up the /var/run symlink to /run on
systems with the new layout.  Therefore we must wrap COND_PATH with
pid_runpath() to create the correct runtime path.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 15:17:07 +01:00
Joachim Nilsson 0da1deb487 Add docs/*.md to distribution
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 09:02:19 +01:00
Joachim Nilsson 0337985422 Ignore generated files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 09:02:19 +01:00
Joachim Nilsson f59d41cdec Add silly process monitor script to distribution.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 09:02:18 +01:00
Joachim Nilsson 1cc998eb60 Distribute and install contrib/ directory with all examples
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 09:01:58 +01:00
Joachim Nilsson 8c1d84305d Minor, refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-22 08:38:52 +01:00
Joachim Nilsson 7e4e5127c7 Preserve Markdown links on installed .md files in docs/ sub-directory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-21 10:22:25 +01:00
Joachim Nilsson 3b813bca68 Ignore generated files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-20 20:48:26 +01:00
Joachim Nilsson a1f210bc70 Distribute and install relevant docs/*.md
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-20 20:47:33 +01:00
Joachim Nilsson 0ecf46d7a9 Prefer _exit() over exit() in forked service handlers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 16:35:15 +01:00
Joachim Nilsson 268304927d Fix segfault, stop a crashing service before deleting it
Finit tries to restart crashing services.  If a service is removed
before Finit has given up restarting it, then the background timer
responsible the restart may dereference a free():d svc_t.

Hence, make sure to properly stop (and step) a service and its timer
callbacks in service_unregister() before calling svc_del().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 16:27:25 +01:00
Joachim Nilsson fa02b59db5 Refactor, set STOPPING state in service_stop()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 16:24:39 +01:00
Joachim Nilsson 2c904b5b44 service_unregister(): Also call inetd_del() for inetd services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 16:07:22 +01:00
Joachim Nilsson 4191abc79f service_timeout_cb(): Check callback pointer before calling it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 16:07:22 +01:00
Joachim Nilsson abb928f60b service_stop(): Also stop any pending restart timers
In service_stop() we call svc_del() which, as of Finit v3.1, free():s
the svc_t, so we don't want any lingering restart timers to wake up
after free() and start dereferencing the svc_t.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 16:07:22 +01:00
Joachim Nilsson 3c52118a8e svc_clean_dynamic(): Fix access after free()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-19 13:20:25 +01:00
Joachim Nilsson 5354a57313 plugin_unregister(): Stop I/O watcher before free():ing watcher
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-18 18:35:18 +01:00
Joachim Nilsson 92b1d882e5 do_kill(): Also skip gdbserver from being killed
To improve debug possibilities at shutdown, keep gdbserver running even
during shutdown.

Note: The gdbserver service runlevels must be sth like [123456789] for
      this to work in the first place.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-18 18:21:37 +01:00
Joachim Nilsson fd7a6c5020 cond.c: Normalize COND_PATH, some systems have /run not /var/run
On most modern Linux systems /run is a tmpfs that replaces /var/run.
The latter is set up as a symlink to /run by the bootmisc.so plugin.

However, Finit conditions rely on the /var/run/finit/cond prefix, which
does not exist until bootmisc.so has run, which is *after* `mount -a`
has run.  Therefore, to have working conditions before we run `mount -a`
we must normalize the path constructed by cond_path() to use either the
/run or /var/run (default) prefix.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-18 14:44:25 +01:00
Joachim Nilsson a61551d15f pid.c: Relocate pid_runpath() to a static inline fn
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-18 14:44:00 +01:00
Joachim Nilsson 7f62a69f74 New hook/mount/post, runs after mount -a but before hook/mount/all
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>
2018-01-18 13:34:28 +01:00
Joachim Nilsson c969bda62d bootmisc.so: Create /etc/mtab symlink if missing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-18 13:34:28 +01:00
Joachim Nilsson af41fcd35e api_exit(): Must stop libuEv watcher before closing descriptor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-18 13:34:28 +01:00
Joachim Nilsson 84e9569be6 initctl: Adjust field widths in show/status
The job:id field can now be used to display job:INET_PORT_NUMBER, e.g.
100:16161 for job 100 localhost SNMP port 16161.

The service name field has been reduced from 20 --> 16 bytes since the
full path has been reduced to display the basename.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-17 18:42:24 +01:00
Joachim Nilsson a4ece0fe3f Add log rotate, log, condition and non-SIGHUP example .conf sample
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 17:41:03 +01:00
Joachim Nilsson b2f66da1f9 Cleanup TODO, last item turned out to be bogus
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 17:06:55 +01:00
Joachim Nilsson abbc0a1d5c Fix Ctrl-C, and signals in general, on "logins" in nologin mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 16:25:11 +01:00
Joachim Nilsson 37e420bd35 Minor, itemize example files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 16:03:36 +01:00
Joachim Nilsson d72eb45d6e Refactor, simplify text and rename section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 16:02:06 +01:00
Joachim Nilsson 30c593f64e Minor, reorder debug messages to not mess up progress text
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 14:55:57 +01:00
Joachim Nilsson f858d94d2a Reinitialize screen at shutdown and when in debug mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 14:47:14 +01:00
Joachim Nilsson 992bab2f8f Allow empty -- run/task/service descriptions => no progress
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 14:38:55 +01:00
Joachim Nilsson 72c9681ffb Change debug messages to use svc->cmd rather than empty svc->desc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 14:15:49 +01:00
Joachim Nilsson e439b79e82 Refactor, only show process progress if -- Description is set
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 14:15:10 +01:00
Joachim Nilsson 36e001d636 Refactor, rindex() --> strrchr(), LEGACY as of POSIX.1-2001
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 14:13:48 +01:00
Joachim Nilsson 75aa14466f Allow disabling log rotation, log size:0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 07:50:52 +01:00
Joachim Nilsson 7f899b7a91 Clarify size:200k and count:5 global log rotation options
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 07:46:27 +01:00
Joachim Nilsson 1c177fd953 TODO before v3.1 GA release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-16 07:41:20 +01:00
Joachim Nilsson 617ec7c147 Document global log rotation setting log size:200k count:5
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 19:42:33 +01:00
Joachim Nilsson 192d3aafe7 Add support for global logfile max size and max num. rotated
# Max file size for each log file: 100 kiB, rotate max 4 copies:
    # log => log.1 => log.2.gz => log.3.gz => log.4.gz
    log size=100k count=4

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 19:42:33 +01:00
Joachim Nilsson f11ebb0046 New function, strtobytes(), allows k/M/G ISO size modifiers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 19:42:33 +01:00
Joachim Nilsson b5e260b9e0 Minor refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 18:30:41 +01:00
Joachim Nilsson 45c10edad6 Fix static build, libplug.la is now in ../plugins/, not plugins/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 16:05:39 +01:00
Joachim Nilsson b60d8ce4b6 Fix bootstrap ordering problem, inotify watchers *after* HOOK_BASEFS_UP
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>
2018-01-15 15:23:25 +01:00
Joachim Nilsson d35a8bbda9 Fix problem building external plugins
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>
2018-01-15 15:07:24 +01:00
Joachim Nilsson c616270ccb Bump version for v3.1-rc2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 12:19:51 +01:00
Joachim Nilsson 890ac2f4e1 Update ChangeLog for upcoming v3.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 12:19:51 +01:00
Joachim Nilsson 8063b1bfe1 Include rescue.conf in distribution
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 12:19:51 +01:00
Joachim Nilsson 0bcfb464ce make release: Call distcheck target verify build from tarball
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 12:19:51 +01:00
Joachim Nilsson dc5b1a5980 Increase size of intermediate buffers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 12:19:51 +01:00
Joachim Nilsson 14555d7a7b configure: Fix misspelled --enable-redirect option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 10:17:50 +01:00
Joachim Nilsson a06127b990 Document new log:... option to task/run/services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 10:10:20 +01:00
Joachim Nilsson 3b8e7d677f rlimit can be set globally or locally depending on .conf file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 10:06:19 +01:00
Joachim Nilsson 097fce4170 Ignore logit binary
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 10:03:12 +01:00
Joachim Nilsson 306bf0f191 Add support for configurable redirect to /dev/null, issue #21
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 07:44:33 +01:00
Joachim Nilsson f25390004b Add support for redirecting output to a file using logit, issue #21
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 07:44:33 +01:00
Joachim Nilsson cbd4cc8d34 Extend .conf syntax for 'log' option, issue #21
This is the first patch in a series to add support for

    log:/path/to/logfile,priority:facility.level,tag:ident

In this patch support for 'priority:' and 'tag:', log file support
coming later.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 07:44:33 +01:00
Joachim Nilsson 44591c6e51 logit: Sync each log entry to file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 07:44:33 +01:00
Joachim Nilsson 0e51a1eed8 logit: Hard code program name and clarify distribution scope
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 06:58:44 +01:00
Joachim Nilsson c315fb5637 Add logit v1.0 to Finit distribution
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-15 06:58:44 +01:00
Joachim Nilsson 1017e7b8e5 Disable conditions for some non-oneshot (runtime) hooks
The SVC_RECONF, SVC_LOST, SVC_START, and RUNLEVEL_CHANGE hooks are not
one-shot, they are also not regular conditions since there exist no
mechanism to reset them from flux.

One idea was to turn them into actions, but the lost + start hooks need
to be called multiple times per trigger, e.g. `initctl reload`, which
turned out to be non-trivial to implement right now.

Therefore, for (at least) the Finit v3.1 release these conditions have
been disabled ("nop") and ignored by Finit.  Only actual C-style plugins
will be called.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-14 11:24:29 +01:00
Joachim Nilsson 8ef216af62 Let hook conditions be oneshot, prevents flux on reload
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-14 11:24:29 +01:00
Joachim Nilsson a9b9631098 Minor, reduce debug noise from plugin recursion
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-14 11:24:29 +01:00
Joachim Nilsson cc186334e0 Add support for one-shot conditions, like most hooks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-14 11:24:29 +01:00
Joachim Nilsson e1b87d707f Support touching custom PID files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-13 22:03:17 +01:00
Joachim Nilsson 68e7bcba4c Refactor and document pid_file_parse()
This patch cleans up the implmentation, adds documentation and also
makes sure to adjust the prefix path of a pid:/prefix/path argument.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-13 21:52:06 +01:00
Joachim Nilsson f9783b4b41 pidfile: Use realpath() to figure out of _PATH_VARRUN is a symlink
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-13 21:49:18 +01:00
Joachim Nilsson 32d9afc7bb Use pid_runpath() in svc_find_by_pidfile(), used by pidfile plugin
The pidfile plugin just listens to changes in files in /run or /var/run,
so when trying to locate an svc_t from a file change we need to compare
using the proper prefix path.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-13 21:47:11 +01:00
Joachim Nilsson 91b550662e New function, pid_runpath(), figures out /var/run or /run prefix
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-13 21:42:13 +01:00
Joachim Nilsson d87af8270e docs/config.md: Document new pid:/optional/file.pid argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-12 21:09:55 +01:00
Joachim Nilsson 366c23f5d1 TODO: Remember to handle PID files in subdirectories to /run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-12 21:07:15 +01:00
Joachim Nilsson 0d4bc69584 pidfile: Use new svc_find_by_pidfile() in plugin
A service may now have a custom PID file, possibly because it doesn't
really create one itself.  This needs to be taken into account also in
the pidfile plugin.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-11 10:50:19 +01:00
Joachim Nilsson cccf199280 New function, svc_find_by_pidfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-11 10:49:58 +01:00
Joachim Nilsson a1c33dec21 Refactor, move all PID file related functions to the same module
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-11 10:48:17 +01:00
Joachim Nilsson df303c6243 Nota bene, changing name of PID file of running process
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-11 09:05:24 +01:00
Joachim Nilsson 6a6ae6fa3b Fix #95: Create PID file if program does not
This patch adds support for creating, and removing, a PID file for
programs (services) that for some reason does not create one.  With
Finit this is very useful since it allows us to use our condition
support even for "broken" daemons.

To enable this for a service, use the following syntax:

    service pid[:[/path/to/]file[.pid]] /path/to/daemon

I.e., `pid` is a required argument if you want to enable the feature,
but the rest is optional:

    pid             --> /run/`basename $CMD`.pid
    pid:file        --> /run/file.pid
    pid:file.dip    --> /run/file.dip
    pid:/mnt/k      --> /mnt/k.pid
    pid:/mnt/k.foo  --> /mnt/k.foo

There is an additional feature with this patch.  For daemons that run
with a different identiy one usually wants to create the PID file with
that identity, e.g.:

    service inadyn -I dyn     -- Dyn.com DDNS client
    service inadyn -I freedns -- FreeDNS DDNS client

Here inadyn will look for /etc/dyn.conf and create /run/dyn.pid, and
/etc/freedns.conf and create /run/freedns.pid, respetively.  While Finit
will in both cases assume the PID file is /run/inadyn.pid ... err fail!

To get out of this mess the `pid` argument can be used to tell Finit
what the real PID file the daemon creates is called:

    service pid:!dyn     inadyn -I dyn     -- Dyn.com DDNS client
    service pid:!freedns inadyn -I freedns -- FreeDNS DDNS client

The same composition rules listed above applies also to the `!` variant.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-10 23:27:05 +01:00
Joachim Nilsson 4011b5a3b8 Relocate all docs from doc/* to docs/*, integrates better w/ GitHub
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-10 02:28:33 +01:00
Joachim Nilsson 68ef6ec108 Fix v3.1 regression, segfault when inetd service connection exits
The service_step() function may call svc_del() on an svc from the
service_monitor(), so we need a way to tell the latter that it no
longer can dereference the pointer.

This regression is limited to v3.1, due to the introduction of the
new non-shared-memory store of svc_t.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-10 02:10:14 +01:00
Joachim Nilsson 89a9d92d6c Refactor construction of inetd service connection description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-10 01:41:14 +01:00
Joachim Nilsson 15cb576293 Fix v3.1 regression in start of inetd services, missing rlimit
Per service rlimit is new in v3.1.  When an inetd service connection is
created we do a selective copy from the parent inetd.  We also need to
copy the parent's rlimits, otherwise the child will be killed as soon
as the kernel starts it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-10 01:36:24 +01:00
Joachim Nilsson 90734eee16 reboot: Reboot via Finit + watchdogd may take a while
This patch increases the default wait, 2 --> 5 sec, while pending for
Finit + watchdogd controlled reboot/shutdown.  We don't want to hand
back the prompt when we're not really ready yet.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-04 11:20:08 +01:00
Joachim Nilsson 71915e0e14 Make sure log_exit() restores progress output on shutdown/reboot
This patch builds on top of the recently introduced "silent by default"
and support for kernel cmdline `splash` to disable silent operation.

At shutdown/reboot `log_exit()` is called, the intention is to re-enable
progress output so the user can see what's going on.  So, we need to re-
set `silent` to the same setting as log_init() started with, hence the
new `muffler()`.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-04 11:16:58 +01:00
Joachim Nilsson 112ab2c22f initctl: Refactor, use struct command rather than command_t
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-04 11:15:55 +01:00
Joachim Nilsson 8f00ac2e90 Do *not* redirect stdout/stderr of services by default
Automatic redirection of output was introduced in v3.0 and for the
upcoming v3.1 a configure option was added to disable it.

By popular demand this patch flips the default.  One now has to
explicitly enable this feature to get redirection.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2018-01-04 11:12:59 +01:00
Joachim Nilsson 6fb070c75c TODO: Update and remove recently fixed items \o/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 18:31:02 +01:00
Joachim Nilsson 8fd431f3e9 initctl: Show uptime of running services in show <NAME> output
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 18:30:08 +01:00
Joachim Nilsson 50f128cd1d Track service start time using new jiffies() function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 18:29:43 +01:00
Joachim Nilsson f6fa576270 New functions: jiffies() and uptime(), implemented with sysinfo()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 18:28:29 +01:00
Joachim Nilsson b26d30757d Document new initctl status <JOB|NAME> command
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 17:11:15 +01:00
Joachim Nilsson dc9d0b6fca Add service wrapper script, sometimes more convenient to use
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 17:08:35 +01:00
Joachim Nilsson ff95ca92b1 Update cron syntax proposal: @hourly, @daily, @weekly, @reboot, etc.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 16:52:09 +01:00
Joachim Nilsson c939aed87f Add net/IFNAME/running to list of supported conditions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 15:01:11 +01:00
Joachim Nilsson 71ea9e2ea3 Support for restarting initctl API socket on SIGHUP
This patch adds support for restarting the API socket on SIGHUP, similar
to how SysV init and systemd use SIGUSR1 to restart their FIFO or D-Bus.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 13:28:27 +01:00
Joachim Nilsson b6bd10d960 Follow-up to c1344e8, never shutdown() API socket, or segfault
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 13:27:25 +01:00
Joachim Nilsson 87d8157175 fixup! netlink.so: Add support for IFF_RUNNING => net/IFNAME/running
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 13:26:58 +01:00
Joachim Nilsson cf6faa9eeb netlink.so: Refactor, break out condition set/clear func.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 12:41:27 +01:00
Joachim Nilsson 80a71aff07 netlink.so. Refactor (simplify) and fix problem with loss of events
An interface may come up with IFF_RUNNING already set, but we would
only detect IFF_UP.  This patch simplfies the code a lot by pivoting
the qualifier from using ifi_change to ifi_flags, which is the actual
current status of an interface.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 12:25:50 +01:00
Joachim Nilsson 04a4653e9b netlink.so: Add support for IFF_RUNNING => net/IFNAME/running
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-31 12:07:47 +01:00
Joachim Nilsson 3aa9d9f451 README: Document how to re-enable progress with configure or splash
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 22:10:10 +01:00
Joachim Nilsson c1afca9c33 README: Clarify that runparts runs *before* networking is up
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 22:01:56 +01:00
Joachim Nilsson 205915d42f Document new rescue (recovery) mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:58:26 +01:00
Joachim Nilsson 631f89b58c conf_parse_cmdline(): Relax check for 'debug' flag
Relax check for 'debug' flag, we want to catch '--debug' and 'finit_debug'

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:57:36 +01:00
Joachim Nilsson 6d1c245985 Update documentation, debug replaces --debug and finit_debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:56:24 +01:00
Joachim Nilsson fc08b0c65b README: Clarify runlevel section a bit, new 'single' user mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:46:03 +01:00
Joachim Nilsson 83021b11d8 No need to take down network if it's already down (at boot)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:33:45 +01:00
Joachim Nilsson 5309ece2f9 Add support for splash progress mode from kernel cmdline
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:28:30 +01:00
Joachim Nilsson 6480850ee2 Enforce *no networking* in single-user mode, runlevel 1
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>
2017-12-30 21:20:06 +01:00
Joachim Nilsson eaa82377c4 Add support for single (S) user mode from kernel cmdline
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson 5b3df3654c conf_parse_cmdline(): Use strict string comparison
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson 55cb50ef90 In rescue mode, always set hostname from /lib/finit/rescue.conf
If hostname is missing from /lib/finit/rescue.conf the system will
default to the configured default hostname (noname).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson 3f7e03e813 Refactor, re-order a bit so screen_init() doesn't run in rescue mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson ab723d2f31 Add support for a rescue (recovery) mode from kernel cmdline
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>
2017-12-30 21:20:06 +01:00
Joachim Nilsson bc149d95fc conf: Add hostname alias to host
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson c605874b26 Remove --with-plugindir=DIR, use --prefix or --libdir instead
The /lib/finit/plugins path is as of this patch not longer possible to
change.  Use --prefix or --libdir instead to change the leading path.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson c33ba6a477 Remove reboot symlinks properly on uninstall
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson 63199d368f conf: lim2str(): Fix buffer overflow in local debug function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:20:06 +01:00
Joachim Nilsson db3263c441 Refactor conf_parse_cmdline(), support 'debug' as well as '--debug'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 21:19:55 +01:00
Joachim Nilsson 925212f7cf Merge pull request #94 from joerg-krause/patch-1
doc/config.md: Add entry about using wrapper scripts to execute pre commands
2017-12-30 21:03:03 +01:00
Jörg Krause ad401280c2 doc/config.md: Add entry about using wrapper scripts to execute pre commands
See: https://github.com/troglobit/finit/issues/93
2017-12-30 17:55:12 +01:00
Joachim Nilsson f3d2586417 Fix build warning on musl libc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 13:12:05 +01:00
Joachim Nilsson 6fc1d27bcf conf: Check if a kernel module has been loaded first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 13:09:34 +01:00
Joachim Nilsson f3305e75b7 conf_reload(): Exit properly, even if no /etc/finit.d/*.conf exitsts
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-30 12:47:27 +01:00
Joachim Nilsson e4c12314b1 doc/config.md: Mention /etc/finit.d/available/ and initctl enable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 21:00:46 +01:00
Joachim Nilsson c9a1a64ce5 doc/config.md: Update with changes to finit.conf and stanza limits
Finit v3.1 adds support for reloading /etc/finit.conf, document what
actually is read at runtime, compared to at bootstrap, and clarify
which stanzas are for what part of the boot process.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 20:52:43 +01:00
Joachim Nilsson 3843f62aa8 README.md: Update with difference between runparts & /etc/rc.local
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 20:51:42 +01:00
Joachim Nilsson ef54c4826b bootstrap.md: runparts goes before the runlevel change
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 20:51:14 +01:00
Joachim Nilsson 2fac65becb Fix long-standing bug, runparts() should run before runlevel change
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>
2017-12-29 20:48:47 +01:00
Joachim Nilsson 46b253dea6 doc: The module configuration stanza supports optional args
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 20:15:29 +01:00
Joachim Nilsson b04983c3f3 conf: Make rlimit [hard|soft] optional => possible to set both
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 20:15:12 +01:00
Joachim Nilsson f2d142ef57 Only reload .conf and services if any .conf file has changed
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>
2017-12-29 19:22:01 +01:00
Joachim Nilsson 33ce746e58 parse_conf(): Increase log with actual limits in case of problems.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 16:57:36 +01:00
Joachim Nilsson 6ecb86b4a7 conf_reload(): No need to reload global rlimits again
This patch removes duplicate reload of global_rlimit[], which
parse_conf() already has done.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-29 16:56:30 +01:00
Joachim Nilsson 338810b886 Fix #92: Load .conf files and initialize global_rlimit[] earlier
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>
2017-12-29 16:51:49 +01:00
Joachim Nilsson c1344e89ff api_exit(): Only shutdown() of API socket at runtime
Not needed at shutdown/reboot.  Also, it may segfault at that stage.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-28 20:48:44 +01:00
Joachim Nilsson bc35b42bd2 inet_stop(): Check argument and skip shutdown(), just close() socket
- Validate function argument
- Skip¹ shutdown() when closing a TCP socket, not needed

___
¹ also, shutdown() segfaults a late shutdown/reboot

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-28 20:46:19 +01:00
Joachim Nilsson dcf8fbe235 do_shutdown(): Advise watchdog using SIGPWR, system is going down
On shutdown/reboot, send SIGPR as a heads-up to watchdogd that the
system is going down.  All file systems are about to be unmounted.
It's just about the last process left running in the system, so we
give it two seconds to complete its work before we continue.

When everything has been unmounted and we're ready to call reboot(),
we send SIGTERM to the registered watchdog, to give ti the chance to
let the WDT reset the system.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-28 20:45:02 +01:00
Joachim Nilsson c82a2ce215 Built-in watchdog: on SIGPWR, exit main loop and prepare for SIGTERM
When Finit enters shutdown/reboot we need to advise any watchdogd that
we are going down *before* we unmount any file systems.  This to let
the user save any state, e.g. reboot counters, to disk.  Right before
we call reboot() in Finit we send SIGTERM to the watchdogd to give it
the chance to use the WDT to reboot the system.

The WDT cricuitry on embedded systems is often connected to the RESETn
logic of all relevant board compoents, whereas reboot() only reboots the
SoC with the CPU.  Hence, a WDT reboot is more efficient and more like a
regular power cycle, which users of embedded systems often want.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-28 20:24:32 +01:00
Joachim Nilsson e1bb5e3396 Add --disable-redirect-output to configure script
This patch makes it possible to control the default redirection of
(misbehaving) services output to /dev/null.  With this disabled,
a service may write to its stdout/stderr and mess up the console.

By default all service/run/tasks stdout/stderr is redirected.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-28 20:22:06 +01:00
Joachim Nilsson 8198582c10 Revert "Travis-CI: Disable clang temporarily, for Coverity Scan run"
This reverts commit cbafbaea1d.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 11:01:24 +01:00
Joachim Nilsson 0d19842aa1 conf_changed(): Fix possible NULL ptr deref, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 10:35:07 +01:00
Joachim Nilsson 6f665ab283 inet_dgram_drop(): Fix control flow logic, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 10:31:19 +01:00
Joachim Nilsson 3f731aa5a3 inet_dgram_drop(): Check return value from recv()
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 10:28:22 +01:00
Joachim Nilsson 9e8a01669e api: Fix possible descriptor leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 10:02:49 +01:00
Joachim Nilsson cbafbaea1d Travis-CI: Disable clang temporarily, for Coverity Scan run
... so we don't lose tokens ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 09:53:14 +01:00
Joachim Nilsson f534368b33 The @console and nologin flags deserve mentioning early
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 09:51:16 +01:00
Joachim Nilsson 78fc9fccc5 Update initctl usage text
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 09:51:04 +01:00
Joachim Nilsson 3f7df3d35e Update ChangeLog with new nologin option to tty configs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 03:29:38 +01:00
Joachim Nilsson 9fc33418f9 Document nologin option flag to tty configuration directive
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 03:26:31 +01:00
Joachim Nilsson 72bc3b1a91 Fix #91: Add support for tty nologin, to start /bin/sh immediately
This patch adds a `nologin` flag to the `tty` configuration directive,
making it possible to set up really simple embedded systems with no
login.

Example, put the following line in `/etc/finit.d/getty.conf` to get
a "Please press Enter to ..." prompt before being presented with a
root shell prompt.

    tty [12345] @console noclear nologin

Needless to say, this is not very secure, but can be really useful
for developer setups, during board bringup, or similar.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-24 01:54:07 +01:00
Joachim Nilsson d6ea1c0cab Protect internal services like dbus-daemon and udevd
In f3669c7 the difference between static and dynamic services was
removed.  This led to a regression in handling internally created
services for, e.g., dbus-daemon and udevd, mentioned in issue #90.

This patch introduces a "protected" flag for svc_t to prevent the
mark-and-sweep handling of regularly loaded services.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 21:57:31 +01:00
Joachim Nilsson 523a270f22 Update README slightly, there's systemd-udevd and eudev these days
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 19:33:27 +01:00
Joachim Nilsson 3258edc246 Fix #90: Restore tmpfs mount of /dev/shm, removed in d7401b2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 19:02:06 +01:00
Joachim Nilsson 32b7a14cb3 Add ismnt() helper function, wrap fismnt()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 19:00:41 +01:00
Joachim Nilsson 55479cc511 Bump version for first -rc, v3.1-rc1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 11:52:40 +01:00
Joachim Nilsson b702f7eeef Update ChangeLog for upcoming v3.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 11:52:40 +01:00
Joachim Nilsson 0e37bb0924 Follow-up to b0663d0, cond_init() must run before first hooks
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>
2017-12-23 11:19:35 +01:00
Joachim Nilsson 360f3e72bc Audit b0663d0, add newline to generation ID in cond files
- Add newline to cond generation ID, like PID files, easier when
  debugging.  Does not affect fscanf() in cond_get_gen()
- Update copyright years

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 10:05:45 +01:00
Joachim Nilsson c1023c03c7 Merge pull request #89 from westermo/cond-generation
Cond generation
2017-12-23 09:37:16 +01:00
Joachim Nilsson e94d2a8c08 Merge branch 'master' into cond-generation 2017-12-23 09:31:41 +01:00
Joachim Nilsson f7c0366fa2 Fix segfault on X86_64, call va_end()+va_start() for each vfprintf()
... varargs is a special kind of hell.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-23 00:38:01 +01:00
Joachim Nilsson 8992e7bf2b Refactor svc_iterator() into a proper iterator, add first flag
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 23:56:14 +01:00
Joachim Nilsson 95518df62d Some systems rely on /dev/shm being there for mount -a
This was accidentally removed in d7401b2, when svc_t was refactored
from using shared memory.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 16:44:52 +01:00
Joachim Nilsson 85fe95835a doc/build.md: Mention required library versions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 13:17:39 +01:00
Joachim Nilsson baf9c4f61f Travis-CI: Update build deps, libite v1.9.2 --> v2.0.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 13:12:04 +01:00
Joachim Nilsson b439ac670d .conf: don't rely on mtime to determine if service needs reloading
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>
2017-12-22 13:08:38 +01:00
Joachim Nilsson bb3d9c8670 initctl: Add support for touch <CONF>, mark .conf for reload
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:50:18 +01:00
Joachim Nilsson 2f9b97b3a7 Update libite (-lite) requried version: 1.9.2 --> 2.0.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:49:04 +01:00
Joachim Nilsson c59f7d23f4 Add and improve debug messages, clean out old dev. comments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-22 12:40:43 +01:00
Tobias Waldekranz b0663d04e4 cond: don't rely on mtime for condition management
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.
2017-12-21 11:10:47 +01:00
Joachim Nilsson 6f26f2f9d0 TODO: Idea about addding support for an optional rescue mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:30:49 +01:00
Joachim Nilsson e7cca05fe3 Reserve certain configuration directives for bootstrap only
The following configuration directives, previously only allowed
in /etc/finit.conf, are now also only allowed in runlevel S, i.e.
at bootstrap:

- host
- mknod
- network
- runparts
- runlevel

This change is in preparation for allowing reload of finit.conf
as well as /etc/finit.d/*.conf, which we already support.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:16:55 +01:00
Joachim Nilsson f3669c7537 svc: Remove svc_dynamic_iterator(), soon no difference between svc's
This is a prelude to a major behavioral change.  The difference between
a static and dynamic service will be removed in Finit v3.1.  This means
all .conf files, including /etc/finit.conf, will be re-read on reload.

However, not all configuration directives will be re-read, some will
only be applicable at bootstrap, i.e. runlevel S.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:04:14 +01:00
Joachim Nilsson a9456cec41 svc: Remove unused function, svc_foreach_dynamic()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 09:02:38 +01:00
Joachim Nilsson 61a9926442 Minor, staticify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-20 00:13:21 +01:00
Joachim Nilsson 7784480abe Postpone networking stuff, + hooks, a bit to the finalize() step
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>
2017-12-20 00:10:29 +01:00
Joachim Nilsson db50c09ec5 initctl: Improve show SVC command output a bit, provide summary
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 21:04:17 +01:00
Joachim Nilsson 0f1f51b5ad Refactor, change from static array of svc_t to linked list
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 17:50:02 +01:00
Joachim Nilsson d7401b2a96 Follow-up to issue #81: remove SysV shared memory IPC altogether
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>
2017-12-18 11:20:21 +01:00
Joachim Nilsson c0515d112e New client side API to access svc_t entries without shared memory
This change is one of the required intermediate steps to remove the
shared memory store for all svc_t, this in turn to avoid any external
programs manipulating the internal memory of PID 1.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 11:06:19 +01:00
Joachim Nilsson 9a8b55737f Move svc_status() + svc_dirtystr() to header file as static inline
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 11:03:15 +01:00
Joachim Nilsson d7d8b8487d Refactor other iterators to use new re-entrant svc_iterator1() API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 07:49:45 +01:00
Joachim Nilsson 7f04382eee Refactor, use new re-entrant svc_iterator1() API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 00:21:07 +01:00
Joachim Nilsson bf004d9ec4 svc: Re-entrant replacement to svc_iterator() --> svc_iterator1()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 00:18:13 +01:00
Joachim Nilsson 23e0928e5c Minor, unused arguments no longer need magic tricks or hand waving
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-18 00:17:00 +01:00
Joachim Nilsson d6b2ac94dd Fix regression in 32b9096, only pick next :ID for inetd services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 14:54:46 +01:00
Joachim Nilsson 7362e6d00a initctl: Fix error handling for intictl start/stop if missing arg
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 12:12:57 +01:00
Joachim Nilsson d94d11e00a initctl: Allow short forms of commands
For ease of use, allow short forms of commands, like:

   initctl h
   initctl c d
   initctl l

Also, default to show conditions if no argument to cond is given.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 12:09:41 +01:00
Joachim Nilsson f06a0fcb71 initctl: Support printing previous runlevel
This patch adds support for "PREVLEVEL RUNLEVEL" output to the initctl
runlevel command.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-17 10:54:06 +01:00
Joachim Nilsson cae61ad6df initctl refactor, break out domain socket/client API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-16 12:15:28 +01:00
Joachim Nilsson 27e4af5ed8 Rename, client.c --> telinit.c
We need the name client.c for the client side of api.c, so let's rename
the client to its traditional name.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-15 14:00:11 +01:00
Joachim Nilsson f10a724503 Add mention of dropping UDP connections from blocked interfaces
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-14 17:23:54 +01:00
Joachim Nilsson 33037b012a Merge pull request #88 from ccb3/master
Drop UDP packets from unwanted interfaces
2017-12-14 10:44:29 +01:00
Lennart Eriksson 0c75e59b77 Drop UDP packets from unwanted interfaces
Previously UDP packets were never dropped and if a request came
from a not valid interface inetd got stuck in an inifinite
loop looking at the same packet every time and not dropping it.

Signed-off-by: Lennart Eriksson <lennart.eriksson@westermo.se>
2017-12-14 10:34:07 +01:00
Joachim Nilsson 8e55a76732 Initial draft of v3.1 release notes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-14 09:13:13 +01:00
Joachim Nilsson 32b9096e31 Fix #87: Allow inetd services to be registered with an id != 1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 22:20:30 +01:00
Joachim Nilsson f51723e8b7 Fix #86: Ensure that run/tasks are run at least once per runlevel
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>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 9e31bd8a23 Fix #18: Add support for calling run/tasks on HOOK points
This patch implements support for calling run/task jobs on the built-in
`HOOK_*` points in Finit.  To map each HOOK point to a condition a new
classification was made, as shown in plugin.h and in the example below.

task <hook/mount/root> /sbin/attachubi.sh      # run in parallel with other tasks/services
run  <hook/net/up>     /sbin/dosomething.sh    # run in sequence with other commands

Please note, only rudimentary tested.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson e841984a4e service_step(): Fix problem with double start of service/run/tasks
Make svc state transition to RUNNING *before* service_start(), because
in that function we may call service_step() as well, which would start
the svc again (since it was still in READY).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 594476c4fc Fix progress print-out ordering bug, and run HOOK_SVC_START only on success
Only run HOOK_SVC_START on successful start, and *after* having printed
the result of the started service, otherwise any print-outs from plugins
or tasks we start may overwrite the started service's progress.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 9c423dfca4 Disable toggling of log/debug in fsck() loop
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>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 77cd0f0243 Fix problem with duplicate log messages before syslogd has started
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 5dc4e7c058 cond_update(): Minor, log service description as well as cmd
If you have lots of service/run/tasks using the same cmd it's impossible
to tell them apart in debug mode.  This patch logs description as well
as cmd to improve on this situation a bit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 3c015f384d Track run/tasks, should run at least once per declared runlevel
This patch adds a 'once' counter to the svc_t for run/task jobs.  This
counter is incremented when Finit calls service_start() and is reset on
runlevel changes.

Also, at the end of a runlevel each run/task have their state reset to
SVC_HALTED_STATE so they can be launched again for the new runlevel, if
so declared.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 5117b723c2 Minor, fix missing rlim2str() declaration
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson b55a609834 Handle /etc overlayfs: reload /etc/finit.d/*.conf after mount -a
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>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 60eccbac31 Refactor, relocate+rename service_enabled() --> svc_enabled()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson b182e6bcc5 Minor update and refactor, use kernel doc style comments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson b8bf26b107 Refactor, rename restart counter and change type to char, MAX=10
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-12-13 17:58:48 +01:00
Joachim Nilsson 14c0d80f63 Merge pull request #85 from reverendhomer/doc-fix-typo
doc: fix couple of typos in config.md
2017-12-01 18:45:20 +01:00
Reverend Homer 1f55f677d1 doc: fix couple of typos in config.md 2017-12-01 20:07:58 +03:00
Joachim Nilsson 40267a5f0f Minor, comment fixes and additions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-28 08:07:06 +01:00
Joachim Nilsson 9f50b033d9 Abort service kill if already terminated, otherwise kill(0, SIGKILL)
This patch fixes a rather nasty bug in the SIGTERM+SIGKILL logic
employed by Finit when stopping tasks, e.g. at a runlevel change.

When a process terminates, after Finit having sent it SIGTERM, and the
SIGKILL timer expires *before* the timer has been cancelled, then the
timer callback would cause kill(0, SIGKILL).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-28 08:00:46 +01:00
Joachim Nilsson bbaa7a1403 TODO: Process callbacks replaced with conditions in Finit 3.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-27 22:37:38 +01:00
Joachim Nilsson b68c5c1291 Fix #45: add support for rlimit per service/run/task/inetd/tty
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>
2017-11-26 16:35:37 +01:00
Joachim Nilsson 44007c86f2 initctl: Fix problem with start/stop using job ID
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-24 08:51:50 +01:00
Joachim Nilsson cd73c1c951 Replace libite:fmode() with stat(), removed in libite v2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-22 14:40:02 +01:00
Joachim Nilsson 5406af2054 watchdog: Adjust WDT timeout (30 sec), use half that as kick period
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:51:33 +01:00
Joachim Nilsson 3c800f6508 Refactor, simplify registration of built-in watchdog daemon
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>
2017-11-19 16:48:32 +01:00
Joachim Nilsson e0fb2b036d Improve debug of initctl api
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:45:07 +01:00
Joachim Nilsson 0ee4657f1c Follow-up to 6c563a2, clean up unused variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 16:39:27 +01:00
Joachim Nilsson ec2382b6d4 Silence, remove "Starting ..." of inetd services from boot progress
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:30:04 +01:00
Joachim Nilsson 0fc2df1a65 Silence, remove "Loading %sconfiguration ..." from boot progress
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>
2017-11-19 12:29:31 +01:00
Joachim Nilsson 6c563a2b22 Silence, remove "Loading plugins ..." from boot progress
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>
2017-11-19 12:27:57 +01:00
Joachim Nilsson 6a2911223d Fix screen_init() regression introduced in a6290da
A simple missing semicolon caused initscr() to not be called properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-19 12:26:45 +01:00
Joachim Nilsson 7f499ed1d0 watchdog: Kick one last time before handover to external watchdogd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-18 14:48:46 +01:00
Joachim Nilsson 2d2807bc65 Change log message for crashing services, remove dev. debug info
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-18 14:48:08 +01:00
Joachim Nilsson 4af7974fb9 Travis-CI: Install new required version of libuEv, v2.1.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:26:12 +01:00
Joachim Nilsson 3fd45eac7c bootmisc: Handle _PATH_VARDB inconsistency gracefully
Some systems use /var/db while others use /var/lib/misc, we need to
support both and cannot rely on _PATH_VARDB, since it too might not
be set properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:24:25 +01:00
Joachim Nilsson bb4578292f Bump version for v3.1 release cycle
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:01:02 +01:00
Joachim Nilsson 656fa3d0e7 Bump required libuEv version to v2.1.0, fixed failure mode support
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:00:36 +01:00
Joachim Nilsson 9a75813350 api.c: Handle domain socket errors more gracefully, restart socket
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 15:00:05 +01:00
Joachim Nilsson 5af1f05606 plugin: Only close() PID file descriptors >0, skip -1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-14 14:34:08 +01:00
Joachim Nilsson fcdb5c2965 initctl: Refactor, reduce code duplication
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 22:58:50 +01:00
Joachim Nilsson af3e560d79 tty.c: Refactor, move LIST_REMOVE() to tty_unregister()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 21:33:22 +01:00
Joachim Nilsson b6e695b656 Bump required libuEv version to v2.0.0, with failure mode support
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 19:40:54 +01:00
Joachim Nilsson 123df18847 Travis-CI: Bump required libuEv version to v2.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 19:40:28 +01:00
Joachim Nilsson dae21d9d64 Simplify rlimit documentation a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 19:18:32 +01:00
Joachim Nilsson bf4a0abe5c conf_parse_rlimit(): Refactor, replace 'new' with 'cfg'
'new' is a reserved keyword in C++, it is recommnded to avoid it also in C.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 14:57:22 +01:00
Joachim Nilsson 6826d7ee3f Handle event loop watcher failure modes
When alibuEv event watcher callback has `UEV_ERROR` in the events mask
we must handle the error.  Unfortunately, in most cases there is not
much we can do but ignore it or log the error.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 11:18:12 +01:00
Joachim Nilsson 168da2a5c6 plugin: Update list of available events for I/O plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 02:47:33 +01:00
Joachim Nilsson c82dc54205 initctl: Minor refactor, handle errors first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-12 02:46:19 +01:00
Joachim Nilsson eb0a759371 TTY: If parsing speed argument fails, do NOT default to B38400
If the speed argument to the `tty` stanza is invalid we should not
default to some other random speed.  Instead, leave the line speed
as-is, like we do when starting an external getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-11-02 10:48:04 +01:00
Joachim Nilsson 830abc1971 getty: Remove leading \n in do_issue(), not needed
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 20:57:36 +01:00
Joachim Nilsson 4c3a11131f Minor cleanup + use strlen() rather than sizeof() on const strings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 20:56:48 +01:00
Joachim Nilsson 796701c854 getty: Ignore SIGINT & C:o earlier
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-31 20:54:56 +01:00
Joachim Nilsson ab760aa3ff Mention @console TTYs in top-level README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 17:21:21 +01:00
Joachim Nilsson 2b9eecbef3 Spell check and mention use of logger tool in service stanza
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 17:17:21 +01:00
Joachim Nilsson b8190c8a2a Refactor, move speed parser from getty() to prepare_tty()
This patch relocates the speed parser so that exec.c can set the TTY
speed properly as soon as possible.  For external getty we make sure
to not touch the TTY speed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 16:53:26 +01:00
Joachim Nilsson adb4670d2f Clear current line before printing \nPlease press Enter ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 16:52:14 +01:00
Joachim Nilsson d31575538c getty: Disable VINTR + VEOF, re-enable before calling /bin/login
This patch makes the Finit built-in getty behave a bit more like other
getty implementations.  We now not only disable ISIG but also VEOF and
VINTR when prearing the TTY for the getty (built-in or external).

Like before, it is up to the getty process to leave the TTY in a
usable state to /bin/login, so we also move the stty() call to
just before calling /bin/login in getty.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 16:11:59 +01:00
Joachim Nilsson faf0c680b8 getty: Disable ECHO, XON/OFF while waiting for initial <CR>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 12:14:04 +01:00
Joachim Nilsson 250e26f2f6 Fix #84: Reset TTY w/ stty() before taking any pre-getty action
This patch moves the stty() function from getty.c to a separate file so
it can be called from exec.c as well.  The fix to #84 is simply to call
stty() in prepare_tty(), which is shared by run_getty() and run_getty2()
and called before "Please press Enter ...".

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-29 11:59:48 +01:00
Joachim Nilsson b45c3d5cb8 timespec_newer(): time a should be > or >= to b
Time comparision should be >= not just >.  May seem a bit silly to
nitpick like this since we're comparing nano seconds, but on systems
with no high-res timers this happens more often than you would like.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 16:04:18 +02:00
Joachim Nilsson 6b2678c2ed pidfile: On HOOK_SVC_RECONF the netlink plugin must run first
When performing an `initctl reload` with one (unchanged) service
depending on, e.g. `net/iface/lo`, its condition will not be set
to ON by the pidfile plugin unless the netlink plugin hook runs
first.

Example:

    service <net/iface/lo> /sbin/dropbear ...

Which provides the <svc/sbin/dropbear> condition, will not be
set by pidfile.so during `initctl reload` because dropbear is
still SIGSTP:ed waiting for <net/iface/lo>.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 15:55:35 +02:00
Joachim Nilsson 0d6f203e0b tty_reload(): When reloading a single TTY dev, remember to clean it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-24 13:48:25 +02:00
Joachim Nilsson 781ba66905 Revert "Remove reconf condition when .conf reload completes"
This reverts commit 06479aa5f1.
2017-10-24 13:07:48 +02:00
Joachim Nilsson 9a97ab29dc Revert "cond_reassert(): Use cond_set_path(), not cond_clear(), for reconf"
This reverts commit afb3fada50.
2017-10-24 13:07:15 +02:00
Joachim Nilsson b2b17ea4fb doc/config.md: Document new tty @console support in finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:30:24 +02:00
Joachim Nilsson bfa99266e7 Minor, cleanup old unused function prototype
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:30:04 +02:00
Joachim Nilsson c76a58ef7a Remove long since deprecated finit.conf: console <DEV> support
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>
2017-10-23 19:28:11 +02:00
Joachim Nilsson 51c5f3cbfa Length of the ANSI escaped runlevels string is 20 chars, need 21
Problem reported by @wkz

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:20:25 +02:00
Joachim Nilsson a6290da210 screen_init(): Verify that STDOUT is a TTY
Before we call screen_init(), which in turn calls libite:initscr(),
which in turn does a lot of tcgetattr() and termios to STDOUT to figure
out the size, we need to check that we're not backgrounded, or don't
actually have a TTY.  Problem reported by @wkz

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 19:16:51 +02:00
Joachim Nilsson 949f02eff4 tty: Add support for auto-detecting serial console from SysFS
This patch adds support for a new TTY device keyword `@console` which
auto-detects the system console by reading the SysFS file:

    /sys/class/tty/console/active

Embedded systems with one of /dev/ttyAMA0, /tty/ttyMXC0 or the original
/dev/ttyS0, as their active serial console can now instead use a single
line to /etc/finit.d/getty.conf to start the built-in getty on the same
TTY as the kernel already runs on:

    tty [12345789] @console 115200 noclear

With no TTY defined Finit will either do nothing (default), or start a
fallback shell if enabled in the configure script.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 17:24:46 +02:00
Joachim Nilsson 7970e45f45 Follow-up to cf60cdd, make sure to disable ISIG before calling getty
Disable INTR, QUIT, SUSP, and DSUSP while handing over to getty.  It is
up to the getty process to allow ISIG again.

This patch is due to the differences in control line setup between ARM,
x86/x86_64, and most notably PPC.  PPC in particular seem to have ISIG
set by default from the kernel.

Without this patch pressing Ctrl-C before getty is started will lead to
Finit receiving SIGINT and defaulting to a reboot, as introduced in the
BusyBox init signal adoption in eeb59eb.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-23 11:57:58 +02:00
Joachim Nilsson a36dafaa6c README: Update initctl usage
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 20:16:37 +02:00
Joachim Nilsson c092d22d48 initctl: Default to show services listing, not usage text
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 20:01:15 +02:00
Joachim Nilsson e4401f92ad Bump version for v3.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 0197a9427c Update ChangeLog for v3.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 49481053a4 Fix GCC 7 string truncation warning, too small temporary buffer
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().

This patch suppresses the warning by allowing only a subset of the
parent inetd service description to be copied to the child connection.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 13887f323a Fix GCC 7 string truncation warning, too small temporary buffer
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().

This patch fixes a possibly problem in path name creation which,
combined with the scandir() function, might cause loss of .conf
files, failure to call run-parts properly, and kill services at
shutdown.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson faca84a590 Fix GCC 7 string truncation warning, too small temporary buffer
In GCC 7 the -Wall infers the new -Wformat-truncation which finds
problems with string truncation in functions like snprintf().

This patch fixes a problem in condition parsing for very long
PID filenames which might be truncated in internal buffers
causing a mismatch in Finit condition tracking.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 920df09cd5 Fix GCC 7 warning, convert "Fall through" to "fallthrough" comment
In GCC 7 the -Wextra infers the new -Wimplicit-fallthrough which can be
suppressed by adding a simple comment

    /* fallthrough */

Which we had, but was too verbose (and misspelled) for GCC to notice.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-19 09:58:05 +02:00
Joachim Nilsson 3e71d43bff Follow-up to 22192ac, missing semicolon
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 23:19:41 +02:00
Joachim Nilsson 5c3a07e8e6 tty_exist(): Simplify, no need to call access() and then open()
Found by Coverity Scan, classified as security issue but was just
unnecessary overhead.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 23:06:04 +02:00
Joachim Nilsson 11dd877484 initctl: Fix possible divide by zero, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 23:01:07 +02:00
Joachim Nilsson 921fd1e363 service_start(): Don't fclose() invalid file pointer, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:58:31 +02:00
Joachim Nilsson f949017596 logrotate(): Ignore any error from rename(), file may not exist
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:57:18 +02:00
Joachim Nilsson 03a33fc0ee Check stat() return value, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:56:02 +02:00
Joachim Nilsson 22192acce4 initctl: Make sure to NUL terminate info string from Finit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:53:23 +02:00
Joachim Nilsson 500d301700 tty_unregister(): Fix possible out-of-bounds access, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:45:02 +02:00
Joachim Nilsson e8f26709e2 service_register(): Fix possible memory leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:41:13 +02:00
Joachim Nilsson 91b3e5eeb4 inetd: Fix possible tcp socket leaks, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:37:21 +02:00
Joachim Nilsson 71026adf03 tty_register(): Fix possible memory leak, found by Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:32:26 +02:00
Joachim Nilsson 978beb8e7e Don't log if failed to remove non-existing condition
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 22:05:00 +02:00
Joachim Nilsson 3ef75ac176 debian: Mention the possibility to change the default init to Finit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 21:49:19 +02:00
Joachim Nilsson 83b613581a void: Clean up README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 21:48:58 +02:00
Joachim Nilsson d4c28f87d1 void: Update installation instruction, recommend manual edit of grub
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 19:15:28 +02:00
Joachim Nilsson 5b53f001a2 Revert parts of c2bf7d3, core-services scripts not executable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 11:24:29 +02:00
Joachim Nilsson f1c9581da9 service_start(): Must set GID before dropping user privs, obvs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 11:05:59 +02:00
Joachim Nilsson 5301bcb4f1 void: Drop-privs to correct @username:group
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:51:39 +02:00
Joachim Nilsson c2bf7d3a50 void: Call runit core startup scripts using run-parts at bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:30:21 +02:00
Joachim Nilsson 685771aef2 void: Simplify uuidd service description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:29:53 +02:00
Joachim Nilsson 3ebb697910 Install a proper #!/bin/sh style rc.local on Void Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:18:11 +02:00
Joachim Nilsson bacaea0e02 bootmisc: Fix misspelled uuidd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:14:56 +02:00
Joachim Nilsson 07d6e69c30 bootmisc: Check return value from getgroup()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:10:13 +02:00
Joachim Nilsson d2053bd07d bootmisc: Follow-up to f4662d8
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:09:15 +02:00
Joachim Nilsson 1e8a45cbe2 void: Remove non-working hack to create /run/uuid in <service>.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:06:12 +02:00
Joachim Nilsson f4662d8c06 boomisc: Create /run/uuid for Void Linux if uuid user exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:05:46 +02:00
Joachim Nilsson 38ba9930d0 helpers.c:getuser() - Make @home an optional argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 10:03:54 +02:00
Joachim Nilsson 00fe37174d Refactor initial /dev popoulation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:57:38 +02:00
Joachim Nilsson 33916a2097 Fix #82: Revert parts of 34a1524 and add workaround from Void Linux
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>
2017-10-18 09:43:37 +02:00
Joachim Nilsson dd8dd67106 void: Create /run/uuid directory and start uuidd as @uuid:uuid
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:14:22 +02:00
Joachim Nilsson eb870efaff Add support for setting effective group ID of services
Finit has long since supported an @user:group syntax to services, tasks,
and run stanzas.  Setting UID was implemented at that time, but setting
GID never was.  This patch fixes that oversight.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 09:11:23 +02:00
Joachim Nilsson 84369ab8b5 void: No syslogd to wait for in Void Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 08:54:24 +02:00
Joachim Nilsson 7ef3959a45 Minor, consistency in presentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-18 08:14:29 +02:00
Joachim Nilsson 858f793ad2 Initial support for Void Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-17 23:53:24 +02:00
Joachim Nilsson 8749459206 doc/condiitions.md: Update and simplify, hopefully more readable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 17:07:52 +02:00
Joachim Nilsson 1c9f2e9b55 initctl: Fix set/clear condition
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 16:49:35 +02:00
Joachim Nilsson 9b8e7a0793 Minor, update documentation on raw condition dumps
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 14:54:48 +02:00
Joachim Nilsson 3f150901fe initctl: Align STATUS output from cond show and dump
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 11:26:43 +02:00
Joachim Nilsson fd090a6785 initctl: Fix 'cond dump/set/clear' commands, only show worked
This patch fixes an invalid use of strpbrk() causing all cond
sub-commands, except initctl cond show, to fail.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 11:23:57 +02:00
Joachim Nilsson 83445f1ebe initctl: show, use '-' for runlevels service is not member of
This patch adds a '-' for each runlevel a service/task is not part of.
The resulting listings are easier to read and also makes it clearer to
the user what happens when changing runlevels.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 09:43:58 +02:00
Joachim Nilsson e88241316b Prune bootstrap tasks/services that never ran
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 09:42:08 +02:00
Joachim Nilsson f91205cbad initctl: list, only print whitespace separator between services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 08:43:29 +02:00
Joachim Nilsson 94aec26e8c initctl: shoow, adjust width of runlevels column, needs 12 chars
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 08:42:47 +02:00
Joachim Nilsson 11026d9da3 initctl: Minor, use local screen_cols rather than SCREEN_WIDTH
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-16 08:42:03 +02:00
Joachim Nilsson a6a3299f08 Free cmd from which() after having registered the udevd service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 23:10:42 +02:00
Joachim Nilsson 34a15241ca Convert udevd to a regular system service
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>
2017-10-15 23:10:18 +02:00
Joachim Nilsson 7a2667d34c plugins/dbus: Free cmd returned from which() when done
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 23:01:10 +02:00
Joachim Nilsson f39cd50762 plugins/dbus: Use cmd found by which() to start dbus-daemon
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 22:48:04 +02:00
Joachim Nilsson ddeed15191 plugins/dbus: Start dbus-daemon with absolut path
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 22:45:01 +02:00
Joachim Nilsson 2b173e831f service_start(): Redirect service output to /dev/null by default
This patch prevents output of stderr/stdout from services to leak to the
console.  Use the 'log' keyword to service/run/task stanza to redirect
output to syslog.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 21:39:58 +02:00
Joachim Nilsson b02f241e5e plugin/dbus.c: Minor, documentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 21:18:21 +02:00
Joachim Nilsson 1a45045a0f service_register(): Do not modify input string, may be read-only
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 21:17:00 +02:00
Joachim Nilsson e131b20a6c service_register(): Make sure to initialize username to NULL
Follow-up to 7d9f873, which converted this from a function argument to a
local variable.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:47:18 +02:00
Joachim Nilsson 888ce56f3e plugin/dbus.c: Register dbus-daemon as a service
This patch changes how the D-Bus plugin starts dbus-daemon, from being
started in the background to letting Finit start and monitor it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:46:22 +02:00
Joachim Nilsson 7d9f873b7c Follow-up to a2f4b35, remove username arg from service_register()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:32:11 +02:00
Joachim Nilsson cf60cdd9c9 Fix termios regression on PPC introduced in 907595d
For some reason PPC is much more sensitive than ARM when it comes to
termios changes.  This patch fixes a regression in Ctrl-C handling
after login introduced in 907595d when blocking of Ctrl-C was added
to prevent breaking the login-prompt.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 20:12:37 +02:00
Joachim Nilsson bb27dde3ca Nope, keep original logo to home page instead, this is Finit3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:34:39 +02:00
Joachim Nilsson 6d02c6a71c New logo on top maybe?
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:33:17 +02:00
Joachim Nilsson f0c5c2d7f2 Play around a bit with altering logo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:32:23 +02:00
Joachim Nilsson 29357acf18 Update bootstrap.md to match Finit3 changes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 13:09:26 +02:00
Joachim Nilsson a32d3b0c87 Update ChangeLog upcoming v3.0 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-15 12:41:55 +02:00
Joachim Nilsson 510b53e62d Add simple ToC
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:35:51 +02:00
Joachim Nilsson 23481b197b build.md: Simplify and sectionalize better
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:34:09 +02:00
Joachim Nilsson 4782b1dc54 conditions.md: Remove ToC heading and rewrite introduction
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:30:31 +02:00
Joachim Nilsson 1ee1b9cec4 signals.md: Clarify and update slightly
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:22:45 +02:00
Joachim Nilsson cef2ef82b6 Add mini ToC for overview
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:20:46 +02:00
Joachim Nilsson cafa759edb distro.md: Clarify vague leading paragraph
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:18:15 +02:00
Joachim Nilsson cf0554405b bootstrap.md: Start updating, needs more work ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:17:42 +02:00
Joachim Nilsson f6071d6701 contrib: Rename tty.conf to getty.conf to reduce confusion
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:09:35 +02:00
Joachim Nilsson 7104296396 Remove ToC heading and audit grammar + wording in Limitations section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 16:04:56 +02:00
Joachim Nilsson 38a274114d Allow registering TTYs that are not yet available
This patch removes the following very annoying warning for TTY devices
not yet available, i.e. plugged-in to the system.

Loading configuration ............................................................................. [ OK ]
[   11.097414] finit[1]:tty_register():Incomplete or non-existing TTY device given, cannot register.
[   11.101457] finit[1]:tty_register():Incomplete or non-existing TTY device given, cannot register.
Mounting filesystems .............................................................................. [ OK ]

Finit will not start a getty (built-in or external) if the TTY does not
exist, but having the configuration enabled makes it possible to do a
simple `initctl reload` to activate a plugged in TTY.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-14 13:14:48 +02:00
Joachim Nilsson 97eca563b6 Reduce indent and remove non-matching keyword conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:34:32 +02:00
Joachim Nilsson 0174347039 Use Apache .conf highlighting for finit.conf sample
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:32:43 +02:00
Joachim Nilsson 02cc426f05 Update Alpine screenshot, removed failing/missing D-Bus service
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:17:37 +02:00
Joachim Nilsson 06d9d95723 Minor updates, linking to scripts, grammar
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:11:59 +02:00
Joachim Nilsson b8a7f3e0cc Link to Alpine Linux home page
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:08:18 +02:00
Joachim Nilsson 7db0e265ad Link to Alpine Linux home page
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:07:06 +02:00
Joachim Nilsson 6818813ff8 plugins/dbus: Conditionalize, don't run if dbus-daemon is missing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 08:02:59 +02:00
Joachim Nilsson 5b8f7ce2a3 Update screenshot, TroglOS Linux --> Alpine Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:59:33 +02:00
Joachim Nilsson 1f9a6a42c1 Push badges even further down
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:37:22 +02:00
Joachim Nilsson 1c2d987bea Place logo first, then badges
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:36:06 +02:00
Joachim Nilsson 906827cc88 Move documentation to doc/ sub-directory, all except README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-13 07:35:09 +02:00
Joachim Nilsson b2d98dc010 Update path to sample finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:10:47 +02:00
Joachim Nilsson d027b4ff9c Relocate old sample finit.conf to contrib/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:09:32 +02:00
Joachim Nilsson 843621aded Move documentation to doc/ sub-directory, all except README + TODO
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:07:21 +02:00
Joachim Nilsson da5ac16670 Minor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 23:05:27 +02:00
Joachim Nilsson 2c68183045 Clarify actions of Alpine Linux install script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:51:15 +02:00
Joachim Nilsson c40cd06d60 Update Alpine README, we now have an install script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:44:56 +02:00
Joachim Nilsson c901b65581 Simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:44:00 +02:00
Joachim Nilsson 27abcb5682 Add option to install Finit as system default init
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:41:20 +02:00
Joachim Nilsson b7617248ce Simple install script for Alpine Linux
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:35:17 +02:00
Joachim Nilsson c400d35f83 Also include /usr/lib/pkgconfig in PKG_CONFIG_LIBDIR
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:26:37 +02:00
Joachim Nilsson d236709457 Minor, script output updates
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 22:26:24 +02:00
Joachim Nilsson 07790f4044 Debian/REDAME: Clarify last paragraph, add reminder of /etc/rc.local
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 19:03:53 +02:00
Joachim Nilsson 3d5128be77 Remove Emacs Local Variables, not really needed and looks bad
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 19:01:25 +02:00
Joachim Nilsson b37ea48e5d Debian/README: Update, modernize, simplify, and clarify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:54:34 +02:00
Joachim Nilsson 92616d2ac0 README: Add URLs for the various RFC inetd services available
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:46:14 +02:00
Joachim Nilsson 46bc75e7f3 README: Add more examples on conditions and multiple dependencies
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:43:47 +02:00
Joachim Nilsson 5f81404162 xdm.conf: Remove lightdm, now has its own .conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:25:51 +02:00
Joachim Nilsson 6ba7cfc851 Rename Debian xdm.com --> xdm.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:24:41 +02:00
Joachim Nilsson 09d2243eba Add Debian .conf for LightDM
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 18:23:19 +02:00
Joachim Nilsson e97c5e5860 Increase log level for poweroff/reboot/halt
In case the kernel is incapable of handling a reboot,
power-off, or halt request we want to be able to let
the user perform some basic diagnose of the system.

The existing debug messages are good enough, and use
the correct grammar form, to be enabled always.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 09:03:24 +02:00
Joachim Nilsson 660a09c7c1 Reduce log level when skipping re-register of boostrap tasks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 09:02:05 +02:00
Joachim Nilsson 41c003b221 Don't reload *.conf files when changing to runlevel reboot
... or if someone manages (regression) to change to runlevel bootstrap.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 08:56:08 +02:00
Joachim Nilsson 12d8ac2399 service_register(): Skip bootstrap services if not in bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 08:55:42 +02:00
Joachim Nilsson 8dc263d508 Revert live logging of state machine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:28:38 +02:00
Joachim Nilsson afb3fada50 cond_reassert(): Use cond_set_path(), not cond_clear(), for reconf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:23:43 +02:00
Joachim Nilsson 227dda34f7 cond_set_path(): Log error if unlink() fails
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:23:16 +02:00
Joachim Nilsson 06479aa5f1 Remove reconf condition when .conf reload completes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 01:07:09 +02:00
Joachim Nilsson 75d29de3cc initctl: Use entire screen width for task/service description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-12 00:19:10 +02:00
Joachim Nilsson 40fc95047d Prevent 100% CPU, allow bootstrap tasks to fully complete
When collecting a bootstrap task we need to allow its state machine to
complete before cleaning them out.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 23:53:34 +02:00
Joachim Nilsson 5551324291 Minor, comment style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 23:52:20 +02:00
Joachim Nilsson 46cef811d6 Make sure to step state machine when collecting bootstrap tasks
During the runlevel change from S --> 2 the state machine will pause,
waiting to collect all S-only tasks/services, before continuing.

When an S-only task/service is collected we therefore need to call the
state machine again so that it can reassert all conditions properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 23:02:13 +02:00
Joachim Nilsson 52ccd6d662 Use correct grammar form
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 22:54:48 +02:00
Joachim Nilsson 70afaa16f5 sm_step(): Log pending stopped svc if we exit state machine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 22:05:33 +02:00
Joachim Nilsson 8a1015cf3e API refactor, allow svc_stop_completed() to return the pending svc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 22:04:17 +02:00
Joachim Nilsson 586f0a7799 Live debug stopped but not yet collected tasks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:56:49 +02:00
Joachim Nilsson 474bd2f361 Minor, comment style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:56:31 +02:00
Joachim Nilsson 0caa8330b7 Increase live debugging of main state machine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:41:42 +02:00
Joachim Nilsson c8d8c817e7 Minor, cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:29:21 +02:00
Joachim Nilsson 0d9542c222 Live debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-11 21:29:15 +02:00
Joachim Nilsson b6be354508 Minor, whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 23:39:22 +02:00
Joachim Nilsson 448c6749d6 Add missing debug calls to RTM_NEWLINK and RTM_DELLINK
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 22:53:19 +02:00
Joachim Nilsson 0f09c1b0dc Minor, comment fix
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 22:53:05 +02:00
Joachim Nilsson 7db6611593 Debian GNU/Linux: Minor caveats
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 22:15:27 +02:00
Joachim Nilsson c9b13759a2 Debian GNU/Linux: Install finit.* using install and cp
A recursive cp is requried for finit.d

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 18:50:58 +02:00
Joachim Nilsson 449c712329 Remove old symlinks and install finit.d directory instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 16:15:36 +02:00
Joachim Nilsson e27283c5e6 Add extra spacing
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 16:14:27 +02:00
Joachim Nilsson f337efcc35 Debian GNU/Linux: Update install script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 16:13:22 +02:00
Joachim Nilsson 3c7eaff7b3 Debian GNU/Linux: Update and sync build instructions with Alpine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 12:00:04 +02:00
Joachim Nilsson d4d42a7a75 Debian GNU/Linux: Convert finit.conf to finit.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 11:59:29 +02:00
Joachim Nilsson 3c1c5621a5 Alpine Linux: Slight update + sync with Debian
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-10 11:46:02 +02:00
Joachim Nilsson 2d9c147e0e Minor, fix comment within comment GCC warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-09 09:03:58 +02:00
Joachim Nilsson 53de1c8575 Follow-up to issue #81, don't append error message again.
Also, when called multiple times, return workaround immediately instead
of warning again.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 22:07:21 +02:00
Joachim Nilsson 3d4e3c99ed Fix #81: Workaround for systems without SYSV shm IPC support
We should not let PID 1 fail on systems where Linux is built without
CONFIG_SYSVIPC, or the libc does not support shmget()/shmat().

This workaround implements a fallback to using calloc() for PID 1,
which means the initctl tool will not work properly.  A better fix
would be to refactor the shm implementation to instead have initctl
call Finit using api.c for each svc_t.  This has been added to the
TODO file as future work.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 20:52:01 +02:00
Joachim Nilsson c1b6c7e840 TODO: Remove shm, as soon as possible
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 20:01:57 +02:00
Joachim Nilsson f17515d791 Merge pull request #80 from joerg-krause/patch-1
helpers.h: fix build error: unknown type name ‘va_list’
2017-10-01 18:56:45 +02:00
Jörg Krause 48262e4250 helpers.h: fix build error: unknown type name ‘va_list’
Building finit with a uclibc-ng-toolchain fails with:
```
../src/helpers.h:53:43: error: unknown type name ‘va_list’
 void    printv          (const char *fmt, va_list ap);
```
2017-10-01 16:50:39 +02:00
Joachim Nilsson 9d9dc74768 Minor corrections
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-10-01 01:26:43 +02:00
Joachim Nilsson e1d1d1c795 Makefile: Remove service script wrapper from distribution as well
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 12:16:33 +02:00
Joachim Nilsson fcfef0af47 Initial cleanup + refactor of Debian contrib files
We should no longer need to rely on runparts to handle initial set up of
keyboard and console.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 10:26:03 +02:00
Joachim Nilsson c44c217c4a Clean up unused and long since deprecated contrib files/patches
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-30 10:23:21 +02:00
Joachim Nilsson d60fc1ce62 Refactor, simplify
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-29 01:22:10 +02:00
Joachim Nilsson 0a12997d32 Try right aligning Finit3 logo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-29 01:21:07 +02:00
Joachim Nilsson dce8031c83 Clarify, early on, that conditions also stop services.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-28 08:22:41 +02:00
Joachim Nilsson bd9d9c8303 Add early example of conditions in service stanza
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-28 08:22:28 +02:00
Joachim Nilsson 956acc4b93 Update getty overview
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-28 08:10:31 +02:00
Joachim Nilsson 5ed54d79fc Update configure flags
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:27:15 +02:00
Joachim Nilsson acc77c27c3 Add URL to initctl reference
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:23:54 +02:00
Joachim Nilsson bcb9fe039a Move running and debugging to doc/build.md
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:22:04 +02:00
Joachim Nilsson 55f44386d1 Clarify focus, refer to examples and tell what the screenshot is
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:09:23 +02:00
Joachim Nilsson 37983e69c4 Clarify service stanza and simplify text further
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 09:08:32 +02:00
Joachim Nilsson a45a872c28 Simplify introduction a lot, focus on screenshot and example
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 08:43:53 +02:00
Joachim Nilsson 152b2be8ea Clarify warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-27 08:43:27 +02:00
Joachim Nilsson 1677436137 initctl: Allow C99 style
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-26 10:39:45 +02:00
Joachim Nilsson c69ca6847a Update ToC and move references to alternative init systems here
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-25 19:06:07 +02:00
Joachim Nilsson f8147214f1 doc/config.md: Significant update, less limitations for /etc/finit.d
- Detail limitations in separate section
- Focus on syntax early in document
- Overhaul and simplify introduction

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-25 19:03:22 +02:00
Joachim Nilsson 56eec5164d Minor, update code comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-25 19:02:19 +02:00
Joachim Nilsson e58f84f3fb Update introduction, much system config can be done using finit.d
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-24 20:54:27 +02:00
Joachim Nilsson d22ffa05bd initctl: Refactor initctl list slightly
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-24 20:41:40 +02:00
Joachim Nilsson 2e66db3fea helpers.c:printv() - Iterate over size of buffer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-24 20:40:44 +02:00
Joachim Nilsson 376811c1a7 doc/config.md: Update run and task, mention pipes + redirects
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-21 22:52:48 +02:00
Joachim Nilsson 9b5f2388c1 Alpine Linux: Add LXDM service .conf
Enable LXDM using:

    initctl enable lxdm
    initctl reload

The latter command reloads all /etc/finit.d/*.conf files and starts lxdm
in runlevels 2-5.

Remember to first edit /etc/lxdm/lxdm.conf, necessary to get a session.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 15:33:56 +02:00
Joachim Nilsson 686193b701 Only load modules at bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 14:03:56 +02:00
Joachim Nilsson b43bca529c Minor, fix build error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:57:23 +02:00
Joachim Nilsson 545171a8b2 Minor, improve comments in parse_dynamic()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:50:44 +02:00
Joachim Nilsson d54d5b7f20 Allow kernel modules to be loaded from /etc/finit.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:48:07 +02:00
Joachim Nilsson e52d952ca5 Alpine: Move bootstrap services and setup from finit.conf to finit.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:30:36 +02:00
Joachim Nilsson 633a56054b Add support for boot[S]trap services in /etc/finit.d/*.conf
This patch enables support for bootstrap services in /etc/finit.d/

Please note, however, that this does not mean that all configuration
directives are now allowed in /etc/finit.d/*.conf -- the intention is
only to simplify distribution setups.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 13:21:11 +02:00
Joachim Nilsson 3eeb966f15 Alpine Linux: Simplify build instructions by referencing script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 12:55:32 +02:00
Joachim Nilsson d09253bdbd Make Alpine build script executable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 12:50:36 +02:00
Joachim Nilsson 0052793a46 Update Alpine Linux README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 11:41:05 +02:00
Joachim Nilsson 333871caf2 Minor, reorder
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 11:40:56 +02:00
Joachim Nilsson ef9d0c479e Load mousedev kernel driver for Alpine installs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 01:40:24 +02:00
Joachim Nilsson d5cce03a76 Enable D-Bus plugin for Alpine installs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-10 01:39:23 +02:00
Joachim Nilsson 744903d455 Alpine Linux finit.conf, clear space at end for easy script append
Restore original file layout somewhat, it's better if we clear the space
at the end of the file for easy `cat BOOTSTRAP.conf >>/etc/finit.conf`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-06 08:12:44 +02:00
Joachim Nilsson cc00be48b5 Move runlevel stanza to the end, possibly more intuitive
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 21:24:59 +02:00
Joachim Nilsson b45a37ca47 Add simple build script for targeting Alpine
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 21:20:32 +02:00
Joachim Nilsson f1f9ee712a Refactor Alpine example to use /etc/finit.d/*.conf for services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 21:15:11 +02:00
Joachim Nilsson 7c4a9ad5af alpine: Migrate rc.local bootstrap tasks to finit.conf
Finit now supports pipes and redirects in run/task stanzas.  Hence, we
can reduce rc.local to an example template.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 20:16:54 +02:00
Joachim Nilsson f3a000560f exec_runtask(): Refactor, remove GLIBC:isms to build with musl
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 20:05:22 +02:00
Joachim Nilsson fdd13c1ae1 README: New shell redirect + pipe possibilities with task + run
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:35:22 +02:00
Joachim Nilsson 0585767258 README: Update tty configuration examples with noclear + nowait
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:35:04 +02:00
Joachim Nilsson 9e7e92b4b7 run stanzas are never caught in service_monitor()
A run stanza blocks operation by calling waitpid(), so it will never be
caught by the service_monitor() function.  Hence, we need to clean up
any bootsrap calls after waitpid(), or at least perform a manual state
change.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:02:23 +02:00
Joachim Nilsson 29822ef0f7 Always collect bootstrap tasks, regardless of previous runlevel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:02:01 +02:00
Joachim Nilsson 718e82bc10 svc_clean_dynamic(): Actually clean dirty services ...
Add missing call to svc_mark_clean() in while() loop.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:01:05 +02:00
Joachim Nilsson 684314db0f Allow pipe + redirect in task/run stanzas, exec() in /bin/sh
This patch extends the capabilities of task and run .conf stanzas by
enabling pipes and redirects.

Example:

    task [s] echo "foo" | cat >/tmp/bar
    run  [s] echo "$HOME" >/tmp/secret

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 16:00:49 +02:00
Joachim Nilsson 442598282f Update Alpine Linux sample to latest Finit dev.
- Show progress when booting
- Use noclear + nowait on TTY's
- Update `loadkmap` args

Works on Alpine Linux 3.4 .. 3.6

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-04 07:19:12 +02:00
Joachim Nilsson 3e2b78305d Update finit.conf tty documentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:45:29 +02:00
Joachim Nilsson 8eea64cebf getty: Set $TERM environment variable if given in tty config
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:41:22 +02:00
Joachim Nilsson b8a7cb6b93 tty-register(): Fix regression in built-in TTY baud + term parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:40:52 +02:00
Joachim Nilsson 529b39ebba tty: Add 'noclear' + 'nowait' options to built-in and external tty's
This patch aligns the two tty configuration stanzas, thus clear and wait
are now the default for both.

    tty [LVLS] <DEV> [BAUD] [noclear] [nowait] [TERM]
    tty [LVLS] <CMD> <ARGS> [noclear] [nowait]

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 06:10:08 +02:00
Joachim Nilsson f029ba2111 Reorder functions a bit, group run_getty*() family
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 05:50:50 +02:00
Joachim Nilsson 277c3dbb14 getty: Remove TTY clear from built-in getty, delegate to run_getty()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-09-01 05:47:53 +02:00
Joachim Nilsson f273ecc135 Fix #79: Add 'nowait' option to tty setting, external getty
This patch makes it possible to disable the "Please press Enter" prompt
when using an external getty. Simply append `nowait` to the .conf entry
and Finit will spawn the getty immediately.

A future patch will add support for `noclear` as well to external getty,
as well as a change in default (=> `wait`) for the built-in getty.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-31 00:51:11 +02:00
Joachim Nilsson 2fe257b7af getty.c: Handle Ctrl-U properly, erase line to beginning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 17:19:43 +02:00
Joachim Nilsson 907595d9ed getty.c: Ignore signals like SIGINT, SIGHUP
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 17:19:12 +02:00
Joachim Nilsson 55c12aa6f6 Remove developer debug message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:08:14 +02:00
Joachim Nilsson 04891d3e5b Update and align service descriptions in finit.conf example
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:05:31 +02:00
Joachim Nilsson 9973cd22a5 Update sample .conf files after purge of startx and user settings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:02:39 +02:00
Joachim Nilsson a2f4b35e4e Fix #77: Remove deprecated startx and user .conf settings
It is strongly recommended to instead use the service stanza to start
XDM/GDM, or use startx after a regular login.

Note: the `user NAME` setting was always reserved for use with startx

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 15:01:05 +02:00
Joachim Nilsson 1de540dd67 Update external getty TTY documentation, remove limitations
Also, provide an agetty example.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 14:47:15 +02:00
Joachim Nilsson dec21e758a Fix #78: Support agetty cmd line format for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-30 14:44:10 +02:00
Joachim Nilsson 513f03b897 Merge branch 'external-getty-support' 2017-08-27 17:08:21 +02:00
Joachim Nilsson 371fb3d0d0 Add example for using an external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 17:07:12 +02:00
Joachim Nilsson f9f1846c8b Document alternative tty ... config option for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 17:03:39 +02:00
Joachim Nilsson f7b9b7be96 tty.c: Free memory for external getty on tty_unregister()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 16:57:26 +02:00
Joachim Nilsson 74affb32d3 tty_register(): Fix parser for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 16:43:01 +02:00
Joachim Nilsson 675f82a6b9 run_getty2(): Minor fixes only, whitespace + cautionary _exit()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 16:41:58 +02:00
Joachim Nilsson 19fcfcfef4 Initial support for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 15:02:55 +02:00
Joachim Nilsson 7c50d86a55 Restore pre built-in run_getty() as run_getty2()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 15:01:42 +02:00
Joachim Nilsson b629348973 Refactor TTY exec, prepare for external getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-27 15:00:43 +02:00
Joachim Nilsson 7c185b4575 Fix really bizarre inetd builtin example ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-21 21:23:51 +02:00
Joachim Nilsson fefa6a93ca Merge branch 'emergency-shell-improvements' 2017-08-19 20:17:31 +02:00
Joachim Nilsson 299962118a Update debug section with info on rescue shell, issue #76 2017-08-19 20:16:44 +02:00
Joachim Nilsson 054baed134 Reap zombie processes in emergency shell mode, issue #76
The emergency shell is just a Finit debug mode.  This patch adresses a
concern from GitHub issue #76, with zombie processes in this mode.

Emergency shell could be further improved, e.g. informing the real Finit
process of each collected child (zombie) to be restarted if needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-08-15 08:09:19 +02:00
Joachim Nilsson b20fafd9fa tty.c: Add support for reloading a single TTY
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-14 11:03:59 +02:00
Joachim Nilsson 62081d9525 tty.c: Refactor, break out enabled check + stop/start
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-14 11:03:10 +02:00
Joachim Nilsson 100b4c70e4 tty_enabled(): Simplify, tty_exists() checks for existence
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-14 10:54:51 +02:00
Joachim Nilsson 5631849ced Travis-CI: Update build dependency, libite --> v1.9.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-10 17:48:14 +02:00
Joachim Nilsson 14ee218443 Refactor, use libite (-lite) version of initscr()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 16:25:22 +02:00
Joachim Nilsson 52fe525442 Update version requirement for libite, v1.9.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 16:25:01 +02:00
Joachim Nilsson fec00377e5 Update documentation for tty .conf option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:36:31 +02:00
Joachim Nilsson c9ab70e30f Update section on built-in getty, add info on noclear option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:18:16 +02:00
Joachim Nilsson 8aef1e76c3 Follow-up to eec32e2: Support for removing TTYs at runtime
In commit eec32e2 support for reloading TTY configurations was added.
This patch is a follow-up to that with support for cleaning up and
removing allocated TTYs.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson 44f69bd575 Check if symlink with lstat(), mtime with stat()
With the new scheme using /etc/finit.d/available/, and symlinks from
there to the enabled directory, we need to check mtime of .conf files
using stat(), not lstat() which we need to check if .conf is a symlink.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson 963b736d8b tty: Refactor, remove useless runlevel argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson 4cc3aed139 Avoid 2 sec block of Finit when stopping TTYs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson e791e3dbe9 Make silent bootup the default, use --enable-progress for old style
This patch disables console heading and bootup progress messages by
default. Use --enable-progress to get the old behavior back, or try
the new HOOK_BANNER and HOOK_SVC_UP to run a custom progress.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-09 15:05:32 +02:00
Joachim Nilsson d34ee62f77 Update copyright years
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:32:24 +02:00
Joachim Nilsson e48901b90f tty: Clear tty before login: prompt by default, add 'noclear' option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:31:59 +02:00
Joachim Nilsson 60f73dc952 tty.c: Refactor parsing of tty .conf stanza in tty_register()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:30:51 +02:00
Joachim Nilsson eec32e299b Allow loading TTYs from /etc/finit.d rather than /etc/finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:28:22 +02:00
Joachim Nilsson fe362341dc finit.conf: Remove check config, replaced by fsck over /etc/fstab
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 15:01:31 +02:00
Joachim Nilsson 8505db24b7 Refactor, rename local variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 12:28:52 +02:00
Joachim Nilsson 560adb2065 Remove debug message(s) from tty_fallback()
When the TTY fallback mechanism is enabled tty_fallback() prints this
annoying debug message whenever *any* is process is collected by PID 1:

   "Not starting fallback (%d) shell, lost pid %d", fallback, lost"

This patch removes it, and a two other useless debug messages.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 11:06:28 +02:00
Joachim Nilsson 6676d4b50c Silence service start/stop *before* launching TTYs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 11:04:50 +02:00
Joachim Nilsson c1bd3961cf log_init(): If called with debug disbled set (or restore) LOG_NOTICE
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:11:24 +02:00
Joachim Nilsson 4fa47eaf71 log_init(): If debug mode enabled, set loglevel LOG_DEBUG
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:08:27 +02:00
Joachim Nilsson e5f47024af early_logit(): If debug mode enable, also print to stderr
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:07:49 +02:00
Joachim Nilsson 115b5f1ca7 Add HOOK_BANNER for plugins to override the default Finit banner()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:07:21 +02:00
Joachim Nilsson 878885e2b2 Load plugins much earlier, for future banner plugin
This patch moves the plugin loader much earlier, making it possible to
provide a custom banner/logo in a plugin.

To facilitate this move we need to also move banner later and parsing
of the kernel cmdline earlier, right after mouting /proc.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-08 00:05:07 +02:00
Joachim Nilsson 709e4230c8 plugin: Add private method plugin_exists() to check for HOOKs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:33:43 +02:00
Joachim Nilsson 46c5e41b68 README: Reduce indentation of code blocks, use ``` instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:18:06 +02:00
Joachim Nilsson 0b43d0dc70 Refactor screen_init(), preparing for migration to libite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-07 23:00:27 +02:00
Joachim Nilsson 99f3f0291a Makefile.am: Fix cut-and-paste error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 21:48:16 +02:00
Joachim Nilsson 6d3d190134 reboot: Add search path to libite (-lite) headers and .so
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 21:40:46 +02:00
Joachim Nilsson 769659767c Minor, comment fixes only
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 21:12:54 +02:00
Joachim Nilsson 99818f9ce0 Convert banner() and printv() to use new screen_init() values
This patch changes the traditional look of the Finit boot sequence.
Now we stick to the screen width probed by screen_init(), or max
132 chars.

Also, some minor cleanup of the currently unused print_timestamp()
method used by printv() when showing [ OK ] or [FAIL] of services
at boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 20:59:49 +02:00
Joachim Nilsson be6f0de0df Add util.c:screen_init() to probe screen size once per boot
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 20:58:43 +02:00
Joachim Nilsson 405cf4d997 initctl: Use actual terminal/screen width for table listings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:55:34 +02:00
Joachim Nilsson 91480a0f02 configure: Check for termios.h, needed by screen_width()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:55:10 +02:00
Joachim Nilsson 90793c71a2 util: Import screen_width() developed for the SMCRoute project
This patch introduces the screen_width() method from the SMCRoute
project.  The code is hereby also available under MIT/X11.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:53:19 +02:00
Joachim Nilsson 9bcb3e5778 initctl: top:ify table headings, i.e. use captial letters
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:39:41 +02:00
Joachim Nilsson c97e23bd58 initctl: Remove currently unused -d debug flag
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:38:22 +02:00
Joachim Nilsson 73f1b986dd initctl: Fix regression in initctl utmp
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:37:59 +02:00
Joachim Nilsson b06502b0cb initctl: Use printheader() from libite for table headings
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-04 12:37:20 +02:00
Joachim Nilsson c4b6fab3f3 Travis-CI: Update with latest version of libite, v1.9.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 16:46:52 +02:00
Joachim Nilsson 109b5bb9df Update TODO, some completed and some deprecated features
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 15:16:36 +02:00
Joachim Nilsson 6f61e8e915 Remove hard-coded paths to system tools available in $PATH
Since at least a44daf2 both run() and run_interactive() can access all
system tools in _PATH_STDPATH.  A system that uses non-standard paths,
e.g. /system/bin and /apps/bin, should update _PATH_STDPATH.

For reference, see issue #69 and PRs #70 and #72.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 13:18:42 +02:00
Joachim Nilsson 9c6e046d93 Remove hard-coded paths to system tools available in $PATH
This patch implemements a new feature of libite v1.9.1, whichp(), which
instead of fexist() that requires an absolute path, searches $PATH.

For reference, see issue #69 and PRs #70 and #72.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-03 13:13:55 +02:00
Joachim Nilsson 30822f0d68 Remove UNUSED() macro and disable the compiler warning instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 21:59:23 +02:00
Joachim Nilsson e46e3cdcb6 log.c: Filter debug messages by default, like before refactor
Ways to log:
- Set debug, using kernel cmdline, or edit the sources
- Change loglevel severity, default blocks > LOG_NOTICE

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 21:56:19 +02:00
Joachim Nilsson 260335a19f Usability, a servivce stopped by a user is stopped, not blocked
The generic term for a non-running service is blocked, but a service may
be blocked for several different reasons.  When a user stops a service
with `initctl stop` the intuitive expected output from `initctl show` is
"stopped" not "blocked".

When the user later restarts the service with `initctl start` it may of
course be blocked due to wrong runlevel or a missing condition.  As can
be expected from the service's configuration.

The rest of the patch refactors the internal API names a bit to reflect
this change.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 15:42:44 +02:00
Joachim Nilsson 516dbcc512 Remove --disable-quiet and quiet mode, default to a sane behavior
This patch is a follow-up to 1f1c2e0 which introduced the new semantics
for the very confusing quiet and silent modes.

The initial idea was to loosely follow the kernel cmdline 'quiet' option
and as a working concept this was good.  The resulting code, however,
became unnecessarily complex and the configure options impossible to
explain.

With this patch the quiet mode, and thus the --disable-quiet configure
option, is removed.  Finit now defaults to a sane behavior: services are
shown only at startup.   The --enable-silent option works like it did
before, silencing everything.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 13:40:54 +02:00
Joachim Nilsson 7a48240856 log.c: Do reopen syslog() when toggling debug => LOG_PERROR
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 13:19:22 +02:00
Joachim Nilsson cda5938215 helpers.c: New function, printv()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:43:41 +02:00
Joachim Nilsson cd947a69a8 log.c: New functions to hide access to quiet and silent flags
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:42:44 +02:00
Joachim Nilsson 60df2f2ea9 Minor, cleanup old requirement for clients to set silent
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:41:23 +02:00
Joachim Nilsson 51e1a907e6 log.c: New log_is_debug() function, hide access to debug variable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:40:50 +02:00
Joachim Nilsson e9d5512e1a Refactor, simplify ... print() APIs already check if silent
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:38:35 +02:00
Joachim Nilsson bd54cf6dee log.c: New log_init() function, called at initial bootstrap
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:34:12 +02:00
Joachim Nilsson 1036c365b8 log.c: New log_exit() function, called at shutdown
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:31:38 +02:00
Joachim Nilsson 8ce330bcdb log.c: Rename log_toggle_debug() --> log_debug()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 12:28:16 +02:00
Joachim Nilsson 8161e8d153 Simplify log message from kernel cmdline parser
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-02 01:26:36 +02:00
Joachim Nilsson ec52a6a240 Set correct syslog() log level based on debug flag
Also, refactor logging to /dev/kmsg to separate function.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 22:23:53 +02:00
Joachim Nilsson 9a4f46dba4 Install log.h for external plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:36:47 +02:00
Joachim Nilsson 5e8cb63f9a Refactor, _d() et al to use logit() instead of err.h
This patch is the first in a series of changes to clean up the internal
logging APIs of Finit:

  1. Convert log macros to use logit() for everything (this patch)
  2. Set correct syslog() log level based on debug flag
  3. Do closelog()/openlog() when toggling debug flag to control LOG_PERROR

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:37 +02:00
Joachim Nilsson d1df837d04 Refactor, move debug toggle to log.c:log_toggle_debug()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:37 +02:00
Joachim Nilsson 670f08ce51 Refactor, move logit() and log macros to log.c + log.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:37 +02:00
Joachim Nilsson 82661346b7 Follow-up to 885056a, collapse and simplify code
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 20:34:26 +02:00
Joachim Nilsson b2ac81540f Merge branch 'enable-disable-services'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 18:02:52 +02:00
Joachim Nilsson fd861e1691 conf.c: Log warning for dangling .conf symlinks in /etc/finit.d/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 17:52:15 +02:00
Joachim Nilsson 76b5bdc2c4 conf.c: Simplify .conf load/parse debug messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 16:06:01 +02:00
Joachim Nilsson 0ec5ad6961 TODO: Remember the idea of creating service stanzas using initctl
See issue #69 for a background.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 12:18:46 +02:00
Joachim Nilsson 1c2dcd9acc doc: Add distribution recommendations and tips, issue #71
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-07-01 12:17:57 +02:00
Joachim Nilsson 018a87286c initctl: Sort commands in usage according to topic
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 12:12:13 +02:00
Joachim Nilsson d0a3b4b019 Note neat feature of Solaris SMF, enable service temporarily
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-30 10:41:24 +02:00
Joachim Nilsson 3428cd48b7 Fix #71: Add support for enabling/disabling services in /etc/finit.d
This patch adds support for enabling and disabling services in
/etc/finit.d/ by adding another subdirectory:

    /etc/finit.d/available

Enabled service/run/task stanzas are by convention symlinked
to the parent dir.  The initctl tool has three new convenience
commands to facilitate operating with this:

   initctl list
   initctl enable  <CONF>
   initctl disable <CONF>

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-29 22:23:38 +02:00
Joachim Nilsson 023a881fb9 Enable more compiler warnings by default, except unused parameters
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-29 22:23:09 +02:00
Joachim Nilsson 36f38d5a13 initctl: Only append space between args, not at last arg
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-29 22:21:33 +02:00
Joachim Nilsson d4001064a0 configure: Fix hard coded FIFO path, found by previous commit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-11 22:52:09 +02:00
Joachim Nilsson fffdad7645 configure: Add neat summary of settings, from lldpd
Hat tip to @vincentbernat

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-11 22:19:54 +02:00
Joachim Nilsson 32612929d9 doc/conditions.md: Attempt to clarify PID file dependency handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-10 19:49:36 +02:00
Joachim Nilsson d49683cfb6 TODO: Update and clarify introduction a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-10 19:46:19 +02:00
Joachim Nilsson 9ca5ec16af doc/config.md: Minor refactor to add an Introduction section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-10 19:44:48 +02:00
Joachim Nilsson 7041813966 Update Makefile after service script move
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 01:08:46 +02:00
Joachim Nilsson a31ecb32e1 Fix problem with building from a separate build directory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 01:07:47 +02:00
Joachim Nilsson b1ea279940 Move helper script 'service' to contrib/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 01:00:40 +02:00
Joachim Nilsson 82172e65fa Fix indentation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 00:56:24 +02:00
Joachim Nilsson dfedb231dc Add MIT license badge to README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-06-05 00:54:45 +02:00
Joachim Nilsson 5f5be8d74e Merge pull request #73 from westermo/wmo/inetd-remove-ntoh-on-proto
inetd: remove ntoh on proto
2017-04-25 13:34:19 +02:00
Petrus Hellgren fafeaf661a inetd: remove ntoh on proto
getprotobyname() returns p_proto in host endian, so it should not be
converted with ntoh. (Note: getservbyname() on the other hand does
return s_port in network endian)

Signed-off-by: Petrus Hellgren <petrus.hellgren@westermo.se>
2017-04-25 10:39:09 +02:00
Joachim Nilsson 06d3161ffe Merge pull request #72 from abucodonosor/master
Some cleanup

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-28 18:43:32 +02:00
crazy 885056a6c9 networking(): check first ifup exists
Check first ifup exists before using it since
   this is really something only exits on some
   distros an in different ways. Debian/Ubunu has
   an package for this while others have it in the
   initscripts package(s) , meaning the file can be
   around even without the prog.

Signed-off-by: crazy <crazy@frugalware.org>
2017-03-28 13:21:20 +02:00
crazy a44daf20cb finit.c: set _PATH_STDPATH much earlier
This should allow us to run 'prog' without
     absolute paths.  Eg:

     run("/bin/foo"); -> run("foo");

     However we still need absolute PATH for
     checking since fexist() need full path right now.

Signed-off-by: crazy <crazy@frugalware.org>
2017-03-28 13:21:18 +02:00
crazy 67435d2034 finit.h: added fallback for _PATH_{STDPATH,VARRUN} in case is not defined
That should never be needed , however I saw
  already systems with broken paths.h so better
  have something around in case something breaks.

Signed-off-by: crazy <crazy@frugalware.org>
2017-03-28 13:21:14 +02:00
Joachim Nilsson cd5348dffd Add a set of contributing guidelines
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-21 07:58:57 +01:00
Joachim Nilsson 6e4b698fac Add Code of Conduct document
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-21 07:49:19 +01:00
Joachim Nilsson c135a83cb3 Check if /proc/bus/usb exists before trying to mount it
Most newer kernels have usbfs disabled by default.
See issue #69 for details.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-20 20:41:09 +01:00
Joachim Nilsson 37d391d53a doc/build.md: Remove mention of --enable-embedded configure option
As suggested in GitHub issue #68.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-17 16:55:02 +01:00
Joachim Nilsson d335c9833c It is difficult to write readable technical text.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:25:14 +01:00
Joachim Nilsson ab7df43ccb Clarify link target a bit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:17:05 +01:00
Joachim Nilsson ead92b3a27 Fix Markdown link
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:15:52 +01:00
Joachim Nilsson 647a79ffbd README: Add explanation of service early and link to doc/config.md
Also, update the service help text in doc/config.md to include info on
both runlevels and explain the condition in the listed example.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 16:09:40 +01:00
Joachim Nilsson 47793dcdf2 sm.c: Add missing header
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-03-08 08:26:13 +01:00
Joachim Nilsson 9df0454b64 initctl: Support for utmp show FILE
This patch adds support for showing a log rotated (uncompressed)
UTMP/WTMP file in initctl.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 11:44:57 +01:00
Joachim Nilsson 5ea1ac7582 Followup to #66: Gzip log files >= .2
This patch to the logrotate() function extends the log rotattion of a
file with a gzip of .2 and older log files.  If gzip is not available
in $PATH then @num files are left uncompressed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 11:00:17 +01:00
Joachim Nilsson 9f7604848c initctl: Remove no longer neede source files from build
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:21:27 +01:00
Joachim Nilsson bbbaba7b47 Minor cleanup
initctl: Replace daemon-only API from user tool
utmp-api.c: Remove not needed header

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:20:29 +01:00
Joachim Nilsson d56031db7d svc.c: Replace daemon-only logging API with API from err.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:19:00 +01:00
Joachim Nilsson 0f64e18f27 Relocate utmp_show() to initctl.c
Only used by this tool, no need to keep it in the shared utmp-api.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:17:41 +01:00
Joachim Nilsson 958cab8cc7 Relocate runlevel_string() to initctl.c
Only used by this tool, no need to keep it in helpers.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-02-10 10:11:52 +01:00
Joachim Nilsson 9974d65756 Fix #66: Rotate /var/log/wtmp log max:2, size:100k
This patch adds a simple log-rotate function to the UTMP, WTMP, BTMP,
and lastlog files.  Enabled by default, disable with:

    configure --disable-logrotate

Even though it can rotate /run/utmp it is unlikely this file will grow
that much during a system's uptime.

The hard-coded defaults are to keep up to two (2) previous versions
of the files and rotate on file size >= 100k.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-25 19:40:06 +01:00
Joachim Nilsson a0e17c8f47 Relocate create() from bootmisc plugin to helpers.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-25 19:40:06 +01:00
Joachim Nilsson f76268dec9 initctl: Fix build warnings after de4bf53
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-24 09:15:30 +01:00
Joachim Nilsson 8d74a12628 Fix #64: Skip fsck of already mounted devices
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-24 08:03:53 +01:00
Joachim Nilsson 33ae64495a finit.c: Mount /proc and /sys before fsck()
For issue #64 we need to have /proc/mounts, or /etc/mtab but that's
usually symlinked to /proc/mounts.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-24 07:57:19 +01:00
Joachim Nilsson 750712d28d Merge pull request #63 from mattiaswal/add-cond-dump
initctl: Add 'initctl cond dump' to show all conditions in the system
2017-01-18 19:06:48 +01:00
Mattias Walström de4bf53536 initctl: Add 'initctl cond dump' to show all conditions in the system
Remove verbose of initctl cond, and replace it with 'initctl cond dump'
Show all conditions if they are in flux/on even if there are no other
services depending on this condition.

Signed-off-by: Mattias Walström <lazzer@gmail.com>
2017-01-18 16:15:52 +01:00
Joachim Nilsson 205db919f5 Move service script: $PREFIX/bin --> $PREFIX/sbin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:43:24 +01:00
Joachim Nilsson 9b5d12bf22 Install service script wrapper in $PREFIX/bin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:37:55 +01:00
Joachim Nilsson 3b53dfcaed configure: Simplify description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:37:34 +01:00
Joachim Nilsson 1d39decaf1 Update .gitignore files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:32:09 +01:00
Joachim Nilsson 8129ea32aa Remnant of GIT submodule era
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:25:03 +01:00
Joachim Nilsson 2bf024d3c3 Remnant of the old build system
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 07:23:44 +01:00
Joachim Nilsson 19d89d627b Add src/.gitignore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:35:06 +01:00
Joachim Nilsson fff68b7b06 Relocate source files to an src/ subdirectory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:31:02 +01:00
Joachim Nilsson 044ded3045 Fix #61: Reassert net/* conditions after initctl reload
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:09:06 +01:00
Joachim Nilsson 0cccc629bf pidfile: Ensure svc is always followed by a slash
A service need no longer be fully qualified path.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:02:40 +01:00
Joachim Nilsson 57181264e9 pidfile: Make sure to set a default name for plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:02:16 +01:00
Joachim Nilsson 0b5888ed22 cond.c: Use utimensat() instead of utime() for nanosecond precision
We have repeatedly seen use-cases when sub-second resolution for
updatating the mtime of files have been needed.  Yes, all those
cases have been Autobots.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 01:00:10 +01:00
Joachim Nilsson 4321038518 bootmisc: Minor refactor
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-16 00:59:32 +01:00
Joachim Nilsson b84e32a6fe Add initctl log [SVC] command
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:21:19 +01:00
Joachim Nilsson 21a293beae Fix #60: initctl start/stop/restart ignores non-existing services
This patch improves the error handling of initctl so that it returns
non-zero if a service does not exist.

    $ initctl <start|stop|restart> SVC
    $ echo $?
    1

In verbose mode an error message is also returned:

    $ initctl -v <start|stop|restart> SVC
    No such service SVC
    $ echo $?
    1

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:15:10 +01:00
Joachim Nilsson 47b4850aa8 api.c: Factor out SVC|JOB:ID string parser
This patch breaks out the JOB:ID parser from api.c, placing it in a new
function called svc_parse_jobstr().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:12:53 +01:00
Joachim Nilsson 1999956d91 fixup! API: Show debug level in log after initctl debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:07:27 +01:00
Joachim Nilsson 698f736b65 Relocate and export sanitize() function
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:06:45 +01:00
Joachim Nilsson 618744cc52 fixup! Fix compiler warnings after do_sleep() relocation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 23:05:06 +01:00
Joachim Nilsson 67125fedab API: Show debug level in log after initctl debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 21:16:31 +01:00
Joachim Nilsson f7cd46abc9 API: Check input argument
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 21:15:58 +01:00
Joachim Nilsson 9f62153966 Whitespace: reindent and relocate function declaration(s)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 20:53:13 +01:00
Joachim Nilsson 978771a3fb Fix compiler warnings after do_sleep() relocation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-15 20:19:44 +01:00
Joachim Nilsson adc340e4c3 reboot: Use do_sleep() instead of sleep() to prevent wakeups due to SIGTERM
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:56:48 +01:00
Joachim Nilsson 50668161ad Move do_sleep() from helper.c --> util.c
This move makes it possible to share the code between the Finit daemon
and its client tools.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:55:44 +01:00
Joachim Nilsson 6507136bdd reboot: Mention why CMD_SUSPEND is not managed in regular flow
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:54:48 +01:00
Joachim Nilsson 5cdbd57875 reboot: Ignore SIGTERM at halt/poweroff
We want to emulate the behavior of the reboot() syscall on success.
Primarily for a coherency/symmetry, but also to prevent printing
a new shell prompt in the middle of system shutdown messages.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:48:00 +01:00
Joachim Nilsson 1550c34d65 reboot: Simplify applet transformation.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-13 07:47:29 +01:00
Joachim Nilsson ec6e3bc9e7 TODO: Minor update/clarification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-11 17:45:13 +01:00
Joachim Nilsson d5942f3267 Minor whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2017-01-11 17:40:10 +01:00
Joachim Nilsson e272710e36 Merge pull request #62 from mattiaswal/fix-fluxstate
Fix fluxstate
2017-01-11 17:21:27 +01:00
Mattias Walström a95df9d64b svc: The timestamp should have subsecond resolution
When finit completes quicker than one second it will
not find if any configurations has been changed.

Signed-off-by: Mattias Walström <mattias.walstrom@westermo.se>
2017-01-11 16:28:03 +01:00
Mattias Walström 816aa9a17c pidfile: Run the reconf-callback again until no application are in flux
If a service depend on the service last in the list the application
will be kept in flux state forever.

Signed-off-by: Mattias Walström <mattias.walstrom@westermo.se>
2017-01-11 16:25:04 +01:00
Joachim Nilsson f95cd38ddb Refactor #ifndef INETD_DISABLED --> #ifdef INETD_ENABLED
This patch changes the confusing logic in all #ifndef INETD_DISABLED
statements to instead be #ifdef INETD_ENABLED, which is quite a bit
more readable.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-30 13:34:31 +01:00
Joachim Nilsson d9de2717a2 Merge pull request #59 from reverendhomer/master
run: fix array overflow
2016-12-30 11:40:11 +01:00
Reverend Homer 11d5019103 run: fix array overflow 2016-12-29 14:31:28 +03:00
Joachim Nilsson 0946dbb287 Merge pull request #58 from reverendhomer/master
Another typo fix :)
2016-12-29 10:52:00 +01:00
Reverend Homer cfcdedd508 doc: fix typo in signals.md 2016-12-29 12:43:01 +03:00
Joachim Nilsson 3fac6ed6af Merge pull request #57 from reverendhomer/master
fix typo in config.md
2016-12-26 20:13:42 +01:00
Reverend Homer ef7497094c doc: fix typo 2016-12-26 20:44:08 +03:00
Joachim Nilsson de05070ccc tty: Debug messages when TTY is not started
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-25 10:35:51 +01:00
Joachim Nilsson f68daf1b14 Update ChangeLog with -rc2 fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-24 09:43:09 +01:00
Joachim Nilsson 88039f3d65 Fix #56: Check TTY before trying to start getty
This (initial) patch for issue #56 adds a very basic validation of the
device before attempting to start a getty on it.

TODO: Verify a USB/serial device can be plugged in at any point at
      runtime, either automatically start getty or by `initctl reload`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-23 23:11:53 +01:00
Joachim Nilsson 2c0421f2e6 Fix #54: Allow halt and poweroff despite --enable-watchdog
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-13 20:36:34 +01:00
Joachim Nilsson a672988e35 Merge branch 'fix-mpc85xx-getty-regression'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-12 22:30:08 +01:00
Mattias Walström 74f3a3f5c8 Actually disable modem specific flags
Signed-off-by: Mattias Walström <lazzer@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-12 22:29:02 +01:00
Joachim Nilsson f335e74cb8 Add missing #include <signal.h>, non GLIBC targets
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-09 07:29:45 +01:00
Joachim Nilsson 83915b42f3 Bump version for 3.0-rc2, second pre-release
All known major issues triaged or fixed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-09 01:03:18 +01:00
Joachim Nilsson babcd117b1 Fix #43: Add TODO for optimizing HTTP/HTTPS inetd redirect
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-09 00:56:39 +01:00
Joachim Nilsson 892ac2edb2 Fix #47: Relocate sysctl.conf setup to procps plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-08 08:17:38 +01:00
Joachim Nilsson 5b12d17b56 Fix #52: Add implicit "initctl reload" adter run-parts and rc.local
This patch (untested) patch calls `service_reload_dynamic()` after both
run-parts (if directory exists) and after `/etc/rc.local` has run.  The
intention is to reload any services modified/added/removed by a user
script so the system is properly up to date.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-08 01:43:32 +01:00
Joachim Nilsson 1b6930126e Fix #50: Reset TTY properly in stty()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-08 01:38:05 +01:00
Joachim Nilsson 8def97a465 Add missing ctype.h header for whitespace stripper
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-08 01:37:56 +01:00
Joachim Nilsson 7bbc0847b1 Unblock udp/wait parent inetd service on child exit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-07 23:31:54 +01:00
Joachim Nilsson 88dc3f0061 Strip leading whitespace from service -- description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-07 22:09:51 +01:00
Joachim Nilsson 02e69932ae Fix inetd regression introduced in 10b72f1
This patch allows all services to go from READY -> RUNNING, this to
prevent started inetd connections from being treated as "stubborn"
and inadvertently killing them off after a few seconds.

The same actually applies to run/task applications.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-07 21:51:54 +01:00
Joachim Nilsson 662dfbe777 Travis-CI: Update libuEv build dependency
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-05 08:43:48 +01:00
Joachim Nilsson c249cbdbe1 Remove duplicate header
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-05 08:40:29 +01:00
Joachim Nilsson a47171891f fixup! Make blocked state more generic
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-05 08:40:07 +01:00
Joachim Nilsson 1dc67acd40 chargen: Make sure to check target buffer size
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-05 08:37:41 +01:00
Joachim Nilsson 146685c2c2 Fix inverted --enable-quiet option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-12-03 06:15:46 +01:00
Joachim Nilsson 3cc2df20f9 Update minimum libuev requirement, v1.5.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-27 20:39:36 +01:00
Joachim Nilsson 4f3d246100 Make blocked state more generic
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-27 20:38:50 +01:00
Joachim Nilsson 11bfec1a23 Add missing header include guards
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-27 17:38:39 +01:00
Joachim Nilsson f24a03a32c Refactor little progname() for all applictions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-27 17:38:01 +01:00
Joachim Nilsson 829ff0b9f7 Fix #51: Catching SIGSEGV not needed anymore
This patch fixes issue #51 by reverting b4b63d3, which is not needed
anymore since service callbacks have been removed from Finit3.

The `sig_unblock()` function, called for each forked off child, should
now be balanced with caught signals.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-27 17:28:15 +01:00
Joachim Nilsson b9ae4d04ef bootmisc: Replace homegrown desym() with realpath()
Followup to issue #49.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-21 15:01:59 +01:00
Joachim Nilsson 47060c9738 bootclean: Resolve any symlinks in tmpfs check
Followup to issue #49.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-21 09:41:30 +01:00
Joachim Nilsson 846692ca03 Fix #49: Skip tmpfs directories at bootclean
We can safely skip tmpfs, nothing to clean from previous boot there.
In fact, if we clean it we may spoil things for udev, which saves
pre-boot files in /run/udev.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-20 19:29:42 +01:00
Joachim Nilsson 985d53bec4 Restore "udevadm settle" from 8f05b36, see #49
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-20 19:29:42 +01:00
Joachim Nilsson 8548e67dcd Update install warning text slightly.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-20 19:29:42 +01:00
Joachim Nilsson 1c60e949e7 Fix regression from bc84d66 preventing cond_update(NULL)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-18 13:32:55 +01:00
Wang He 86f02e8553 Fix ordering bug, progname() must be called before translate()
Signed-off-by: Wang He <xw897002528@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-12 16:51:29 +01:00
Joachim Nilsson 2c7332583c reboot: Fix build problem after prognm refactor.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-12 13:46:50 +01:00
Joachim Nilsson a96b74ea5e reboot: Replace __progname with a small function
This patch removes the use of non-standard __progname and replaces it
with a small function.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-11 21:28:19 +01:00
Joachim Nilsson 5a1b13ff41 Improve initctl show SVC output
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-11 21:27:08 +01:00
Joachim Nilsson 4a71f19c40 Code cleanup and improved svc abstraction
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-11-01 16:00:20 +01:00
Joachim Nilsson 5c672885f1 Minor cleanup of README, comments, and whitespace
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-31 19:07:43 +01:00
Joachim Nilsson e38eb7cbd5 Minor: relocate code to get rid of #ifdefs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:25:58 +02:00
Joachim Nilsson ba9ae0337d TODO: Good enough watchdog implementation now in place
This patch removes the long standing Watchdog daemon from the TODO list.
We now have a bare-bones watchdog service built-in to Finit, with
support for handing over to an external, and possibly more advanced,
using the initctl API.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:08:58 +02:00
Joachim Nilsson b674aad802 watchdog: Add simple built-in watchdog daemon
This patch adds a simple but effective watchdog daemon with support for
handover to an external daemon, should one register using the API.

Disabled by default, enable by:

    configure --enable-watchdog

The watchdog forks to the background, opening /dev/watchdog setting a
three second timeout, and kicking every second.  At shutdown/reboot the
daemon will receive SIGPWR from Finit to exit and cause a WDT reboot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:06:04 +02:00
Joachim Nilsson 88f9458c6e reboot: Wait a bit on successful signal delivery
To prevent returning the prompt too soon, and thereby messing up the
output from Finit, wait a bit after successful delivery of signal to
reboot/halt/poweroff.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:02:19 +02:00
Joachim Nilsson 6cb3d86cd1 Add support for registering a watchdog daemon
This patch adds initial support for registering a watchdog daemon with
Finit.  Needed for situations when you want the system to actually be
rebooted by the watchdog timer (WDT) circuitry rather than the kernel.

The initctl API has been extended with a INIT_CMD_WDOG_HELLO command
that is used to both register and "ping" Finit periodically.  As long as
Finit responds (with an ACK) the watchdog daemon knows Finit is alive.

At shutdown Finit stops all services (except kernel threads and daemons
marked with @ in the first character of their process name) and, if a
watchdog has registered, SIGPWR is sent to it when Finit has finished
unmounting etc., just prior to kernel reboot/halt/poweroff.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:02:19 +02:00
Joachim Nilsson 5cde809909 Add debug messages to signal handlers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:02:19 +02:00
Joachim Nilsson 1b6931eaea Protect API socket from unauthorized access
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:02:19 +02:00
Joachim Nilsson c3b7530b98 Reenable terse mode at shutdown/reboot
Now that we change runlevel at shutdown/reboot, we also need to restore
terse mode before calling the shutdown hooks, like before.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-24 00:02:18 +02:00
Joachim Nilsson 0f61b0792b Minor cleanup
No need to assign result = 0 since that is the default, also
no other case sets result to OK.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-23 13:10:20 +02:00
Joachim Nilsson bab13c9cef bootclean: Followup to a013e48, reduced verbosity
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-23 11:28:24 +02:00
Joachim Nilsson 9c9fe51eee Fine grained signaling of processes at shutdown
This patch replaces kill(-1, signo) with a more fine grained
do_kill(signo) that traverses each /proc/PID, skipping kernel
threads and special [0][0] == '@' processes.

The reason for this patch is not only future compliance with
freedesktop.org standards, but also a way of not killing any
critical processes at shutdown, e.g. mdadm or watchdogd.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-23 00:28:41 +02:00
Joachim Nilsson 4f8211f6a1 Beautify 'mount -a' error message at boot
This patch from TroglOS makes sure to print any error message from mount
after [FAIL] is printed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-22 18:36:51 +02:00
Joachim Nilsson 5fc3a0a3b9 Move HOOK_SHUTDOWN so it runs right before runlevel change
The shutdown hook is supposed to run right before services start
receiving SIGTERM.  Change due to previous refactor.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-16 23:06:17 +02:00
Joachim Nilsson 67c55145b9 Fix warning for comment in comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-10 00:03:08 +02:00
Joachim Nilsson fc2489d9e1 Remove or mark unused variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-10 00:02:45 +02:00
Joachim Nilsson a384a95529 Add missing warning flags and enable STD:GNU99
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-10 00:02:10 +02:00
Joachim Nilsson a013e48ab5 Run bootclean() from bootmisc plugin instead
This patch moves both the definition and the call to bootclean() from
finit.c to the bootmisc plugin.  We want to call bootclean() *after*
any /run and /var file systems have been mounted.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-09 23:15:06 +02:00
Joachim Nilsson 24a0ddfc59 Minor, remove TODO comment, fixed now.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-06 23:07:07 +02:00
Joachim Nilsson 3da4c2abe9 README: Add requirements to ToC
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-05 23:16:09 +02:00
Joachim Nilsson 2950820d34 README: Add requirements section
- New requirements section about what Finit expects from the system
- Remove commented out `udevadm settle` code, now in README

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-05 23:14:21 +02:00
Joachim Nilsson 75b1ac8199 Fix CID 171497, ignore return value from remove()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-04 12:37:36 +02:00
Joachim Nilsson 8f05b36551 Do not call udevadm settle, only Debian uses this
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-04 12:12:59 +02:00
Joachim Nilsson 0f840e6576 Do not force silent mode on udev systems
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-04 12:12:59 +02:00
Joachim Nilsson 451f63ebe0 Clean up unused local variables
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 23:11:49 +02:00
Joachim Nilsson 2dc9daf118 Clear screen in silent mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 23:10:49 +02:00
Joachim Nilsson 3c67a10347 Actually unblock signals for child processes
Also, make them session leader so they can manage their own offspring if
needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 23:08:39 +02:00
Joachim Nilsson 6885a9f868 Systems with udev/udevadm mess up /dev/console => silence console
On systems with systemd-udev/udevadm the trigger addition of devices at
boot wrecks havoc of /dev/console.  This patch forces Finit to go silent
by default on such systems.  Far from ideal, but since the actual root
cause for this messup is unknown this will have to do for now.

Also, add a settle timeout of 120 sec to the udev device tree population.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 23:08:18 +02:00
Joachim Nilsson 38142baa93 Do not fork external process, use sync(2) instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 14:06:06 +02:00
Joachim Nilsson 34bdbdb3b1 resolvconf: Simplify and fix buglet
- The /dev/shm/ directories are no longer needed
- Do not create the resolv.conf symlink

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 13:14:16 +02:00
Joachim Nilsson 83af7e8e9d resolvconf: Initial cleanup of plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 13:06:03 +02:00
Joachim Nilsson 4eb5f8a0dc bootmisc: /var/lock/subsys created by D-Bus plugin
No need to create it twice.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 12:05:27 +02:00
Joachim Nilsson e03b358ff0 Fix #46: Set correct umask() before makedir() and chmod()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 11:42:40 +02:00
Wang He d2846b805a Fix issue #42: Skip base directories in bootclean.
Signed-off-by: Wang He <xw897002528@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-10-02 11:07:54 +02:00
Joachim Nilsson 07d767e1af Fix issue #42: Use ftw() to recursively clean up dirs.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-30 23:01:26 +02:00
Joachim Nilsson d423e6b774 doc: Reminder about conditions for run/task/service/inetd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-26 21:43:56 +02:00
Joachim Nilsson bb89bdd8a9 Refactor fallback handling in getent()
This patch factors out the fgetint() fallback code for parsing
/etc/services and /etc/protocols.  Useful on systems with a
malfunctioning C library.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-26 21:42:34 +02:00
Joachim Nilsson 5cc98f6e53 inetd: List service/proto in error message
Improve error when failing to register an inetd service.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-26 21:41:28 +02:00
Joachim Nilsson a6300f6ac6 Fix warning on 32-bit ARM: 2 << 31 overflows int
Thanks to GCC 6.1 for finding this.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-26 21:40:31 +02:00
Joachim Nilsson aeabb4d2ea Realign logo and mention systemd
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-21 15:40:27 +02:00
Joachim Nilsson dcbb429863 Remove logo HTML+CSS alignment screws up rendering
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-21 15:11:14 +02:00
Joachim Nilsson 077d52d209 Attempt new right-floating logo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-21 15:09:55 +02:00
Joachim Nilsson 44f5de188d Update screenshot to Finit3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 19:04:55 +02:00
Joachim Nilsson 191e5440b2 tty.c: Fix minor regression from f9732a6
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 18:52:56 +02:00
Joachim Nilsson a2b0d00058 reboot: Add poweroff symlink, now also supported
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 18:32:53 +02:00
Joachim Nilsson e8fa827026 README: Further cleanup and refactoring
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 18:32:38 +02:00
Joachim Nilsson 89105090ed Massive update, cleanup of README
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 16:53:20 +02:00
Joachim Nilsson 6ce218612b Fix build warnings if fallback shell is disabled
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 12:11:07 +02:00
Wang He dd87c81adc Create missing /var/lock/subsys dir in dbus plugin
Signed-off-by: Wang He <xw897002528@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 12:09:05 +02:00
Wang He 37f3478873 Run udev triggers to add subsystems and devices
Without trigger, kernel modules won't be loaded automatically.  Also
devices are not managed.  For example, i915 was not loaded after boot
and my network card was not renamed from wlan0 to wlp3s0, which means
it was not handled properly by udev.

Signed-off-by: Wang He <xw897002528@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 12:06:12 +02:00
Wang He a64259362e Clean up hidden dot files from /tmp
Signed-off-by: Wang He <xw897002528@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 12:02:36 +02:00
Wang He 3554138118 Sync needed before remount R/O
Signed-off-by: Wang He <xw897002528@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 12:00:16 +02:00
Joachim Nilsson f7d6d269c7 Change to runlevel 0/6 on reboot/halt/poweroff
This patch fixes a long-standing issue with how Finit handles shutdown,
reboot and poweroff -- and even runlevel changes to runlevel 0 and 6.

Prior to this patch sig.c:do_shutdown() was called immediately on any
of the above events, disregarding any services that a user might have
wanted to run as part of the shutdown/reboot.

With this change the handling is unified in all frontends to instead
do a runlevel change followed by the do_shutdown() action.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 11:50:07 +02:00
Joachim Nilsson 2c1e9877f9 Touch /etc/nologin when runlevel change comes in
The /etc/nologin file must be set as soon as the runlevel change to
0/1/6 comes in, not when done with runlevel change and services have
been started, if any.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 11:24:10 +02:00
Joachim Nilsson a94c97221e Force all log messages to console in --debug mode
As a last ditch effort to understand why an embedded system doesn't
boot, the operator should be able to see as much logs as possible
when enabling --debug mode on the kernel command line.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 10:27:03 +02:00
Joachim Nilsson f9732a6fb9 Fix warnings: type mismatch and unused parameters
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 10:27:03 +02:00
Joachim Nilsson 581fc956be Staticify local variable
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 10:27:03 +02:00
Joachim Nilsson ee901b018c Finit bringup: add optional fallback shell
This patch adds an `--enable-fallback-shell` option to confiugre.
When enabled Finit will start `/bin/sh` on the console, but only
if there are no active TTYs running in the current runlevel.

With this it will be easier to do board bringup with Finit, but it also
enables using the fallback shell in a rescue mode (runlevel) where no
TTYs are allowed to run.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-18 10:27:03 +02:00
Joachim Nilsson d373ebfdd7 New function tty_num_active()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-17 22:52:21 +02:00
Joachim Nilsson 698b87dd35 Clean out remnants of old (now unused) fallback shell
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-17 21:09:45 +02:00
Joachim Nilsson dd566acfd2 Update ChangeLog and bump version for v3.0-rc1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-14 00:04:00 +02:00
Joachim Nilsson 5c56f5c5a7 Fix make distcheck: Add missing header file to build deps.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 23:02:01 +02:00
Joachim Nilsson 7ab963a576 Remove eXecutable flag from source files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 23:00:06 +02:00
Joachim Nilsson 73d462c847 utmp_set(): Fix uninitialized return value
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 22:47:16 +02:00
Joachim Nilsson 56e94a4e4a Merge branch 'westermo-usr/wkz/timeout'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 21:56:39 +02:00
Joachim Nilsson 51830e0f5b Merge branch 'usr/wkz/timeout' of https://github.com/westermo/finit into westermo-usr/wkz/timeout 2016-09-13 21:53:26 +02:00
Joachim Nilsson 85115eca62 Fix invalid ptr assignment for --enable-static builds
Also changes the default to set $HOME to / instead of nothing.  This can
of course be improved immensely.  Pull requests always welcome ;-)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 21:41:36 +02:00
Joachim Nilsson 659ff9962e Fallback (unused) PLUGIN_PATH for --enable-static builds
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 21:41:11 +02:00
Joachim Nilsson 9436c8b73c Minor whitespace cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 21:25:40 +02:00
Joachim Nilsson 5a3397419f Remove support for service callback plugins
This patch removes the now heavily outdated (and non-working) support
for callback plugins.  I.e. plugins that attach themselves to services
listed in /etc/finit.conf and can be queried to determine if a service
should be started or stopped.

The Finit3 support for adding/removing services at runtime with plain
text *.conf files in /etc/finit.d and `initctl reload`, this old, and
rather cumbersome service callback feature, is not longer supported.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-13 21:20:06 +02:00
Tobias Waldekranz 10b72f1d7f service: kill stubborn services, wait before restart
Add support for registering callbacks to be called after a given
timeout.

Use this to implement forceful termination of services that refuse to
terminate upon receiving a SIGTERM. If the service PID is not collected
within 3 seconds, send a SIGKILL to it.

Also, rework restarting of crashing services. When a service crashes for
the first time, try to restart it immediately. If it crashes again, wait
a few seconds before trying again. Just as before, if it continues to
crash, block the service.
2016-09-13 20:26:28 +02:00
Joachim Nilsson 6b237b7b00 Refactor abstraction of svc blocking state
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-12 19:30:48 +02:00
Joachim Nilsson b4f385d2e0 Only log to stderr if opening /dev/kmsg failed for early logging
This patch prevents double critical/error messages from being printed on
the console when there is no syslog daemon running yet.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-08 17:11:52 +02:00
Joachim Nilsson 4b4572de4d Minor refactor of error/debug messages
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-08 17:11:27 +02:00
Joachim Nilsson 19b81cf434 Fix #40, #39: initctl plugin started too early, before /run FS existed
Delay setup of initctl plugin to after the base filesystems are up and
after the bootmisc plugin has run.

This patch factors out the I/O initialization of plugins so it does not
have to run when plugins are loaded.  Instead, plugins can now call this
API to register an I/O callback when they are ready.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-08 12:58:28 +02:00
Joachim Nilsson 3023433def Do not write DEAD_PROCESS records to UTMP, only WTMP
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-08 12:51:32 +02:00
Joachim Nilsson 49968c188b UTMP: Make sure to use the full width of all UTMP fields
In UTMP a terminating zero in string fields is optional, so we need to
take that into account when preparing entrys.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-08 12:51:20 +02:00
Joachim Nilsson 2499405b27 Misc. whitespace fixes, and comment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-06 00:08:40 +02:00
Joachim Nilsson 9fc1f50678 bootmisc: The getgroup() API returns int not gid_t
Must use int to check for error code (-1) from getgroup() API.
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:55:21 +02:00
Joachim Nilsson b1d709ba22 reboot: CMD_SUSPEND not handled atm by Finit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:54:52 +02:00
Joachim Nilsson 5ddc35d387 echo: Mark callback argument as unused
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:54:29 +02:00
Joachim Nilsson 50632f941b Fix missing initializer for array end marker
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:46:15 +02:00
Joachim Nilsson 7b215e4fd4 Update dependencies for libuEv and libite (-lite)
This patch makes Finit require libuEv v1.4.2, a minor bugfix update, and
libite (-lite) v1.8.2, which is quite a bit more than just a few bug
fixes.  The most relevant fixes are the removal of implicit logging for
touch(), makedir(), makefifo(), and erase() inline functions.  The
release also removed implicit logging to stderr on error, as well as a
a few build fixes for running on musl libc.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-05 00:24:55 +02:00
Joachim Nilsson bb7208c591 bootmisc: Check return value from chmod() API
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 23:23:37 +02:00
Joachim Nilsson bb0505f57c bootmisc: Check return value from getgroup() API
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 23:13:51 +02:00
Joachim Nilsson 4aa569de44 Fix descriptor leak in getty()
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 23:03:42 +02:00
Joachim Nilsson 512a07a25c Fix resource leak if tty_register() fails (minor)
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 22:55:21 +02:00
Joachim Nilsson 8cfd11c909 Use safe string copy using strlcpy()
Fixes issues with buffers not being NUL terminated properly.
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 22:52:34 +02:00
Joachim Nilsson c3adf3bf51 Bump version to v3.0-beta2 no more feature expected
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 20:48:49 +02:00
Joachim Nilsson 3ca28e765d Fix #38: Add --enable-emergency-shell fallback debug mode
This patch adds a very special debug mode to Finit.  With this feature
enabled the actual duties of PID 1 is forked off early to a child.  If
that child ever dies, usually due to a SIGSEGV, this wakes up the real
PID 1 which lauches a debug shell on the console.

Remember to disable 'quiet' and enable '--debug' on the kernel command
line to get all the debug logs -- which these days goes into the kernel
log in /dev/kmsg -- simply `cat /dev/kmsg` and use Ctrl-C to get the
shell prompt back.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 20:27:12 +02:00
Joachim Nilsson 79207dcb22 Support for starting finit-getty with a given user
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 20:02:59 +02:00
Joachim Nilsson 47f3e2ca04 Clarify what --disable-quiet actually does
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 18:40:58 +02:00
Joachim Nilsson 2e7bee9f84 Fix #36: Don't delete inetd on failed registration
This patch fixes to root cause to issue #36, reported by Markus Svilans.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:22:50 +02:00
Joachim Nilsson 2681e4c01a Add early logging support to /dev/kmsg
Very early, before syslogd has started, we have traditionally been
forced to use stdout/stderr for debug, warning and error messages.

With this patch we can now rely on /dev/kmsg to preserve all logs
from early Finit problems.  When syslogd/klogd starts up they read
/dev/kmsg and copy logs to /var/log/* files.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:19:06 +02:00
Joachim Nilsson 56a3f6882b Improve inetd service registration
- Refactor getent() for improved separation and readability
- Warn and exit if /etc/protocols or /etc/services is missing

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:17:22 +02:00
Joachim Nilsson 88d8ab67c9 Add _w() for developer warning logs
Adjust debug levels slightly and add _w() macro for LOG_WARNING,
useful when having /dev/kmsg as backend.  The latter outputs any
log <= LOG_ERR to console as well.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:15:41 +02:00
Joachim Nilsson 74eb2bf4d2 initctl: Add dependency on bootmisc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 17:13:38 +02:00
Joachim Nilsson b3fb9ab3ed Fix placement of newline for early debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-09-04 16:10:23 +02:00
Markus Svilans 308ae609c4 Fix #35: Build fails with --disable-inetd
This patch fixes a build problem when configured without inetd support.

Signed-off-by: Markus Svilans <msvilans@aeonyx.ca>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-31 16:30:04 +02:00
Joachim Nilsson e3783e8bac README: Fix spelling error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-26 21:36:04 +02:00
Joachim Nilsson 002b24fbc2 README: Improve ingress
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-26 21:34:36 +02:00
Joachim Nilsson 3f71ed352d initctl: Remove confusing/wrong debug message
The 's' runlevel after boot is the traditional single-user rescue mode.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-24 22:08:46 +02:00
Joachim Nilsson f7305c36b8 reboot: Clarify -f, --force option in usage text
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-24 22:08:26 +02:00
Joachim Nilsson 8bcecd474b Refresh telinit client
- Add support for SysV init setenv to activate poweroff
- Update help text considerably to be more helpful

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-24 20:26:09 +02:00
Joachim Nilsson a9a7b08021 Disable login also in shutdown/reboot
Disable login in single-user mode as well as shutdown/reboot

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-24 19:27:23 +02:00
Joachim Nilsson 62cb683af0 initctl: Show WTMP log first and active UTMP last
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-23 16:35:44 +02:00
Joachim Nilsson 65e44dc88f UTMP: By convention, getty has user "LOGIN"
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-23 07:49:32 +02:00
Joachim Nilsson 54467d4467 configure: Minor whitespace changes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-22 12:39:51 +02:00
Joachim Nilsson cfa258e7f2 UTMP: Log to /var/log/wtmp as well as /run/utmp
The UTMP db tracks currently logged in users and WTMP is an audit trail
of all user logins and logouts, as well as runlevel changes and reboot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-22 12:36:17 +02:00
Joachim Nilsson 574760df13 UTMP: Set LOGIN_PROCESS for built-in getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-22 12:36:03 +02:00
Joachim Nilsson c2ec25efd3 Use logit() for _d() and _e() messages as well
The new logit() function takes care to print to stderr if syslogd has
not yet started.  The _d(), _e(), and _pe() macros have an additional
requirement: to always print on stderr.

After the boot we also want to see what happned during, so this patch
simply adds syslog() support to _d(), _e(), and _pe().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-18 01:48:41 +02:00
Joachim Nilsson d670e7d3e8 Clean up logging, log to stderr until syslogd has started
This patch removes internal logging macros and adds support for logging
to stderr until a syslogd is up and running, i.e. /dev/log appears.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-18 01:18:31 +02:00
Joachim Nilsson 77561b6071 Replace old ANSI helper macros with libite/conio.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-18 00:39:59 +02:00
Joachim Nilsson cec1c64755 Fix build on older (G)LIBC's w/o RB_SW_SUSPEND
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-18 00:11:11 +02:00
Joachim Nilsson 5bab329178 UTMP: Only account for getty processes
This patch removes accounting for all processes to instead implement the
traditional SysV getty accounting.  (Telnet/SSH et al maintain their own
accounding for UTMP.)

TODO: WTMP support

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-17 18:43:49 +02:00
Joachim Nilsson b6bf8bf518 Fix GRUB menu entry generation for Debian & Ubuntu
This patch fixes the /etc/grub.d/40_custom generation for the Debian
sample so that it properly extracts the UUID For /boot and /

Note: the maintenance free symlinks /vmlinuz and /initrd.img may not
work properly with /boot on a separate partition or disk.  If only
the symlinks where in /boot as well ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-15 02:26:01 +02:00
Joachim Nilsson 0a21ff5236 Update Alpine configure example
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-15 02:25:13 +02:00
Joachim Nilsson 3853061f09 Remove --enable-embedded configure option
Instead of ugly #ifdefs we now probe for mdev or udevd at runtime.  Take
care to check for udev-finalize and location of udevd, it differs a lot
between distros.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-15 00:25:07 +02:00
Joachim Nilsson 078982d3ec Initial support for mdadm RAID arrays
This patch adds initial support for handling MD RAID arrays.  Adding
a pass at the very end of the shutdown sequence to signal any external
RAID controller to clear its state before we proceed to halt/reboot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 21:26:18 +02:00
Joachim Nilsson f4327910d9 Only unmount non-protected filesystems at shutdown
This patch adds support for a more fine grained approach to what
filesystems are unmounted at shutdown/reboot.  This so we later
can add support for `mdadm --wait-clean --scan`, which relies on
/proc, /sys, and /dev being there before we call reboot().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 21:09:15 +02:00
Joachim Nilsson b1fb536468 reboot: Remove sync() is up to user to do that
Also, this code will be refactored soon to be a part of the finit
binary, like telinit, and then we will be called after unmount to
do a forced halt/reboot/poweroff.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 13:29:58 +02:00
Joachim Nilsson 95cb94cf49 Remember to shift use state machine in sig.c:do_shutdown()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 13:26:27 +02:00
Joachim Nilsson e1c0e7fe58 Add install/uninstall for reboot symlinks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 13:20:48 +02:00
Joachim Nilsson 9783e120af Fix install/uninstall of Finit symlinks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 13:20:27 +02:00
Joachim Nilsson 3ad149fb28 Workaround for uninstalling .so plugins
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 13:19:35 +02:00
Joachim Nilsson e6430aabc2 Update and remove services script from distribution
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 13:19:20 +02:00
Joachim Nilsson 2743a49d91 reboot: Add halt/poweroff/suspend and force cmd
This patch is a complete rewrite of the Finit reboot command.  Not only
does it bring it up to speed with the new signal model, but it also adds
new features like poweroff, halt, and suspend -- including a forced mode
that goes for reboot(2) immediately.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-14 12:27:52 +02:00
Joachim Nilsson 6f99c1db05 initctl: Add missing signal.h include for older systems, e.g. Travis CI
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-11 00:03:20 +02:00
Joachim Nilsson 0eafe8bcd9 initctl: Show error message when trying to signal PID 1 as non-root
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-10 21:39:09 +02:00
Joachim Nilsson b01fae03ec Copy all chars of UTMP fields: id, line, and user
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 20:35:44 +02:00
Joachim Nilsson dbbe6b31b8 UTMP: Fix runlevel regression after refactoring
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 20:35:03 +02:00
Joachim Nilsson 2718c709aa UTMP: Add support for INIT_PROCESS & DEAD_PROCESS
Services started by Finit are now properly accounted for in UTMP.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 00:58:00 +02:00
Joachim Nilsson 8c54fde36c Fix D-Bus plugin, remove old #ifdefs
Still TODO, replace `run_interactive()` start of dbus-daemon with a
proper service.  Possibly only service_register() is needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 00:12:47 +02:00
Joachim Nilsson 0d1bc167ff initctl: Fix display of UTMP records, add IP addr
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 00:12:47 +02:00
Joachim Nilsson f8def336d4 Fix ordering of UTMP events: reboot, then runlevel
This patch fixes the ordering of UTMP events. The first event that is
expected in /var/run/utmp is reboot, next is the runlevel change to
the configured runlevel, e.g. from S --> 2.

Let the bootmisc plugin handle this, it knows when /var/run/utmp has
been created and is writable.  It is not the eact boot time, but close
enough for most usees.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-09 00:12:47 +02:00
Joachim Nilsson addc21bdf6 UTMP: Set BOOT_TIME record and add shutdown
This patch adds support for initializing /var/run/utmp with the initial
reboot as well as a shutdown record in the UTMP db.

Also, the run level change now properly records ~ and ~~ as line and id,
respectively, and the kernel release and time of each UTMP record is now
set properly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-08 19:06:35 +02:00
Joachim Nilsson 27899feea0 bootmisc: Add /var/log/btmp 0600 support
The file /var/log/btmp holds bad login attempts and must be created with
0600 perms.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-08 00:05:34 +02:00
Joachim Nilsson a016359891 Factor out runlevel handling to new UTMP API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-07 22:36:31 +02:00
Joachim Nilsson 7cdd42195b initctl: Break out UTMP logic to separate file
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-07 22:22:42 +02:00
Joachim Nilsson 07f06c8b95 inictl: Enable UTMP dump command
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-06 18:51:25 +02:00
Joachim Nilsson 2067fd597f initctl: Raw UTMP dump tool
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-06 18:49:22 +02:00
Joachim Nilsson f0318b0df0 Rephrase
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 17:46:44 +02:00
Joachim Nilsson 508c7b225a Prune completed TODO items
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 17:45:58 +02:00
Joachim Nilsson 8a79b05a97 Add missing bracket
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 17:45:25 +02:00
Joachim Nilsson 7b07d5559c Service status 'crashing' --> 'crashed'
Minor coding style cleanup, code simplification, and change service
'crashing' status text to 'crashed' to fit column width.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 17:43:45 +02:00
Joachim Nilsson 23cdd6e438 Update Debian HowTo with new build.sh script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 01:16:35 +02:00
Joachim Nilsson 576cb1075c Boiler plate README for contrib/ section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 01:06:23 +02:00
Joachim Nilsson fc74fb110d README: Further simplication of example in ingress
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-05 01:06:20 +02:00
Joachim Nilsson baa914e995 initctl: add reboot, halt, and poweroff commands
Simple wrappers for the signals Finit responds to.  Will need complete
rewrite when support for delayed reboot/halt is added.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-04 22:45:05 +02:00
Joachim Nilsson 6490735ee9 Remove flux condition emulation, confusing to user
The condition flux state does not work like that, so keeping
this sub-command is only confusing to the user.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-04 22:40:20 +02:00
Joachim Nilsson 13159ea99a Mention support for Debian and Alpine early!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-04 00:38:45 +02:00
Joachim Nilsson b9fa0f85a2 Update inline documentation for Debian finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-03 11:12:56 +02:00
Joachim Nilsson dbbe3cecb3 Debian helper build & install scripts
These scripts help a user to configure, build, and install Finit
correctly on a Debian 8 (Jessie) server install.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-03 10:58:45 +02:00
Joachim Nilsson 1a8f1d9604 getfsent(): Read only six fields per line
The fs.fs_type is only for *BSD, we hard-code it to "rw"
in the meantime.  Should be safe in most cases.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-02 02:01:51 +02:00
Joachim Nilsson d76ecad517 fsck: Prevent debug during interactive fsck
The debug mode cannot be used in run_interactive() that early, so we
must disable it during the complete fsck run.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-02 02:00:01 +02:00
Joachim Nilsson f81750e0b1 fsck: Skip progress, does not work the same with BusyBox fsck
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-02 01:59:14 +02:00
Joachim Nilsson 7fc7faf59a fsck: Prevent double-checking filesystems
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-02 01:58:41 +02:00
Joachim Nilsson c38b452ac4 Add set/get/endfsent() support for musl libc
This patch adds support for the following /etc/fstab API's on systems
that do not have them, e.g. musl libc on Alpine Linux.

- setfsent()
- getfsent(), and
- endfsent()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-02 00:50:23 +02:00
Joachim Nilsson 7eac88b639 Run fsck earlier and print only first 13 chars
Run fsck much earlier, as soon as we can in fact.

The first 13 characters of the UUID, label or device name should
be sufficient to identify the device, without violating max width
of 78 chars.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-01 23:51:11 +02:00
Joachim Nilsson f374f443f4 Allow fsck on UUID= and LABEL= devices
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-01 23:38:55 +02:00
Joachim Nilsson d2a5e65862 Support for checking file systems from /etc/fstab
This patch adds support for running fsck on all file systems listed in
/etc/fstab with a passno > 0.  The fsck runs sequentially, starting with
the root fs (passno 1).

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-08-01 18:08:54 +02:00
Joachim Nilsson 501deae4ed Update doc, support sysctl from all the locations!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-31 10:21:15 +02:00
Joachim Nilsson 2c29893558 Prune old (and now irrelevant) TODO items
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-31 10:16:52 +02:00
Joachim Nilsson a1a7f69349 Update info on getty, no /bin/login included
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 16:06:35 +02:00
Joachim Nilsson 8d9fbea551 Micro adjustment
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 16:03:32 +02:00
Joachim Nilsson 1d89e1a706 Advertise for new logo ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 16:02:51 +02:00
Joachim Nilsson 596b7cc413 README: Mention built-in getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 16:00:31 +02:00
Joachim Nilsson fbed5cd8cb TODO: Timed shutdown/reboot incl. cancellation
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:55:59 +02:00
Joachim Nilsson 0cb1ce2483 Disable clear screen in getty
Disabled until we decide on config to disable/enable.  It is quite
annoying to not be able to see the boot messages with it on ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:54:37 +02:00
Joachim Nilsson e23b62ffb7 Plugin loader fixes for dep handling and unload
- Plugins without declared name registered with full path + ext
  => Strip path and extension
- Plugins registered with __NAME__ => strip extension
- Do *not* call dlclose() from destructor, must be called by Finit

Also, some minor cleanup and code simplifcation.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:54:37 +02:00
Joachim Nilsson 94d41e38f8 Close inotify watcher when TTY plugin is unloaded
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:54:37 +02:00
Joachim Nilsson 42800a1cc8 ALSA plugin: only run if /usr/sbin/alsactl exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:54:37 +02:00
Joachim Nilsson 4cf60b7491 initctl: Add SysV compat support for setenv
- Fix compat INIT_CMD_ defines so Finit clients can talk to SysV init
- Add setenv support, only for INIT_HALT={POWERDOWN,HALT} to runlevel 6

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:54:37 +02:00
Joachim Nilsson 72a9832662 Remove developer debug of reboot/umount sequence
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-30 15:54:37 +02:00
Joachim Nilsson eeb59eb22b Adopt BusyBox init signal handling for halt/reboot/poweroff
This patch adopts the BusyBox init signals for handling halt, reboot,
and poweroff.  The SIGINT and SIGPWR signals still behave the same as
before, even though they likely will become configurable in a future
release.

Note: the disabling of Ctrl-Alt-Delete (SIGINT) is also removed!

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-29 16:47:38 +02:00
Joachim Nilsson 0df0f019e3 Alpine Linux finit.conf updates
First lessons from Debian, more to come ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-29 01:08:48 +02:00
Joachim Nilsson bc7f6f1bc1 Debian HowTo: Minor fixup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-29 00:22:32 +02:00
Joachim Nilsson 73b807a007 Debian HowTo: Minor reformatting
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-29 00:20:46 +02:00
Joachim Nilsson 62113a0057 New mini HowTo: Finit on Debian Jessie
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-29 00:13:03 +02:00
Joachim Nilsson 968f1bf991 The science of unmounting file systems on Debian
That's maybe a bit unfair.  This patch implements a brief version of
what is really needed to safely unmount all file systems on a modern
Linux distribution.  Yes, it's this insane.  (Who am I kidding, it's
worse!  Just have a look at the ancient scrolls hidden in your /etc!)

Here is where we use the new plugin_exit() and api_exit() API's from an
earlier patch.  Making sure to exit and close any kernel descriptors.
Then follows a bizarre spell cast on leaking descriptors, rebooting in
a child, remounting / as read-only, and a whole slew of other R rated
stuff to prevent mount/umount from returning 32 ...

Stay safe people, use protection always!

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:39 +02:00
Joachim Nilsson 57514130fc Starting service as @user chdir() to their $HOME
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:39 +02:00
Joachim Nilsson 0710fdd2a3 Plugin and API init/exit for conformance
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:39 +02:00
Joachim Nilsson 08e46782e5 Print banner earlier
Thanks to udev we need to do a lot more stuff even earlier these days.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:39 +02:00
Joachim Nilsson b96d8d3055 Handle tabs in finit.conf better
Should probably be extended to handle any non-space blank character.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:38 +02:00
Joachim Nilsson 4ede2a93b2 Change initctl FIFO from /dev/ to /var/run/
FIFOs, PID files, and other non-devices belong in /var/run (or /run
these days), not /dev -- as per FHS.  Compat with Debian SysV init.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:38 +02:00
Joachim Nilsson dd2eb9ce04 Initial contrib/debian support for Jessie
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:38 +02:00
Joachim Nilsson d15633781b TTY: Major overhaul, move to built-in getty
The TTY handling in Finit has always been a bit of a patch work.  This
commit is an attempt at a first cleanup and simplification.

Included is a brand new built-in getty which should work fine on both
virtual and serial consoles.  It is however completely untested on the
latter serial consoles.

Still TODO: add support for /etc/securetty, add support for actually
setting TERM when calling /bin/login.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-28 23:48:38 +02:00
Joachim Nilsson 789354ab40 Improve udev support on non-embedded systems
Embedded Linux systems usually employ BusyBox mdev.  This patch assumes
that all non-embedded systems employ udev.  Adding support for cleaning
up the udev db after the initramfs, or mounting /dev if that not done.
It also runs the udev-finish script at the end.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-27 19:28:42 +02:00
Joachim Nilsson 8002704a5f bootmisc: Create /var/run/network/ for ifupdown
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-27 19:25:50 +02:00
Joachim Nilsson 82853bf0ea Add support for ifupdown 'allow-hotplug' keyword
Look for 'auto' *and* 'allow-hotplug' in /etc/network/interfaces when
bringing up Debian/BusyBox interfaces at boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-27 19:25:19 +02:00
Joachim Nilsson bfe9e011bd Remove fallback to /bin/sh if no TTY is defined
If the user specifies no 'tty /dev/ttyN' in finit.conf this code
took upon itself to add a backdoor to the system.  Let's remove
it and rely on the operator deciding what is best practise.

With this patch no getty, or fallback shell, will be started if
no tty line in finit.conf is available.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-27 19:14:36 +02:00
Joachim Nilsson 9416e14074 Minor cleanup and default signals also for getty
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-26 21:13:19 +02:00
Joachim Nilsson 46a58f058a Simplify, simplify, simplify ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-26 01:29:31 +02:00
Joachim Nilsson 72a484b639 Break out building and bootstrap to separate files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-23 00:25:14 +02:00
Joachim Nilsson 82e483d6c7 Start splitting up the README into separate files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 23:31:57 +02:00
Joachim Nilsson dafa50ee42 Add links to dependencies in build section
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 23:07:25 +02:00
Joachim Nilsson 2187e05e06 Update build instructions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 22:59:08 +02:00
Joachim Nilsson a4fd058607 Update example finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 22:58:43 +02:00
Joachim Nilsson c49eb5e10d Replace classic Finit rally car with retro ASCII logo
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 22:57:55 +02:00
Joachim Nilsson 01d1dabaae Remove useless hostname debug
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 22:44:39 +02:00
Joachim Nilsson a3b0022d66 Minor cleanup and additions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 20:00:13 +02:00
Joachim Nilsson e4d882e99e Fix ToC links and add finit.conf example
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 19:29:23 +02:00
Joachim Nilsson 5ef426d424 Link to files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-22 19:28:14 +02:00
Joachim Nilsson 5ee1b7c322 Name waiting-for-enter to getty process
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 20:43:23 +02:00
Joachim Nilsson 0d665f3773 Correct adjustment of initctl show columns
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 16:48:29 +02:00
Joachim Nilsson 38619966ee Fix interface bring up message NULL ptr deref
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 16:35:57 +02:00
Joachim Nilsson 6380f17d1f Prototype support for /etc/netork/interfaces
This patch adds prototype support for the Debian/Ubuntu/Busybox network
configuration file /etc/netork/interfaces.  If this file exists Finit
will call `ifup` for each (non-commented-out) interface marked `auto`.

With this implementation we block boot until all ifup commands have
returned, which is less than ideal.  A better approach would be to ifup
only loopback and create deferred tasklets to be run in parallel with
the rest of the boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 16:11:50 +02:00
Joachim Nilsson 42181a3031 Add OpenRC-like support for sysctl.d/*.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 15:49:00 +02:00
Joachim Nilsson 77b32ebff0 Update Alpine Linux example config
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 15:37:15 +02:00
Joachim Nilsson 97de3ad0bb Slight adjustment, plus 1, to allow 79 char width
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 15:15:26 +02:00
Joachim Nilsson 44f8a2666f tty: Always detach from initial TTY and open actual /dev/ttyN
This patch fixes a long standing problem with TTY's.  The original code
tried to workaround a limitation in the console of some embedded systems
that was detrimental on actual TTYs.

As an added benefit, the console specific "Press Enter" prompt for the
console port is now available on all TTYs -- meaning no getty needs to
be started and kept needlessly in the background until it is needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 14:57:58 +02:00
Joachim Nilsson 4cf5b055cf Adjust max width to 79 chars in text output
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 14:28:03 +02:00
Joachim Nilsson 744bb9dd14 Workaround for loopback interface
We never get any NEWLINK message for lo since it as an interface exists
very early.  So we add this workaround when lo comes up so services can
depend on exists for lo as well as for other interfaces.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 14:04:37 +02:00
Joachim Nilsson 1edfecdaab Use -v to also dump asserted condition flags in cond show
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 13:53:51 +02:00
Joachim Nilsson bc84d66018 Allow conditions for tasklets and runlets as well
The introduction of conditions to Finit only focused on
services (monitored daemons) and not parallell one-shot
tasks or blocking one-shot runs.

This patch enables condition support for 'task' and 'run'
stanzas in both finit.conf and finit.d

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 11:47:21 +02:00
Joachim Nilsson 2216923343 Minor whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 11:43:09 +02:00
Joachim Nilsson ac834cfa1c I am the reaper of lost children ...
... but let's keep it quiet, OK?

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 01:16:51 +02:00
Joachim Nilsson f191266a33 Add --with-random-seed to enable urandom plugin
By default the urandom plugin will use /var/lib/misc/random-seed across
reboots to seed /dev/urandom at boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 00:41:23 +02:00
Joachim Nilsson 796275af62 HowTo: Finit on Alpine Linux 3.4
Mini HowTo with config files :)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 00:29:49 +02:00
Joachim Nilsson a7e52914d2 Set a default description for all services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-21 00:08:56 +02:00
Joachim Nilsson fcfbd57ca8 With 'log' keyword, always log process name
Do not tag log messages with service description, but use process name.
Possibly add :ID later to denote instance if multiple instances exist.

Also, add priority daemon.info log level.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 19:59:27 +02:00
Joachim Nilsson 5b81d14e51 x11-common: If restorecon exists, run it
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 19:58:42 +02:00
Joachim Nilsson 329af172de Fix default GREET
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 19:58:21 +02:00
Joachim Nilsson 33ce1592c1 bootmisc: Create /var/log/wtmp and lastlog too
Set correct permission bits, the utmp group must have write permission.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 19:57:39 +02:00
Joachim Nilsson 7a954e3743 Run user network start script cleanly
If user has no start script fall back to set up at least loopback.  This
fixes (at least) a problem on Alpine Linux where `ifup -a` returns error
if `lo` is already up.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 18:27:11 +02:00
Joachim Nilsson 48c2937f4f Simplify bootstrap message for rc.local start
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 18:24:30 +02:00
Joachim Nilsson 24961eb3ba Minor grammar fix in bootstrap message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 17:30:36 +02:00
Joachim Nilsson aced97c2e6 Handle systems with new /run tmpfs
Modern systems today use a RAM disk for /run and /run/lock, with
symlinks to the FHS locations in /var/run and /var/lock.  See the
following link for details http://lwn.net/Articles/436012/

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-20 17:30:29 +02:00
Joachim Nilsson a67350ebf6 Little bit more careful with init/telinit symlinks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-19 17:00:40 +02:00
Joachim Nilsson c47a0cd812 Conditionalize 'rlimit rttime', not available yet on musl libc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-19 15:56:49 +02:00
Joachim Nilsson 67c0d43912 Merge branch 'refactor-readme'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 20:26:11 +02:00
Joachim Nilsson 7b00969f6c Merge remote-tracking branch 'origin/inetd-plugins'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 20:25:36 +02:00
Joachim Nilsson 875080d1e1 Minor update
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 17:30:56 +02:00
Joachim Nilsson 1121965167 Do not build inetd plugins if inetd is disabled
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 17:30:29 +02:00
Joachim Nilsson 45bdadebb6 Minor cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 17:30:14 +02:00
Joachim Nilsson 7dfdc2395b Add protection against UDP inetd looping attacks
This patch adds protection against a common inetd attack vector wherein
the reply port to UDP inetd services is forged to an internal inetd
service port.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 17:27:37 +02:00
Joachim Nilsson 5723b2e75b Refactor RFC 868, time protocol plugin
- Always do a dummy read to get peer address.
- Refactor to new format used by other built-ins

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 12:28:40 +02:00
Joachim Nilsson d4fdf50636 Add optional support for RFC867, Daytime Protocol
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 12:06:59 +02:00
Joachim Nilsson 4f7366640b Add optional support for RFC864, Character Generator Protocol
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 11:48:04 +02:00
Joachim Nilsson 90497af7bb Add optional support for RFC863, Discard Protocol
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 09:55:19 +02:00
Joachim Nilsson cd0983a7f6 First draft of README refactor and split
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 15:52:19 +02:00
Joachim Nilsson c7573fedad Replace 'initctl emit <EV>' with 'initctl cond <cmd> <COND>'
This patch replaces the old 'initctl emit <EV>' idea with a more
full blown condition generator:

    initctl cond <set|clear|flux> <COND>

This aligns better with terminology used elsewhere in the new Finit
service state machine and dependency handling already documented.

The 'flux' sub-command is mostly intended for simulation/test of
Finit itself and should perhaps not be documented.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 15:51:57 +02:00
Joachim Nilsson 2b74fb0e93 Minor cleanup and corrections for new terminology
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 15:51:57 +02:00
Joachim Nilsson eb57457522 Document /etc/rc.local support
- Document /etc/rc.local support
- Update documentation around runparts(8)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 13:53:10 +02:00
Joachim Nilsson f0cda83d24 Clean up AC_ARG_WITH and use config.h also for default paths
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 13:17:09 +02:00
Joachim Nilsson fbacae7071 Minor cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 13:17:09 +02:00
Joachim Nilsson 48e2cbd183 Add convenient SysV init /etc/rc.local compat
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 13:17:09 +02:00
Joachim Nilsson 8f9ea0ae57 Fix stupid spelling error
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-15 08:41:06 +02:00
Joachim Nilsson 1c0776b818 Tie in service and condition documents with README
This is a first effort at cleaning up and consolidating all information
about the new service state machine and how conditions control this
state machine.

Also, clarified and added sections for all documents regarding how
services and conditions relate.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-14 16:08:44 +02:00
Joachim Nilsson 6ff9cb2ff3 Rename condition net/gw --> net/route/default in netlink plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-14 15:41:47 +02:00
Joachim Nilsson fbef03a4c6 Update Inetd features and service dependencies
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-14 10:03:19 +02:00
Joachim Nilsson 66f22a0a5f Add syntax highlighting helpers for Emacs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-14 09:52:22 +02:00
Joachim Nilsson 171ae7dc85 Add support for disabling the Netlink plugin
Some vendors provide their own Netlink plugin to Finit.  This patch
makes it possible to disable the default netlink plugin from being
built.  However, even before this patch it was possible to overload
the plugin.  This just discards it from being built.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-13 13:23:07 +02:00
Joachim Nilsson ebfa8f061c Fix default handling in M4 macro AC_PLUGIN()
The AC_PLUGIN() could not properly handle if a plugin is to be enabled
by default.  This patch adds support for outputting the correct help
text.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-13 13:20:56 +02:00
Joachim Nilsson 2baa4f8ea9 Followup to 38203ab, remove queue.h from Makefile as well
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-13 13:07:28 +02:00
Joachim Nilsson 38203ab9e8 Migrate to libite version (newer) of BSD queue.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 15:34:52 +02:00
Joachim Nilsson 88a4ebf9e7 Use <> instead of "" for external header includes
Libraries and system headers should be included with <> instead of "".
This makes a great difference for the automatic dependency tracking.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 15:32:36 +02:00
Joachim Nilsson 51f61939da Do not build insecure inetd time (rdate) plugin by default
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 13:36:47 +02:00
Joachim Nilsson 7262a25c85 Merge pull request #34 from troglobit/echo
Basic inetd echo server support and bugfix

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 12:38:14 +02:00
Joachim Nilsson 8b9309ee41 Fix regression in starting internal inetd services
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 12:24:28 +02:00
Joachim Nilsson affc6a97b9 Add support for inetd RFC862 echo server
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-12 09:58:25 +02:00
Joachim Nilsson ec041b3c02 Update configure and build section
Prune standard configure flags and focus on the most important, whatever
they may be.  Mention --disable-inetd and describe how --enable-static
works.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 12:38:45 +02:00
Joachim Nilsson 267eeb9692 Fix --enable-static build, only C library shared
This patch fixes regressions in --enable-static introduced with the
conversion to the GNU configure and build system.

The default link flag to libtool is set to -static-libtool-libs, meaning
not a fully static build -- the C library will still be used as an .so
which is usually what people want -- whereas libite (-lite) and libuEv
are linked statically.

$ ldd /sbin/finit /sbin/initctl
/sbin/finit:
	linux-vdso.so.1 =>  (0x00007ffffde62000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6979ad8000)
	/lib64/ld-linux-x86-64.so.2 (0x000055d893e96000)
/sbin/initctl:
	linux-vdso.so.1 =>  (0x00007ffed0dd6000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007feb3a29c000)
	/lib64/ld-linux-x86-64.so.2 (0x00005556ebd2b000)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 12:14:21 +02:00
Joachim Nilsson 58e00fe52e Fix #17: Mention kernel CONFIG_UEVENT_HELPER_PATH and /etc/fstab
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 11:15:33 +02:00
Joachim Nilsson a40301ef86 Bring Building section more up to date
Now that we have a proper GNU configure script there is no such thing as
lightweight, and the respected environment variables are listed at the
end of `./configure --help`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 11:14:03 +02:00
Joachim Nilsson 3a86db7d9f Fix typo in --enable-rw-rootfs configure option
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 10:30:31 +02:00
Joachim Nilsson 927956bf78 Set correct initial bootstrap runlevel 'S'
This patch corrects a long standing issue with Finit.  System initial
bootstrap runlevel must be set to 'S' (0), not the configured fallback
runlevel 'RUNLEVEL', which likely is '2'.

Also, minor cleanup, reduce code duplication.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 10:24:15 +02:00
Joachim Nilsson 05938a88ce Fix #33: Set up directory required by D-Bus plugin
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-09 10:04:34 +02:00
Joachim Nilsson 4a8a92af2e Minor audit of new top-level state machine
Also, give Jonas copyright for his contribution to Finit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-07 18:32:31 +02:00
Joachim Nilsson 79b95daf3a The pidfile plugin requires /var/run, so depend on bootmisc
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-06 19:44:21 +02:00
Joachim Nilsson ea21bfc4c9 Relocate global sm variable to reduce include file deps
The new state machine handling is not necessary to export to external
plugins, so this patch reduces the exposure of the global variable sm

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 23:10:47 +02:00
Joachim Nilsson e9da876a10 Actually fix fallback shell memory leak
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 22:08:12 +02:00
Joachim Nilsson ef7f0b100b Check return value from fcntl() on inetd server socket
Setting O_NONBLOCK on an inetd server socket may fail, we
must check for this or the event loop may stall and block
Finit completely.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:53:42 +02:00
Joachim Nilsson 33ccff7733 Audit ad2bafb: cleanup of stale pid files
Make sure to check return value of remove(), it may actually signal
something useful.  Log useful errors.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:46:25 +02:00
Joachim Nilsson 00e5a8f5d9 Audit ec25051: service logging support
- Must check return value from open(), found by Coverity Scan
- Minor refactor (and cleanup) to reduce code complexity

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:38:46 +02:00
Joachim Nilsson f74a73be20 Audit commit 1177c73: musl libc compat changes
Must initialize init_request buffer to zero before communicating with
Finit.  Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:21:24 +02:00
Joachim Nilsson 34d8848b5c Fix leak if fallback shell cannot be registered
If we cannot register a fallback TTY we leak a few bytes RAM.
Found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:15:16 +02:00
Joachim Nilsson 662f364d09 Check return value from uev_io_init() at runtime
Possible resource leak due to unchecked return value from uev_io_init()
found by Coverity Scan.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 21:03:36 +02:00
Joachim Nilsson e53acd1cdd Fix minor type warning in debug message
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 20:14:43 +02:00
Joachim Nilsson d96d1a3023 Audit rlimit support, handle possible NULL pointer
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 20:10:37 +02:00
Joachim Nilsson f249210c04 Update Travis-CI build script for Coverity Scan
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 19:52:33 +02:00
Joachim Nilsson 969ecffc05 Merge branch 'westermo-finit-sm'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 19:49:33 +02:00
Joachim Nilsson cc15d3f77b Merge branch 'finit-sm' of https://github.com/westermo/finit into westermo-finit-sm
Hand merged conflicts in the following files:
	Makefile
	finit.h
	service.c

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-06-04 19:48:08 +02:00
Jonas Johansson ad2bafbfe8 services: remove .pid file for (careless) died processes
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-20 09:08:38 +02:00
Jonas Johansson c5fad8e659 services: do not start services before all stopped processes has been halted
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-19 14:46:59 +02:00
Jonas Johansson c1f725340d plugin/pidfile: also notify on modified pidfiles
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-19 13:39:56 +02:00
Jonas Johansson 29315090f9 sm: handle reload event
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-18 10:40:01 +02:00
Jonas Johansson 60df2043ac sm: handle runlevel change
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-18 10:18:40 +02:00
Joachim Nilsson d48da81026 Merge pull request #31 from thezbyg/master
Fix SIGSEGV due to writes to const char array.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-17 20:28:35 +02:00
Albertas Vyšniauskas 5b86c76694 Fix SIGSEGV due to writes to const char array.
If no console is configured, then the following code gets executed:
int conf_parse_config(void)
{
  ...
  char *fallback = FALLBACK_SHELL;
  ...
  tty_register(fallback);
  ...
}
int tty_register(char *line)
{
  ...
  cmd = strtok(line, " ");
  ...
}
FALLBACK_SHELL is constant character array and strtok tries to modify
the first argument, which causes a crash.
2016-05-17 20:38:42 +03:00
Jonas Johansson 364f3bbafb finit: add finit state machine
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-16 15:17:02 +02:00
Joachim Nilsson 9a539c636a Merge pull request #30 from westermo/wmo/2.4
Resource limit manipulation (setrlimit)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-05-01 11:14:08 +02:00
Joachim Nilsson ca830b9a09 Compat install-dev hook
Finit <3 did not use GNU configure and build system.  This patch adds an
install-dev rule that is used by some to install required headers for
external plugin developers.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-30 16:53:43 +02:00
Joachim Nilsson f2b0951d78 Install headers for external plugin devs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-30 16:39:51 +02:00
Tobias Waldekranz 6d84fd010e Resource limit manipulation (setrlimit)
Add support for changing the initial hard and soft resource limits for
finit and any processes it launches.

See /etc/finit.conf section in README.md for more information.
2016-04-28 09:36:22 +02:00
Joachim Nilsson 110ee220e7 Merge pull request #29 from westermo/wmo/2.4
Allow debugging of inetd service's arguments
2016-04-26 11:04:47 +02:00
Joachim Nilsson f29dff691f Allow debugging of inetd service's arguments
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 11:02:32 +02:00
Joachim Nilsson a1e6febc4f Merge pull request #28 from westermo/wmo/2.4
Westermo fixes for services changing type at runtime

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:38:41 +02:00
Joachim Nilsson df1fbbc996 Handle type change from inetd to service
When a service changes type from inetd to a regular daemon we must make
sure to first deregister the currently running inetd service properly.

Example: a system boots up with httpd.conf as an inetd service, so Finit
   opens a socket 0.0.0.0:80 pending connections to start `httpd -i`.
   After a while a user changes httpd.conf to be a regular service and
   calls `initctl reload`.  Without this patch the socket will remain
   open and prevent httpd from opening and binding to the same port.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:30:00 +02:00
Joachim Nilsson 448a9e1198 Stop inetd watcher and close socket when inetd service is removed
This patch fixes a problem with lingering inet sockets when inetd
services are removed.  When removing an inetd service we must stop
the watcher and close the socket.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:27:30 +02:00
Joachim Nilsson 80624d3ff8 Revert "Do not just mark deleted SVC free, clear memory"
We cannot clear the svc_t memory because other applications may have
connected to the same shared memory.  An application may be inspecting
the current list of services (initctl) and pulling the rug from under
them could cause some really unpredicatble results.

This reverts commit 06d1e90bac.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-26 09:23:59 +02:00
Joachim Nilsson 4b0f78c1b5 Merge pull request #27 from westermo/wmo/2.4
Westermo fixes for UDP inetd services and more

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:06:43 +02:00
Joachim Nilsson 5ea3cc0090 Reduce max backlog in listen(): 20 --> 10
Both the original MIT Athena inetd and the GNU inetutils inetd only keep
a backlog of 10 connections in listen() for TCP sockets.  This patch
adjusts the Finit hard coded default accordingly.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson 7f5f8ba09d Minor grammar: "Connection" --> "connection"
When starting an inetd service in verbose mode we print a progress
message to the console appended with "Connection".  This patch simply
changes that to append with "connection" in lower case.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson efd265c9c8 Fix "broken pipe" problem for UDP inetd services
This patch fixes several issues related to the problem of launching
UDP inetd services:

- Make sure to disable O_NONBLOCK on the socket before passing it to
  the inetd service, that's what is expected.  This goes for both UDP
  and TCP (accepted) connections -- there is no guarantee even for TCP
  sockets that they do *not* inherit the parent socket's flags.
- Mark the UDP inetd parent's SVC as busy and stop its watcher before
  starting the child task to service the connection.  The watcher must
  be stopped or multiple child tasks may be spawned!
- Only copy the most relevant parts to the UDP task.  In particular
  must *not* copy the libuEv watcher data to the task!
- With the child task done and the parent inetd service unblocked we
  must restore O_NONBLOCK to the socket before restarting the watcher

When a UDP inetd service connection is handled we create a child task
to service the request, meanwhile we block the parent service.  There
was a problem with blocking the parent since we called inetd_stop(),
which both did a shutdown() and close() of the socket ... this patch
introduces separate handling of blocked (busy) inetd services in the
inetd_stop() function and also make sure to handle restarting the
parent watcher in inetd_start() when the child task is done.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson 7e91cb4afc Minor log message improvements
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 12:01:10 +02:00
Joachim Nilsson 9a03adce5a Do not assume new fd is 0, dup2() with fd instead
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 10:54:31 +02:00
Joachim Nilsson 06d1e90bac Do not just mark deleted SVC free, clear memory
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 10:53:20 +02:00
Joachim Nilsson 439d9df122 Set CLOEXEC flag to prevent leaking descriptors
Both the new initctl API and the new pidfile watcher plugin failed to
set CLOEXEC on their sockets.  This caused forked-off and exec()'d
children to inherit all these descriptors.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-24 10:52:39 +02:00
Joachim Nilsson f44ac5a023 Remove bogus autoconf version requirement
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:20:26 +02:00
Joachim Nilsson 84c75c4416 Rename internal pkg-config reference to libuEv
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-17 00:18:11 +02:00
Joachim Nilsson ee8a69f5ed Let plugins know search path for lite.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-16 22:05:31 +02:00
Joachim Nilsson acf6cb6900 Show configure log to see where hell breaks loose
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-16 21:58:53 +02:00
Joachim Nilsson f51183d5f2 Strip install libs, do not use DESTDIR for Finit
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-16 21:55:39 +02:00
Joachim Nilsson ff5814e4d4 Use pkg-config provided paths for uEv and lite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-16 21:45:21 +02:00
Joachim Nilsson 831d0c5520 Use /tmp as install --prefix for libs, not DESTDIR
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-16 21:21:48 +02:00
Joachim Nilsson d9cc21b3c8 Travis-CI: Attempt to build w/o root privs
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-16 21:12:45 +02:00
Joachim Nilsson 096a3eff51 Mention new log keyword to services et al
Patrick Stewart added the optional `log` keyword to service, run, task
and inetd stanzas in 889bce1.  It redirects stdout/stderr to syslog
using the logger tool.  This addition to the README is mainly just a
place holder so it's not forgotten before the upcoming README refactor.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 23:56:02 +02:00
Joachim Nilsson 889bce1768 Merge pull request #26 from RFCreations/master
Some fixes, and add logging

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 23:46:01 +02:00
Patrick Stewart 0ba8df5c2d Change stdin member of svc to stdin_fd
'stdin' is a macro in stdio.h, so it shouldn't be used as a member name. GLIBC happens to have "#define stdin stdin", but other libcs don't.
2016-04-13 22:09:05 +01:00
Patrick Stewart ec2505191b Add service logging
Adds an extra 'log' parameter to services that routes STDOUT and STDERR to syslog.
Uses a PTY rather than a pipe, as this prevents log messages hanging around in a buffer indefinitely.
2016-04-13 22:09:05 +01:00
Patrick Stewart 3de9e4e5db Fix potential race condition/hang for SVC_TYPE_RUN services
In service_start() the SIGCHLD handler is reenabled before calling complete(), so the service could be reaped by the SIGCHLD handler leaving service_start() waiting forever
Also remove code that duplicates sig_unblock()
2016-04-13 22:09:05 +01:00
Patrick Stewart 1177c734ce Use finit API to get runlevel instead of utmp
utmp is not available with musl libc
2016-04-13 22:07:39 +01:00
Joachim Nilsson f7f222c924 Minor formatting and sectioning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:45:28 +02:00
Joachim Nilsson dd8715f3dc configure.ac: Cleanup, remove commented out old ideas
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:43:40 +02:00
Joachim Nilsson 3e93ed2ead TODO: Add support for throttling connections
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:40:57 +02:00
Joachim Nilsson e50e12417e README.md: Attempt to update to new build system
First attempt to update and simplify the build instructions and example.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:37:34 +02:00
Joachim Nilsson 9e70a12273 configure.ac: Remove datarootdir
Unused after removal of GIT submodules.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:36:41 +02:00
Joachim Nilsson b313e623df Remove double slash '//bin' from default prefix path
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:22:27 +02:00
Joachim Nilsson 376d7a0fbb m4/plugin.m4: Minor cleanup
Use pure M4 syntax, not mixed with -P syntax.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-13 07:17:02 +02:00
Joachim Nilsson 1398536194 README.md: Update initctl help text
Add missing `initctl cond show` help.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 23:48:28 +02:00
Joachim Nilsson 95135ca0a7 README.md: Slightly friendlier warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 23:42:25 +02:00
Joachim Nilsson ec31930638 README.md: Mark optional plugins as optional
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 23:39:00 +02:00
Joachim Nilsson ed8b21db36 plugins/Makfile.am: Make optional plugins optional
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 23:36:35 +02:00
Joachim Nilsson b1cd3a2332 Make a few less used plugins optional
The alsa-utils, dbus, lost (PID), resolvconf, and x11-common plugins are
rarely used in the main use-case for Finit (embedded head-less systems).
This patch disables them by default and makes them possible to enable by
configure --enable-$PLUGIN switches.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 23:34:27 +02:00
Joachim Nilsson 5675d068f8 m4/plugin.m4: Simplify, fix and cleanup M4 code
Slightly more readable code and fix issue with --enable-$PLUGIN not
biting properly in the generated Makefile.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 23:32:52 +02:00
Joachim Nilsson 4baf2611f6 Foundation for selecting plugins in configure
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-12 20:30:29 +02:00
Joachim Nilsson 13d4821abe Disable fast-install by default
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 07:29:01 +02:00
Joachim Nilsson 1f1c2e0466 Replace verbose and kernel quiet modes with silent and quiet
This patch replaces the verbose and kernel-quiet runtime options with
a (hopefully) more useful quiet and silent modes of operation.

By default Finit progressively shows all services it starts at boot, but
when boot has completed and services are started/restarted Finit prints
nothing.  If `--disable-quiet` is given all started/restared/stoppping
messages are shown even after boot.

However, if `--enable-silent` is given Finit is completely silent even
at boot, no progress is shown, until the first service is started, which
on most systems is login.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 00:50:37 +02:00
Joachim Nilsson c4af8b7cbd configure: Shorten and clarify descriptions
This patch makes a few configure options shorter, but still more clear.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 00:49:24 +02:00
Joachim Nilsson 426d915c08 configure: Remove --with-aix-soname=aix|svr4|both
Remove confusing `--with-aix-soname` option to configure.  Replace with
hard-coded `aix-soname=both` => shared + static archives are build as to
be expected.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 00:46:31 +02:00
Joachim Nilsson 86be6812b9 configure: Remove GIT submodule check
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-11 00:45:37 +02:00
Joachim Nilsson 4efdc4fe19 Merge pull request #25 from westermo/wmo/2.4
Westermo fixes to Finit3
2016-04-10 20:08:25 +02:00
Joachim Nilsson da76cf4f75 Check return value from strtok(), may be NULL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:58:46 +02:00
Joachim Nilsson a2177a8063 Fix GCC warning for signed vs unsigned comparison
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:58:13 +02:00
Joachim Nilsson cfa155deae Minor cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:57:48 +02:00
Joachim Nilsson e7832e2ca7 FTBFS followup issue #24
Add missing return keyword to inline function svc_is_starting()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:56:13 +02:00
Joachim Nilsson d7d45b65d0 Merge pull request #24 from westermo/wmo/2.4
Assert svc condition only when PID file has been created/updated

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:50:16 +02:00
Joachim Nilsson 4ae5c54f45 Assert svc condition only when PID file has been created/updated
This patch prevents too early start of services depending on other
services.  E.g, if service B depends on A then we must wait for A to
signal that it is ready before we allow B to start -- in a Finit based
system A does this by creating, or touching (updating mtime), its PID
file.  Services (like A) that support SIGHUP should call utime(), or
utimensat(), on the PID file at the end of their SIGHUP handler.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-10 19:14:48 +02:00
Joachim Nilsson 7b8944730d README: This is Finit3, development version
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-09 20:42:44 +02:00
Joachim Nilsson 87ca6574b8 Travis-CI: Build & install libuEv and libite first
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-09 20:37:09 +02:00
Joachim Nilsson 35844f2d1d Update finit_LDADD for external libuEv and libite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-09 20:35:38 +02:00
Joachim Nilsson 2e2d87ee78 Update include path for libuEv and libite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-09 20:33:07 +02:00
Joachim Nilsson ba11d218bc Remove local GIT submodules for libuEv and libite
From now on the user is required to have libuEv and libite installed
before building and installing finit. This is for maintenance reasons.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-09 20:29:26 +02:00
Joachim Nilsson 707c42db63 Update TODO, remember our origins!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 20:18:31 +02:00
Joachim Nilsson 4cfe4781a3 Remove old (now unused) compat symlinks
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 20:17:38 +02:00
Joachim Nilsson 8f415aeaf6 Add HOOK_SVC_START to detect started processes
This patch adds support for the runtime `HOOK_SVC_START`.

Customer request.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 03:45:23 +02:00
Joachim Nilsson 3f3220e806 Add HOOK_SVC_LOST to detect lost processes
This patch adds support for the runtime `HOOK_SVC_LOST` and the (very
noisy) *example* plugin `lost.so`.

Customer request.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 03:33:58 +02:00
Joachim Nilsson e54c7eef65 Fix dlopening of plugins
Finit must export symbols, but plugins do not since they are modules.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 03:20:10 +02:00
Joachim Nilsson 05cc6bf5d2 Do not bail on makepath() fail if dir exists
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 03:16:40 +02:00
Joachim Nilsson 4fecb8621d Fix PLUGIN_PATH => $(pkglibdir) in build system
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-04-05 02:38:24 +02:00
Joachim Nilsson 6a49f7ed8c Add missing license, copyright and module description
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-21 15:56:15 +01:00
Joachim Nilsson 8bcc34ce91 Remove Emacs version-control handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-21 15:41:51 +01:00
Joachim Nilsson 8da1505454 Minor, use () to denote function in comments
To distinguish between variables and functions in comments Finit use ()
at the end of function names.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-21 15:14:12 +01:00
Joachim Nilsson 34e4d31219 Travis-CI: Set LD_LIBRARY_PATH to /tmp/lib for initctl -h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-19 23:03:41 +01:00
Joachim Nilsson 6489dcc967 Update .gitignore files
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-19 23:00:00 +01:00
Joachim Nilsson 2d6769005a TODO: Add Westermo request for initctl show --json
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-19 22:56:05 +01:00
Joachim Nilsson 98cd6dffb1 Fix build and install temporarily
This patch builds Finit dynamically, including both plugins and GIT
submodules for libite and libuev.  This causes libite.so and libuev.so
to be installed in a public path, which is not good if the user has
other versions of the same libraries already installed.

The correct fix is to remove the GIT submodules for now and require
users of Finit to build and install libite and libuev separately.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-19 22:54:07 +01:00
Joachim Nilsson eb86a76a0d Travis-CI: Remove extra call to configure
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-19 22:51:34 +01:00
Joachim Nilsson 4423a2b16e Fix Travis-CI build, move package install
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-18 21:32:23 +01:00
Joachim Nilsson 0467c571df Merge pull request #22 from westermo/wmo/2.4
initctl: Only show service name, not path, with plain show
2016-03-17 22:04:27 +01:00
Joachim Nilsson cef4b5761a initctl: Only show service name, not path, with plain show
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-16 13:06:47 +01:00
Joachim Nilsson 806d05622a Fix libite.la library dependency in build
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-15 08:20:48 +01:00
Joachim Nilsson 57fb4738f1 Create empty m4 directory for the benefit of autogen.sh and Travis-CI
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-15 07:34:20 +01:00
Joachim Nilsson 0bbc69200b Update Travis-CI to use ./autogen.sh before configure & build
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-15 00:13:07 +01:00
Joachim Nilsson 726f0d428d Initial conversion to GNU Configure & Build System
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-14 22:35:54 +01:00
Joachim Nilsson 0704947c33 Merge pull request #20 from westermo/wmo/2.4
inetd reload fixes

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-19 15:11:20 +01:00
Tobias Waldekranz 2555fe8e96 inetd: Flush existing filters on reload
Flush any existing filter rules when a configuration file is
updated. Otherwise filters are simply appended to the old
configuration which can cause finit to accept connections on
interfaces that are blocked in the new configuration.
2016-02-19 12:53:39 +01:00
Tobias Waldekranz c41016ef32 Only default to SIGHUP support on daemons
When parsing a service configuration, only default to SIGHUP support
if the service is a daemon. inetd services must be stop/started on
change.
2016-02-19 12:50:24 +01:00
Joachim Nilsson 5d86137142 Fix Coverity warning for unchecked return value from mkdir()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 23:13:47 +01:00
Joachim Nilsson bd58345b8c Fix Coverity warning for unterminated string from read()
The read() does not zero terminate the string, then we call strstr() on
that string ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 23:01:24 +01:00
Joachim Nilsson 994b589377 Fix Coverity warning for possible NULL ptr dereference
Add check for return value from strtok()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 22:55:39 +01:00
Joachim Nilsson caff08f58d Fix Coverity warning for unchecked return value from dirname()
- Check return value from dirname()
- Remove static from local compose buffer

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 22:50:08 +01:00
Joachim Nilsson d58c58d972 Test build with both GCC and Clang (LLVM)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:57:58 +01:00
Joachim Nilsson a97499999e Remove initial make distclean step, not needed
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:54:34 +01:00
Joachim Nilsson 9c7046a25d Fix linking error with new autotools based libraries
We may have reached peak Makefile mastery now ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:44:21 +01:00
Joachim Nilsson cd5d55ef51 Call libuev configure script if local libuev is used
Same as for libite, libuev has also changed to autotools, so
call its autogen.sh and configure script in cascade from our
own.  Aslo add safeguards to clean/distclean targets so we
do not attempt to enter the libuev subdirectory if it's not
configured.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:43:04 +01:00
Joachim Nilsson 5eb172ed46 Update to libuEv v1.3.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:23:16 +01:00
Joachim Nilsson 3d99940252 Bump version to 3.0-beta1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:10:47 +01:00
Joachim Nilsson fce420121c Fix unused variable warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:10:25 +01:00
Joachim Nilsson 6c91c4ec12 Fix unused variable warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:09:31 +01:00
Joachim Nilsson 2cb5997abe Fix signed/unsigned comparison warning
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:09:20 +01:00
Joachim Nilsson 5afb47bc9b ChangeLog: Add missing links to referenced previous versions
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:08:21 +01:00
Joachim Nilsson d6d92f1df7 Increase indentation in pretty printing slightly for autotools
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:07:17 +01:00
Joachim Nilsson 4899bba06b Call libite configure script if local libite is used
The new libite uses autotools to build, and since we use it as a GIT
submodule we have to call its autogen.sh before we call the configure
script, from within the Finit configure script.  We may have to move
to use autotools even for Finit ...

Also, make sure to only call clean/distclean on libite if the local
version is selected at configure time.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 21:06:46 +01:00
Joachim Nilsson 97a160dd1d Update to libite v1.4.3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 20:26:40 +01:00
Joachim Nilsson 901bdc68ba Merge pull request #19 from westermo/wmo/2.4
Service state machine and refactored event/condition handling

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-02-05 16:44:51 +01:00
Tobias Waldekranz c6055031b8 Avoid unnecessary restarts of services that do not support SIGHUP
When a service's condition transitions to `flux`, put it in the
waiting state, even if it does not support SIGHUP. That way, if the
condition returns to `on` we can simply SIGCONT it. If it goes to
`off` it will still be stop/started as before.
2016-02-05 13:45:06 +01:00
Tobias Waldekranz e8d699c194 Mark inetd services as clean on dynamic reload
When reloading dynamic services, inetd services deleted marker was not
being cleaned. This caused finit to stop and start all inetd services
at every other reload.
2016-01-28 14:52:49 +01:00
Tobias Waldekranz 80273555c5 Do all service transitions in a helper function
This eases development, since it makes it easy to set a breakpoint on
a specific state transition.
2016-01-28 13:44:27 +01:00
Tobias Waldekranz 6ece4b8fa3 inetd: Re-integrate the inetd subsystem into the new service model
This patch introduces a new service type called SVC_TYPE_INETD_CONN,
which represents a running inetd connection. These are handled in much
the same way as tasks. I.e. they are considered one-time jobs, with
the difference that they are removed upon completion.
2016-01-15 10:07:15 +01:00
Tobias Waldekranz 0beb566e45 git: Ignore Emacs backup files 2016-01-13 16:02:46 +01:00
Tobias Waldekranz c641a1374e Do not ignore updated services when cleaning up removed ones
When cleaning up removed services, the assumption was made that if a
service was not 'removed', it was 'clean'. In reality, it could also
be 'updated', which was then overwritten, causing services not being
restarted. Don't do that.

As a future precaution, make the dirty field const, only allowing
updates from accessor methods.
2016-01-13 15:14:27 +01:00
Tobias Waldekranz 171d611b14 Improve service state machine debug messages
In addition to logging state transitions, also log the parameters that
might trigger a transition.
2016-01-13 15:09:04 +01:00
Tobias Waldekranz 02eb68f46c Ensure that a service has stopped before taking any further action
During documentation of the state machine, some theoretical problems
where discovered that could have lead finit to spawn a new instance of
a daemon before the previous one had been collected.

Now a service will always go through the STOPPING state when leaving
RUNNING. This ensures that the PID has been collected before any calls
to service_start.

...documenting your work is, apparently, not a bad idea. :)
2016-01-07 11:00:52 +01:00
Tobias Waldekranz 7fe4c3355f doc: Add service state machine documentation 2016-01-07 11:00:51 +01:00
Joachim Nilsson 5b28fed321 Audit.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-01-05 21:11:27 +01:00
Tobias Waldekranz aa1da0e9f2 doc: Add documentation for conditions 2016-01-05 17:24:31 +01:00
Tobias Waldekranz 2232aea0f7 Dynamically manage service states based on user defined conditions
Old event system has been replaced with a more generic condition
concept. The idea is that finit plugins may provide arbitrary
conditions that services may specify as dependencies that they require
to run.

In order to accomodate this, the service management has been
redesigned to use a state machine.
2016-01-05 15:01:58 +01:00
Tobias Waldekranz 7a3408c173 Optionally skip stripping binaries during install-exec
One may wish to build and install with debug symbols intact, so allow
overriding the arguments sent to install.
2016-01-05 14:50:13 +01:00
Tobias Waldekranz af7b6c17cb Correctly parse service configuration stanzas containing slashes
Parser would erroneously interpret an event specification containing
slashes as an inet service/proto specification.

E.g. "<net/gw>" was interpreted as port "<net" using protocol "gw>".
2016-01-05 14:50:13 +01:00
Joachim Nilsson a822a7657c Update ChangeLog and bump version for v2.4 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-04 19:15:48 +01:00
Joachim Nilsson e46271c1a9 Revert change in v2.3 listing stopped services as "paused"
Stopped services are now (again) listed as "stopped" and halted
services, due to a runlevel change, are listed as "halted". Several
users complained that this change was just not intuitive. I agreee.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-04 19:05:35 +01:00
Joachim Nilsson 1028725079 Add support for 'initctl show dropbear:2'
By popular request, this patch adds support for querying status of a
single service.  The syntax is similar to that of stop/start/reload.

Both `initctl show ...` and `initctl status ...` is supported.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-03 20:05:25 +01:00
Joachim Nilsson ed5ee667ae [Patch 2/2]: Make sure to start/SIGHUP services when none were stopped
When no services were stopped we must ensure to start/SIGHUP any new or
SIGHUP:able services as the last pass of the `initctl reload` cycle.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-02 13:06:16 +01:00
Joachim Nilsson 4c3e053041 [Patch 1/2]: System reconfiguration causing system freeze
This patch fixes a hang when performing a system reconfiguration using
`initctl reload`, `SIGHUP` or running `(f)init q`, which caused Finit
to wait for SIGHUP:able services to stop.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-02 13:02:40 +01:00
Joachim Nilsson a5c5a5c644 Allow debug mode to override terse mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-01 22:36:16 +01:00
Joachim Nilsson fa3a97366c Update Debugging section, all interesting stuff is in configure now
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-01 22:30:08 +01:00
Joachim Nilsson 5b3e3da7ff Attempt to clarify how BusyBox getty works wrt. the TTY device path
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-12-01 22:24:21 +01:00
Joachim Nilsson 59d96f264d Reenable verbose mode at reboot, if disabled at boot
This patch reenables verbose mode at shutdown/reboot, if it was disabled
at boot.  This allows the user to see the output from the `urandom.so`
and `hwclock.so` plugins at reboot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-30 22:31:48 +01:00
Joachim Nilsson 7027cbc439 Enforce terse mode after boot, if verbose is disabled
The urandom.so plugin uncovered that `print_desc()` does not honor the
`verbose` flag.  At runtime `print_desc()` et al should no be displaying
anyting when we finit operates in terse mode.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-30 19:45:27 +01:00
Joachim Nilsson 8218fff7e5 Update ChangeLog and bump version for v2.3 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-28 13:59:47 +01:00
Joachim Nilsson 263e23a0df initctl: Support for stop/start services by name:id
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 21:22:05 +01:00
Joachim Nilsson 1f88e1ff8a Refactor svc_status() used by 'initctl show'
Leverage new svc_t states in initctl status/show output.  Also, ensure
different svc_t types have correct start state.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 20:51:04 +01:00
Joachim Nilsson b4ccc8b008 Clean up bootstrap-only tasks when leaving bootstrap 'S' runlevel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 20:22:24 +01:00
Joachim Nilsson 8df2b7b6e9 service_stop_dynamic(): Skip already stopped and HALT removed services
new postponed stop handling tried to reload already stopped and removed
services.  We should of course skip already stopped services and halt
those that have been removed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-26 19:13:39 +01:00
Joachim Nilsson 8073f7cf27 Revert semantic change in 'initctl restart' introduced in 924bf04
This patch reverts the change in behavior introduced in Finit v2.2,
commit 924bf041, where `initctl restart JOB` changed from 'stop + start'
to `SIGHUP` for services that support `SIGHUP`.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-25 10:14:18 +01:00
Joachim Nilsson e303e1f833 Fix column alignment in initctl show for services not in current runlevel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-25 09:36:56 +01:00
Joachim Nilsson 3ea4be9343 Fix NULL ptr dereference causing kernel panic
When `service_stop_done()` is called with a `NULL` argument and no
dynamic services have been stopped, this regression is triggered.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-25 09:30:53 +01:00
Joachim Nilsson d8188428ed Bump version for v2.2 release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-23 13:20:44 +01:00
Joachim Nilsson d9f1882204 Update ChangeLog and prepare for release of v2.2
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-23 00:59:04 +01:00
Joachim Nilsson 4d899851cc Upgrade libite (LITE) to v1.2.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-23 00:45:55 +01:00
Joachim Nilsson ad8feca3e7 Upgrade libuEv to v1.2.4
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-23 00:45:20 +01:00
Joachim Nilsson 7569c479b8 Improve event debugging
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 22:18:56 +01:00
Joachim Nilsson e7db6c6ac6 Update README with latest changes to initctl help
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 22:18:40 +01:00
Joachim Nilsson f12535dc19 Clarify that the GW event to listen for in service declarations is GW:UP
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 22:18:15 +01:00
Tobias Waldekranz b19ea16e9d Only trigger on events that matches the service's specification
Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
2015-11-22 19:59:01 +01:00
Joachim Nilsson eb59155dad Enable mdev logging when Finit runs in debug mode
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 19:53:44 +01:00
Joachim Nilsson f38dfaf2dc Pretty printing of current runlevel in initctl show
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 15:58:32 +01:00
Joachim Nilsson 4ada42f380 Add debug flag to initctl client tool
This patch makes it possible to see debug traces when running the client
program initctl, using `--debug`.  Please note, this does not affect the
debug command to the daemon.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 15:57:56 +01:00
Joachim Nilsson 924bf041bc On reload/restart we must wait for services to stop first
This patch adds support for declaring *why* a service is being stopped
or reloaded.  This is later used when all stopped services have been
collected by the `service_monitor()` to issue start or postponed SIGHUP.

As an added benefit we can now also see why a service is not running.
If it has been paused by a user, halted when moving to another runlevel,
waiting for a condition (event), or similar.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 10:11:27 +01:00
Joachim Nilsson b1d57d6828 Set default value for svc->sighup, even if service has no event mask
The `initctl reload <JOB>` command did not work properly.  This
was due to the service not being properly initialized to default
settings when reading the Finit configuration file.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-22 10:05:57 +01:00
Joachim Nilsson 87f9b94b42 Call HOOK_SVC_RECONF only when all processes have been stopped
This patch fixes a race condition when doing an ordered RELOAD and STOP
event sequence.  For services that shall be stopped it is imperative
that we wait for them to be colleced by the `service_monitor()`, so that
we know they have really been stopped, before calling HOOK_SVC_RECONF.

The latter is a promise to external services that all services have been
indeed stopped.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-11-19 19:29:16 +01:00
Joachim Nilsson c8f0b97d0f tty.c: Handle EINVAL and use recommended inotify event size.
The TTY plugin might fail in read() with EINVAL if the inotify event
buffer is too small.  Fix: set the receive event buffer to the size
recommended in inotify(7).  Also add a handler for EINVAL to close and
reinitialize the inotify descriptor so we do not accidentally overrun
the CPU with any unhandled errors.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 04:33:51 +01:00
Joachim Nilsson f902505b5d Declare name for all plugins, needed for static builds.
When building a static Finit the plugins do not get a unique name
automatically from the file.  This led to only the first plugin being
loaded, since its name was 'unknown' it was registered as such and all
other plugins conflicted, since 'unknown' was already ... known and
loaded.

This patch gives all plugins a default name, __FILE__, making it
possible to use all of them when building a static Finit.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 03:44:43 +01:00
Joachim Nilsson a6b78d57c0 Clarify why we must define the name for inetd plugins.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 03:39:05 +01:00
Joachim Nilsson a33478d563 Improve urandom plugin for embedded systems w/o random seed.
For embedded systems with no initial random seed, usually stored in
/var/lib/urandom/urandom-seed on desktops, servers and laptops, we now
provide an initial seed file using a built-in PRNG.

Also, let the configure script default to *enable* the random seeding
at boot, granted the urandom plugin is enabled.  We should encourage
users to properly seed their random, for security reasons.

Moreover, the plugin did not properly regenerate the random seed on
reboot, or shutdown, this patch also rectifies that problem.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 03:31:19 +01:00
Joachim Nilsson 369fcf2100 Issue #14: Improved support for static Finit builds
- Upgrade libite (LITE) for new UNIX file parser API to improve static
  builds of Finit.
- Re-enable bootmisc plugin for static builds by adding built-in support
  for reading GID from /etc/group.
- Allow inetd support for static builds by adding built-in support for
  reading service and protocol from /etc/services and /etc/protocols.
- Do not try to install/uninstall any plugins for static builds.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-26 00:56:50 +01:00
Joachim Nilsson b2c5e97417 Disable bootmisc plugin entirely if configure --enable-static
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-22 19:01:19 +02:00
Joachim Nilsson 8725200260 Build fixes for configure --disable-inetd
service.c:
	Don't declare find_inetd_svc() if inetd is disabled.
api.c:
	Disable inetd API
initctl.c:
	Disable presentation of inetd services

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-22 18:59:20 +02:00
Joachim Nilsson 58980c72fa Misc. fixes to silence warnings when building a static Finit.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-22 18:39:46 +02:00
Joachim Nilsson bcc70ec774 Update libite and libuev to handle static builds.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-22 18:38:47 +02:00
Joachim Nilsson 44579cc089 README: Clarify how arguments to ./configure --with-plugins= work
This should help clarify any misunderstandings detailed in issue #13.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-22 15:19:01 +02:00
Joachim Nilsson da361f460d Update ChangeLog slightly, off by one fix
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-16 20:56:56 +02:00
Joachim Nilsson bc2cb21005 Update version links.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-16 20:46:34 +02:00
Joachim Nilsson e1169628ce Update ChangeLog and bump version for v2.1 release
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-16 20:44:47 +02:00
Joachim Nilsson 48b420b757 Simplify execution and _exit() of service callback.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-16 19:45:09 +02:00
Joachim Nilsson 9796809907 Merge pull request #12 from westermo/wkz/sighup-fix
Unblock blocked signals after forking off a child
2015-10-16 18:42:47 +02:00
Tobias Waldekranz a3193b34a6 Unblock blocked signals after forking off a child
After forking off a new child, all signals that are blocked by finit
should be unblocked before exec-ing the final binary. Also, finit now
blocks SIGHUP, so add it to the set of signals that should be
unblocked.
2015-10-16 18:32:53 +02:00
Joachim Nilsson c0af01db6d Upgrade libite (LITE) to v1.1.1
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-10 17:36:24 +02:00
Joachim Nilsson 3c1c7df420 Default to -O2, not -Os, and use CPPFLAGS for includes, not CFLAGS.
We should not use -Os as default optimization, it is sometimes unstable
in cross compilers.  Instead, default to -O2, which is the more tried
and tested path.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-10 17:34:31 +02:00
Joachim Nilsson 258efd4101 Cleanup, minor bug fixes and silencing of netlink plugin.
Patch courtesy of Westermo.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-08 19:59:19 +02:00
Joachim Nilsson 5e33647f80 Fix too small MAX args in initctl and too few args in svc_t
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-07 21:03:35 +02:00
Joachim Nilsson d2f23e281f Allow Finit to set hostname at dynamic reload.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-06 19:35:02 +02:00
Joachim Nilsson b5e3e69553 Do not allow VERSION to be overloaded by build system.
When integrating finit as a component in another system, that build
system may set VERSION as an environment variable for that OS -- we do
not want that version to be set as the version of finit.

Also, bump version to 2.0.1-dev for upcoming patch release cycle.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-10-02 15:09:07 +02:00
Joachim Nilsson 8d85e59214 Optimization is a CFLAG, not a CPPFLAG
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-29 22:39:49 +02:00
Joachim Nilsson a1c8ada320 Play around a bit with project title heading.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-29 22:39:19 +02:00
Tobias Waldekranz ae15988eb8 Add hook point on fstab mount failure
Check return code from `mount -na`, if there where any errors give
plugins a chance to do something about it.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-29 22:38:06 +02:00
Joachim Nilsson 9491f18972 service_enabled(): Only check WCOREDUMP() from if WIFSIGNALED()
Patch courtesy of Westermo.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-28 19:17:30 +02:00
Joachim Nilsson 545f3105e2 Update ChangeLog and bump version for v2.0 release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-20 12:27:41 +02:00
Joachim Nilsson eec166a9eb Add simple service script for SysV init compat.
This patch adds a simple `service <script> <stop|start|reload|restart>`
script for for SysV init compatibility.  Very common with users of the
Ubuntu upstart init as well.

Also, fixed `make uninstall` for plugins.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-19 22:04:26 +02:00
Joachim Nilsson 125fc661a3 Makefile: Allow clean and distclean targets when libite/libuev are disabled.
Even though libite and libuEv can be disabled, using the --with-libnnn
option to configure, we let make descend into those submodules for the
clean and distclean targets.  This way we can rely on make dev to work.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-18 09:14:49 +02:00
Joachim Nilsson 6531b2f20a Add --with-libuev=PATH to configure script to use external libuEv
This commit makes it possible to build Finit with an external libuEv.
Without this configure script option the libuev submodule is used.

With an external libuEv we make sure to set the SONAME to libuev.so.1
to prevent any future runtime ABI issues.

Fixes issue #4.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-17 12:59:20 +02:00
Joachim Nilsson 1f84edfb8c Add --with-libite=PATH to configure script to use external libite
This commit makes it possible to build Finit with an external libite.
Without this configure script option the libite submodule is used.

With an external libite we make sure to set the SONAME to libite.so.2
to prevent runtime ABI issues with older libite versions.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-17 11:59:46 +02:00
Joachim Nilsson c354d0e7e6 Upgrade libite to v1.1.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-17 11:19:19 +02:00
Joachim Nilsson 98eb7cfea1 Upgrade libuEv to v1.2.3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-17 11:18:38 +02:00
Joachim Nilsson ec80ce1c9b Add distclean step after Coverity run.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-15 11:58:53 +02:00
Joachim Nilsson ef05983dc8 Fix Coverity CID #149216: Buffer not NUL terminated
We should of course always use `strlcpy()` instead of `strncpy()`.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-15 11:49:47 +02:00
Joachim Nilsson 1c04097dca Update ChangeLog with new features and some Markdown syntax fixes.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-15 09:32:12 +02:00
Joachim Nilsson 36aba8952f Bump version to v2.0-beta1 for upcoming release and rename CHANGELOG.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-15 09:25:05 +02:00
Joachim Nilsson 6e07dd8dec Add support for starting/stopping services on Netlink events
This commit adds support for event based services to Finit.  Along with
the previously added support for multiple instances of the same process,
the feature scope for Finit v2.0 has been reached!

As of now a service can be declared in /etc/finit.conf or /etc/finit.d/
like this:

    service :1 [2345] <!IFUP:eth0,GW> /sbin/dropbear -R -F -p 22 -- SSH daemon

Here the first instance `:1` of dropbear is declared to run in runlevels
2-5, but only if eth0 `IFUP:eth0` is up and a gateway `GW` is set.  When
the configuration changes, a new gateway is set, or somehow a new `IFUP`
event for eth0 is received, then dropbear is not SIGHUP'ed, but instead
stop-started `<!>`.  The latter trick applies to all services, even
those that do not define any events.

Currently inetd services are not supported for event based starting, but
it could easily be added.  Likely scenario is to deny incoming requests
on, e.g., eth0 if there is no gateway.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-15 09:13:33 +02:00
Joachim Nilsson ffa32c6674 README: Clearify how multiple events can be emitted by initctl.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-15 09:05:10 +02:00
Joachim Nilsson c30039facf Minor refactor and cleanup.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-14 01:23:17 +02:00
Joachim Nilsson b13c6421b3 First Netlink plugin prototype.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-11 13:10:20 +02:00
Joachim Nilsson fcaf5d7b76 README.md: Commit to spec for v2.0 release.
The event API, including Netlink events to services, looks OK now
to build the remaining two features on:

- Netlink plugin for GW and IFUP IFDN events
- Generic event support for services

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-11 09:51:10 +02:00
Joachim Nilsson f9ddb1bdfc Make sure to always run HOOK_SVC_RECONF when services have been stopped.
Previously `HOOK_SVC_RECONF` was only called on `initctl reload`,
now we also call it on `initctl emit "STOP"`.  This seems like a
good idea atm, hopefully it will remain a good idea.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-11 08:58:39 +02:00
Joachim Nilsson 5701a00558 Update with idea on generic event support.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-08 08:19:16 +02:00
Joachim Nilsson 9a81bbccbb Update section on new emit <EVENT> support.
This part of the README must be completely overhauled before the
release, so much of the contents is basically just TODO or design
ideas atm.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-08 08:18:49 +02:00
Joachim Nilsson 2fcd0fd899 Merge branch 'wishdev-makefile-glibc-2.20' into dev 2015-09-08 08:01:12 +02:00
Joachim Nilsson 5126017c7e Merge branch 'makefile-glibc-2.20' of https://github.com/wishdev/finit into wishdev-makefile-glibc-2.20 2015-09-08 08:00:39 +02:00
John W Higgins d2ed03e74c Update Makefile for glibc-2.20+ 2015-09-07 16:56:32 -07:00
Joachim Nilsson 525aef10dd Add 'initctl show' as alias for 'initctl status', for convenience.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-06 20:45:56 +02:00
Joachim Nilsson 57031071fb Fix missing "libite/lite.h" include.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-06 20:43:28 +02:00
Joachim Nilsson 0bd57a7826 Fix missing overwrite argument to setenv().
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-02 16:05:42 +02:00
Joachim Nilsson 814ffd9259 Fix missing default PATH for root and non-root users.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-09-02 14:50:46 +02:00
Joachim Nilsson f94db7bceb Remove local macros for bitmanip, now provided by libite
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-08-22 14:00:12 +02:00
Joachim Nilsson 98ba5955c8 README: Document initial ideas for future event support
Writing TODO's in the README makes it a promise ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-08-22 13:56:36 +02:00
Joachim Nilsson 52c51f16ed Move to use dockerized/faster build at Travis-CI
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-08-22 13:55:07 +02:00
Joachim Nilsson 3b1e652d40 libite: Upgrade libite to v1.0.0+, lots of fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-08-22 13:53:50 +02:00
Joachim Nilsson d6490df9a3 inetd.c: Improve error detection in inet port conversion.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-07-10 19:10:28 +02:00
Joachim Nilsson 0fd9aa6497 The atonum() function is now provied by libite.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-07-10 19:06:51 +02:00
Joachim Nilsson b30678bbe9 Functions makepath() and ifconfig() now provied by libite.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-07-10 18:33:47 +02:00
Joachim Nilsson 1db144c677 Functions pidfile_read() and pidfile_poll() now provied by libite.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-07-09 03:24:20 +02:00
Joachim Nilsson 8b8ddc43b5 Refactor: Further API cleanup -- hide svc_t internals.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-29 01:50:21 +02:00
Joachim Nilsson 838ec0423d Fix: Loss of dynamic service on second reload (unmodified).
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-29 01:25:45 +02:00
Joachim Nilsson 05a8ace030 Add support for 'initctl emit EVENT' for more granular control.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-29 00:58:12 +02:00
Joachim Nilsson a05f920292 Refactor: Cleanup internal API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-28 17:23:07 +02:00
Joachim Nilsson d8b331d737 Update .gitignore
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-28 17:20:56 +02:00
Joachim Nilsson 381a32bf8a Upgrade libite to fix copyfile() bug.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 22:43:04 +02:00
Joachim Nilsson ee9e49f412 Makefile: Do not fail anymore on warnings, not useful in production.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 22:04:14 +02:00
Joachim Nilsson ff2df8ce5c Upgrade libite, handle missing O_TMPFILE gracefully.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 22:03:32 +02:00
Joachim Nilsson e595e9da5f Upgrde to libite version with new tempfile()
The tempfile() replacement in Finit leaked temporary files in /tmp.
The mkstemp() based implementation does not remove temporary files
when they are closed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 21:44:46 +02:00
Joachim Nilsson f1807a32ca Make it possible to distribute finit.h in 'make dev-install'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 9a6ab331a6 Refactor: Move rest of finit.h settings to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 70af5d7f8d Refactor: Move HAVE_DBUS and CONSOLE to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 36c59e77b4 Fix broken SYSROOT and add it to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 57b167f9aa Refactor: Move root fs remount setting to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 155ae15390 Refactor: Move random seed config to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 06a1a3c839 Refactor: Move default runlevel to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 42f3d4dc79 Refactor: Move DEFUSER and DEFHOST to configure script
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 8e12dba8d9 Refactor: Move conf.c declarations from finit.h --> conf.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 589a7ea8a5 Always run HOOK_SVC_RECONF on SIGHUP/reload
When Finit receives SIGHUP or a reload command all services listed in
/etc/finit.d/*.conf are first stopped and then started again.  I.e.,
removed/changed services are stopped and then new/changed services are
started again.  In between we call HOOK_SVC_RECONF.  It should always be
called, even though no services were removed/changed/added.  This to
allow plugins connected to that hook may need to run as intended.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson e5732f24d3 Followup to tempfile(): template must be writable.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-22 15:12:20 +02:00
Joachim Nilsson 3d0e58ebcd Followup to tempfile(): paranoid umask as well ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 22:25:33 +02:00
Joachim Nilsson 162b394726 Replace insecure tmpfile() with mkstemp() based local tempfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 21:54:24 +02:00
Joachim Nilsson c6a9fa3b98 initctl: Order inetd filters same as in .conf file.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 19:06:07 +02:00
Joachim Nilsson e04c73bab8 initctl: Add UDP/TCP to presentation of inetd services in verbose mode.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 18:55:05 +02:00
Joachim Nilsson ac0edc9b37 initctl: Fix broken presentation of inetd services in verbose mode.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 18:54:29 +02:00
Joachim Nilsson 59731988fd initctl: Add support for showing current runlevel
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 18:30:01 +02:00
Joachim Nilsson d0da3b8b98 Followup to 'initctl with process name as well as JOBID'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 17:56:41 +02:00
Joachim Nilsson be074abce8 Followup libite submodule, use https not git proto.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 16:29:16 +02:00
Joachim Nilsson 577622c945 Add support for calling initctl with process name as well as JOBID
This patch makes it possible to communicate process name or JOB[:ID]
from initctl to Finit.  When the process name translates into a service
with multiple instances Finit applies the requested command to all
instances.  For example, two Dropbear SSH services running on two
different ports, calling `initctl stop dropbear` stops both services.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-21 15:54:47 +02:00
Joachim Nilsson 5d2172eac8 Upgrade to libuev -dev.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-18 08:44:41 +02:00
Joachim Nilsson 276cda9a4d Install -dev files for both libite and libuev, needed for external plugins.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-18 08:44:15 +02:00
Joachim Nilsson bafdf0007f Helper macros moved to libite/lite.h
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-18 02:26:53 +02:00
Joachim Nilsson 064e94e030 Add/readd libite, now as a separate submodule.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-18 02:26:47 +02:00
Joachim Nilsson c00ac21fe2 Remove libite and chomp() in preparing for ... libite.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-18 01:11:22 +02:00
Joachim Nilsson 164fe12685 Update ChangeLog
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 14:27:34 +02:00
Joachim Nilsson e7dad9a770 Add inetd.h to distributed headers, needed for external plugins.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 14:07:35 +02:00
Joachim Nilsson 02e5c868ba Makefile: Declare dependencies better, for parallel builds
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 14:07:30 +02:00
Joachim Nilsson 66f472bb05 service_start(): Make sure to collect the run child.
Fix side effect with run stanza children not being collected if finit is
not run in verbose mode.  Regression introduced in release cycle.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:36 +02:00
Joachim Nilsson 7b894fcf52 Prune and relocate #include files.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:36 +02:00
Joachim Nilsson 0de4fb0cbf inetd: Fix naming of built-in service on custom port.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:36 +02:00
Joachim Nilsson 231539cd7d Move all custom banner() handling to configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:36 +02:00
Joachim Nilsson 195f17ae08 TODO: Markdown syntax fixes.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:36 +02:00
Joachim Nilsson 54ace1a6cf README: Further updates and corrections to inetd syntax.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:36 +02:00
Joachim Nilsson 1f19b50846 Fix Coverty CID #96208: Unchecked return value from library.
Replace `remove()` with our own `erase()` which checks the return value
and warns on actual real failure.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:17 +02:00
Joachim Nilsson 6c58a7d774 Fix Coverty CID #96209: Dereference NULL return value.
The new iterators `svc_inetd_iterator()` and `svc_dynamic_iterator()`
used unsafe constructs that could cause them, at least the latter, to
dereference a `NULL` pointer.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:06 +02:00
Joachim Nilsson dbcece81ea Fix Coverty CID #96210: Argument cannot be negative.
We must check the return value from `accept()`, it may fail.  Also, we
should probably retry the syscall in some cases ...

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:36:06 +02:00
Joachim Nilsson 70f4d99922 Fix Coverty CID #96211: String not NUL terminated.
When receiving a start/stop/reload/restart request from initctl we must
make sure to validate and NUL terminate the job ID.  The `read()` API
does not NUL terminate strings for us and we cannot rely on `initctl` or
any other external API user to do so for us.

This patch improves error and boundary checking.

- Use memcpy() + hard termination instead.
- Fix use of strchr() on possibly non-NUL terminated string.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-17 13:35:10 +02:00
Joachim Nilsson ee6d524bc8 Update ChangeLog and README for release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-15 22:43:03 +02:00
Joachim Nilsson d9055c3965 Fix build/install --with-plugins='a b' -- only build/install a and b
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-15 16:55:17 +02:00
Joachim Nilsson 03573b41ca Add support for a deny filter syntax to inetd services
This patch changes the syntax for custom inetd services and adds support
for deny filters.  The new syntax is:

    inetd service/proto[@iface,!iface,...] </path/to/cmd | internal[.service]>

This means the second column now defines what@from and the third to/what
process.  For internal services on a custom port the internal.service
syntax must be specified, so Finit can properly bind the inetd service
to the correct plugin.  Here follows a few examples:

    inetd time/udp                    wait [2345] internal                -- UNIX rdate service
    inetd time/tcp                  nowait [2345] internal                -- UNIX rdate service
    inetd 3737/tcp                  nowait [2345] internal.time           -- UNIX rdate service
    inetd telnet/tcp@*,!eth1,!eth0, nowait [2345] /sbin/telnetd -i -F     -- Telnet service
    inetd 2323/tcp@eth1,eth2,eth0   nowait [2345] /sbin/telnetd -i -F     -- Telnet service
    inetd 222/tcp@eth0              nowait [2345] /sbin/dropbear -i -R -F -- SSH service
    inetd ssh/tcp@*,!eth0           nowait [2345] /sbin/dropbear -i -R -F -- SSH service

Access to telnet on port `2323` is only possible from interfaces `eth0`,
`eth1` and `eth2`.  The standard telnet port (`23`) is available from
all other interfaces, but also `eth2`.  The `*` notation used in the ssh
stanza means *any* interface, however, here `eth0` is not allowed.

NOTE: This patch breaks syntax compatibility with Finit v1.12!

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-15 14:15:39 +02:00
Joachim Nilsson b0c759e518 Add missing file api.c
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-15 14:06:55 +02:00
Joachim Nilsson 1a1f24721f Refactor: introduce telinit and a new initctl tool w/ API
- Reduce size of `helpers.c`, for linking against new `initctl` tool,
  by moving out functions to `pid.c` and `exec.c`
- Add `AF_UNIX` API to Finit, to complement old `/dev/initctl` FIFO
- Let old FIFO API be used by init/telinit: `init <q | 1-9>`
- Move all advanced initctl code from `client.c` to `initctl.c`, yes
  its a bit confusing to call the *new* tool the same as the old FIFO
  but this is more in line with what, e.g Upstart does.
- Move all advanced server side code from `plugins/initctl.c` to `api.c`
- Update TODO with upcoming inetd syntax change and dynamic events.
- Temporarily fix display of inetd services from `initctl status -v`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-13 12:26:16 +02:00
Joachim Nilsson 66edb42e06 Upgrade to libuev v1.2.0
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-09 14:57:41 +02:00
Joachim Nilsson 4e904142cb configure: Reverse kernel-quiet, enable --> disable, enabled by default.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-08 18:08:08 +02:00
Joachim Nilsson 7b5d56df98 TODO: Document proposal for dynamic event framework
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-08 18:07:40 +02:00
Joachim Nilsson 1d58f4abbe initctl: New symlink to finit binary, document functions in README.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-08 18:06:55 +02:00
Joachim Nilsson 24e1d284ad Add support for finit <stop|start|reload|restart> JOB
This patch further extends the capabilities of the client with the
ability to control the running state of services:

    finit <stop|start|reload|restart> JOB

Since services can now exist with multiple instances the concept of
"jobs" is introduced in this patch.  A job is a numeric identifier of
the form `NUM[:NUM]`, the latter `:NUM` is the new instance syntax
introduced earlier.  See the output of `finit status` for the JOB id.

Also, with the introduction of multiple instances we broke support for
multiple related inetd services.  This became obvious when the shiny new
`finit status` was tested ... hence, this patch also contains fixes to
the inetd support.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-08 08:32:49 +02:00
Joachim Nilsson 720324b256 Change syntax for multiple instances: #ID --> :ID
Turns out that #ID syntax for multiple instances, introduced in cb07556,
was very cumbersome to reference from the shell command line in the new
Finit client.  This patch changes the syntax from #ID to :ID, which also
means that listing services/jobs in the shell will look like JOB:ID.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-08 01:07:41 +02:00
Joachim Nilsson 534979e6c7 inetd_match(): Fix bug in matcher, make sure to also compare protocol!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-08 00:54:54 +02:00
Joachim Nilsson 6a27ad8997 Improve output from 'finit status'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 16:26:11 +02:00
Joachim Nilsson 6d3972cca8 Add --enable-kernel-quiet to configure, delayed quiet after initial boot.
... with the additional twist that the kernel command line option
'quiet' also gets to play.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 16:20:23 +02:00
Joachim Nilsson f8d608107c Allow quiet mode to disable banner, also simplify default banner.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 16:06:23 +02:00
Joachim Nilsson 0dd97de046 Add --enable-quiet to configure, makes Finit real quiet.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 15:57:11 +02:00
Joachim Nilsson 2026486fda Refactor: Cleanup and expand client code to support <version|q|reload|debug>
Further refactoring of the client code.  Supported commands:

- debug:   Toggle PID 1 debug flag
- version: Show Finit version or custom header string
- reload:  Reload config files in /etc/finit.d/, same as SIGHUP

Also supported is the legacy 'init q' command, to reload config.

The 'status' command now supports an optiona '-v', either as an
argument to init itself, or as argument to the command.  When it
is given 'status' lists verbose information about all services.
Currently only the service arguments are listed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 12:11:07 +02:00
Joachim Nilsson 811bd75eab Refactor: Move client code to separate file and add 'status' command.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 12:09:55 +02:00
Joachim Nilsson 97a48ec5fb Refactor: move advanced service methods from svc.c --> service.c
This patch refactors svc.c into two files: svc.c now as a low-level
svc_t API and service.c for the more advanced rest.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-07 03:23:46 +02:00
Joachim Nilsson 8e9a5ee678 Update README on Inetd services and cleanup TODO.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-06 11:30:38 +02:00
Joachim Nilsson 7236e8c6a3 conf.c: Clarify comments, also include file paths must now be absolute.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-06-06 11:29:53 +02:00
Joachim Nilsson 2c1f3b1f7a Make sure to also reload all .conf files in /etc/finit.d/ when changing runlevel.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 22:45:30 +02:00
Joachim Nilsson f5584ecc3c Add two new hook points: HOOK_SVC_RECONF and HOOK_RUNLEVEL_CHANGE.
These two new hooks run when SIGHUP is received and when changing
system runlevel.  The hooks are called when all services have been
stopped, just before starting up new/modified services.  Making it
the perfect hook for reconfiguring the system/hardware before new
services or modified services are started up again.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 22:07:46 +02:00
Joachim Nilsson e83f4ab4bf TODO: Fixed some items.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 01:58:20 +02:00
Joachim Nilsson fa89370517 Fix pid_get_name() when NULL buffer is provided.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 01:58:20 +02:00
Joachim Nilsson 2cba0c73be Fix for unwanted zombies ...
When receiving SIGCHLD we must reap *all* children.  We only receive one
signal, but multiple processes may have exited.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 01:58:20 +02:00
Joachim Nilsson cb075560ed Add support for multiple instances of the same command
This patch adds support for starting and supervising multiple
services (run, task, or service) using an extra #ID number.

service #1 [2345] /sbin/httpd -f -h /http -p 80   -- Web server
service #2 [2345] /sbin/httpd -f -h /http -p 8080 -- Old web server

Also included in this patch is a fix for endless respawn of faulty
services.  For instance, a buggy daemon that crashes repeatedly will now
be stopped after 10 respawns.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 01:58:20 +02:00
Joachim Nilsson 687f52b0b5 Add support for adding/removing services from /etc/finit.d at runtime.
This patch adds support for adding and removing services from Finit at
runtime.  Configuration file stanzas for service, run and task may now
be written to files in /etc/finit.d/*.conf, using the exact same syntax
as before in /etc/finit.conf.  When a file is added, removed or modified
the user may simply SIGHUP Finit (PID 1) to activate the changes.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-05-31 01:55:39 +02:00
Joachim Nilsson 24051ab2fb TODO: Update with plan for dynamic services being loaded from /etc/finit.d
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-27 08:10:11 +02:00
Joachim Nilsson 9139afd318 Bump version for -dev cycle.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-25 10:18:40 +02:00
Joachim Nilsson 71ecead5b7 Make the 'init <CMD | RUNLEVEL>' commands synchronous.
When a user changes runlevel, or wants to reload the config, we want the
command to return only when the operation has completed.  For instance,
rolling in a new system configuration in runlevel 1 requires that we are
sure we've actually entered that runlevel before rolling it in.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-25 10:17:46 +02:00
Joachim Nilsson 56292f27c2 Add missing FINIT_RCSD to config.mk, needed by install/uninstall.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-23 19:44:44 +02:00
Joachim Nilsson 14c2f612cf Rename patches --> contrib to simplify integration in 3rd party build systems.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-04-23 11:40:48 +02:00
Joachim Nilsson e9506aec1c .travis.yml: Update Travis build script to include configure
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-10 22:49:52 +01:00
Joachim Nilsson d2eb46c173 Fix last part of issue #8: Libite install problem with --enable-static
Skip install of .so libs when user has configured with --enable-static

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-10 22:12:26 +01:00
Joachim Nilsson 0d733ad234 Merge pull request #9 from therealprologic/disable_plugins
Add a --disable-plugins option to ./configure (Fixes #8)
2015-03-10 22:05:34 +01:00
James Mills 4955e05882 Add a --disable-plugins option to ./configure (Fixes #8) 2015-03-11 07:04:38 +10:00
Joachim Nilsson c3fcfe7e4e README: Update with info on new configure script.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-10 11:20:39 +01:00
Joachim Nilsson 32587d341c Overhaul build system and add support for disabling inetd support.
This patch adds support for a configure script and with it
support for disabling inetd support.  See the output from

    ./configure --help

* Add configure script
* Sprinkle #ifdef fairy dust on svc.c when inetd support is disabled
* Use GCC built-in autodep calculator (-MMD -MP)
* Fix name space issue with include files, use relative paths
* Disable username/group name to uid/gid functions in static builds
* Bug out (error) if a user tries to build the bootmisc plugin static

Possibly fixes GitHub issue #5 and issue #6.

NOTE: The static build has not received any testing at all!

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-10 10:25:46 +01:00
Joachim Nilsson a74b640507 Initial support for building Finit statically (incomplete)
This patch adresses issue #5.  However, there still remains a few issues
to work around before Finit can be built completely standalone.

    $ make clean all STATIC=1
    LINK    finit
    helpers.o: In function `getgroup':
    helpers.c:(.text+0x10a7): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    helpers.o: In function `getuser':
    helpers.c:(.text+0x108e): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    inetd.o: In function `getent':
    inetd.c:(.text+0x127): warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
    inetd.c:(.text+0xce): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

The problem is the NSS plugins and similar issues that prevent static
linking when using the above functions.  See issue #5 for more on this.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-06 21:58:56 +01:00
Joachim Nilsson 52664791f5 Upgrade to libuev with support for static-only builds.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-06 21:34:46 +01:00
Joachim Nilsson cf651df744 Bump version for v1.12 release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 17:00:37 +01:00
Joachim Nilsson 807df44769 finit.conf: Update sample config with some example inetd services.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 16:59:53 +01:00
Joachim Nilsson f97bc83ac1 Update libuev to v1.1.0 +1, with .gitignore update.
This commit prevents false warnings about untracked files in libuev.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 16:14:18 +01:00
Joachim Nilsson daa299721d inetd.c: Check for SO_REUSEPORT capability in system first.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 15:54:13 +01:00
Joachim Nilsson ec90e3dac3 Update ChangeLog before release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 15:32:49 +01:00
Joachim Nilsson 5ddd5c15a5 inetd.c:spawn_socket() - Set socket options for reusing address and port
Without this patch binding to sockets when restarting them fails.  This
was found when quickly changing between runlevels where a service runs,
not runs, then back to a runlevel where is shall run.

Also, refactor previous setsockopt() call to use new common macro.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 15:21:43 +01:00
Joachim Nilsson 957586db09 inetd.c:inetd_dgram_peek() - Fix reading inbound UDP interface.
There seems to have been a regression from earlier when this worked.
I'm sure it worked ... or am I?  This patch makes the whole thing look
a lot more sane, so I wonder ... might have worked in my unit tests on
x86, but not when I cross-compile to ARM.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 15:15:03 +01:00
Joachim Nilsson e0c8a7df66 inetd.c: Shutdown sockets properly before closing them.
When changing runlevels netstat still listed closed sockets as being
open and listening.  With this patch all sockets are properly shut down
before we close them.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 14:45:21 +01:00
Joachim Nilsson c769fbda0f svc.c: Add debug to svc_runlevel().
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 14:45:04 +01:00
Joachim Nilsson 1f860164f4 initctl: Make sure to open fifo with CLOEXEC
With O_CLOEXEC we prevent forked+exec'ed children from accessing the
initctl fifo via that socket.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 14:43:06 +01:00
Joachim Nilsson e29c5c069b TODO: Minor update.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 11:49:28 +01:00
Joachim Nilsson 872d0d24e7 inetd.c: Only ever allow respawn if correct runlevel.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 11:48:16 +01:00
Joachim Nilsson b644f6f635 plugins/initctl.c: Minor debug updates.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 11:47:14 +01:00
Joachim Nilsson 510d15195c plugins.c:generic_io_cb() -- Stop watcher before running callback
Stop event watcher before running callback, the plugin may manipulate
the descriptor and cause the kernel into a EPOLLHUP frenzy.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 11:46:32 +01:00
Joachim Nilsson 7ad4bce487 Upgrade to libuEv v1.1.0 for error handling fixes.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-04 11:02:01 +01:00
Joachim Nilsson 703b7537cf Refactor inetd support to add support for switching runlevels.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-03-01 02:35:30 +01:00
Joachim Nilsson 9cb6c88f34 Spellchecks, cleanup and simplify intro.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-27 10:02:08 +01:00
Joachim Nilsson 97068223ff CHANGELOG: Add user-friendly info on the 1.12 release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-27 00:14:49 +01:00
Joachim Nilsson 1de5777f7e README: Update with new inetd support.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-27 00:14:14 +01:00
Joachim Nilsson aff11d83d8 tty.c: Let fallback shells be consoles, improved job control etc.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 18:57:17 +01:00
Joachim Nilsson 335f09726f conf.c: Slight update in TTY fallback behavior.
If no tty is configured in finit.conf, only use FALLBACK_SHELL (usually
/bin/sh on UNIX) when no console is configured either.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 18:57:10 +01:00
Joachim Nilsson 12c470667f Only restart daemons when getting SIGCONT after SIGSTOP
Fix `restart_any_lost_procs()`, called when finit recovers from being
stopped for a while.  This function should not restart task/run/inetd
services when called -- must check for type `SVC_CMD_SERVICE` when
iterating over all registered `svc_t`, just like a regular lost pid.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 16:55:15 +01:00
Joachim Nilsson 71ac8bb802 Set hostname early, so boostrap processes, e.g., syslog can use it.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 16:47:55 +01:00
Joachim Nilsson fc9758da8e Fix Coverity CID #87811 Double close
Fix double close of TCP socket introduced in GIT ded4b39,
replaced with closing all open stdio descriptors, which
shouldn't really be needed.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 16:39:30 +01:00
Joachim Nilsson 216701ce3c Attempt to fix Coverity CID #87810 Dereference null return value
Fixes, or rather works around the Coverity warning of possible NULL
pointer dereference.  (Not an error.)

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 16:34:38 +01:00
Joachim Nilsson 5d5075954e TODO: Add some ideas on pmon to watchdog chapter.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 16:14:29 +01:00
Joachim Nilsson ded4b3926e Refactor inetd support, now with support for custom ports and iface filtering
This patch adds support for custom port and interface filtering to inetd
services, in a very condensed syntax:

    inetd ssh@eth0:222/tcp nowait [2345] /usr/sbin/sshd -i
    inetd ssh@eth1:22/tcp  nowait [2345] /usr/sbin/sshd -i

In this example eth0 and eth1 are allowed inbound interfaces for SSH
connections, on port 222 and 22, respectively.  Attempting to connect
from any other interface is denied.  Also, if the system is not in
runlevel 2, 3, 4, or 5, ports 222 and 22 will not even be opened.

If eth0 is your upstream interface you may want to avoid using the
default port.  To run ssh on port 222, and all others on port 22:

    inetd ssh@eth0:222/tcp nowait [2345] /usr/sbin/sshd -i
    inetd ssh/tcp          nowait [2345] /usr/sbin/sshd -i

This actually adds a deny rule for eth0 on ssh/tcp, implicitly.  You can
even list the services in the reverse order with the same result:

    inetd ssh/tcp          nowait [2345] /usr/sbin/sshd -i
    inetd ssh@eth0:222/tcp nowait [2345] /usr/sbin/sshd -i

There is no specific deny syntax available yet, see the TODO file for
more details on how this can be implemented.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-26 01:37:11 +01:00
Joachim Nilsson 365932510f Update dreamworld.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-25 10:13:44 +01:00
Joachim Nilsson 888128e56b README: Slight cleanup to make it more readable w/o Markdown.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-25 10:13:12 +01:00
Joachim Nilsson 2adec264af Replace atoi() with atonum() --> better error handling.
Friends don't let friends use atoi().

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-25 10:12:15 +01:00
Joachim Nilsson ccdab464c3 Fix Coverity CID 87570: Unchecked return value from setsockopt()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 23:10:30 +01:00
Joachim Nilsson a7353678a3 Actually fix Coverity CID 56281: dlopen() resource leak
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 22:59:32 +01:00
Joachim Nilsson ad8ae4af91 Fix Coverity CID CID 56281: Resource leak (RESOURCE_LEAK)
Initial support for unloading plugins.  Currently we only save dlopen()
handle.  The plugin_unregister() function itself is never called atm.
This should at the very least make Coverity happy.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 22:39:54 +01:00
Joachim Nilsson dd7f0ce090 Fix Coverity CID 87571: Uninitialized scalar variable (UNINIT)
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 22:18:02 +01:00
Joachim Nilsson 8c955836dd Load plugins before finit.conf is parsed, needed by internal inetd services
This patch is slightly sub-optimal, since it will causes us to load all
availble plugins, not just those referenced by finit.conf.  However, in
the short term perspective we need to reference internal inted services
provided by plugins from finit.conf, so the dependency order is clear.

In the midterm perspective we want to add support for SIGHUP to reload
finit.conf, but not plugins.  So again, this is an OK patch.

One fix would be to allow loading of all plugins, parse finit.conf and
then unload all unused plugins before continuing.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 22:04:36 +01:00
Joachim Nilsson 183022ebe4 Initial support for RFC 868 (rdate), internal inetd service.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 22:04:31 +01:00
Joachim Nilsson 33be077f92 TODO: Remember to support non-getty logins.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 16:53:00 +01:00
Joachim Nilsson 6a137fa73c TODO: Update with info on internal inetd services, like time, echo etc.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-18 15:17:00 +01:00
Joachim Nilsson 25c85dfc88 Add markdown hinting for Emacs.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-16 10:27:16 +01:00
Joachim Nilsson 58cc96115c Initial support for figuring out inbound interface for inetd connections
This patch adds initial support (only SOCK_STREAM verified!) for
figuring out the inbound interface for inetd service connections.

The intention is to use this later on for a very simple tcpwrappers
replacement, e.g: `deny telnet eth0 eth3`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-16 10:26:54 +01:00
Joachim Nilsson b4b63d3722 Trap segfaults caused by service callbacks in separate process context
This patch traps segfaults caused by 3rd party service callbacks in a
separate process context.  Effectively preventing a single programming
mistake from taking down the entire system.  Previously it was up to the
callback coder to write error free code so that PID 1 did not crash.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-16 10:21:03 +01:00
Joachim Nilsson d6efe85a57 Silence launch of inetd services.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-09 00:57:21 +01:00
Joachim Nilsson 51b27e8372 Revert "Use vfork() instead of fork() before exec()"
This reverts commit 074686b520.  Which
turned out to not work so well after all.  For instance, launching TTYs
in a background process completely blocked inetd services from even
starting up listening sockets ... proper fork seems to work fine though.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-09 00:45:09 +01:00
Joachim Nilsson cac612c485 Remember to fix these ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-09 00:43:33 +01:00
Joachim Nilsson a5b9f566b3 Initial support for inetd/on-demand services \o/
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-09 00:43:15 +01:00
Joachim Nilsson 0d098616e8 Whitespace changes only
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-01 17:28:36 +01:00
Joachim Nilsson 63722a20ac Allow mixed case configuration commands in finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-02-01 17:27:18 +01:00
Joachim Nilsson 6f6ab6bc33 Minor whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-29 12:34:30 +01:00
Joachim Nilsson 7f0a85c106 Updated inetd syntax and add possible bug, needs investigating.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-29 12:33:35 +01:00
Joachim Nilsson 46ddf4bcc6 Commence new -dev phase.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 23:56:52 +01:00
Joachim Nilsson f5ab075f9d Upgrade libuEv to v1.0.4
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 23:54:53 +01:00
Joachim Nilsson 9b361864fa Fix make dist target for v1.11 release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 16:16:13 +01:00
Joachim Nilsson 41b0dc41a6 Update ChangeLog for v1.11 release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 16:13:46 +01:00
Joachim Nilsson cab339c857 Simplify build example.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 16:07:55 +01:00
Joachim Nilsson dcb42602c9 Cleanup README for release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 16:04:54 +01:00
Joachim Nilsson 9e446557b4 Change Coverity Scan branch to use 'dev' instead of master.
We don't want to run out of scan tokens for every README update.  This
also means the introduction of a new workflow.  All new development must
be staged to the dev branch before being merged to master.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-24 15:29:16 +01:00
Joachim Nilsson a3d76c58a4 Expand on how plugins can interact with system bootstrap.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-21 19:34:01 +01:00
Joachim Nilsson e0e0581d10 Trim slogan ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-21 13:29:35 +01:00
Joachim Nilsson ef75d5ec31 Cleanup Introduction and add Bootstrap section.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-21 13:25:24 +01:00
Joachim Nilsson dfeabd8bae Improve inetd syntax proposal
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-21 13:15:16 +01:00
Joachim Nilsson 7aa687bad9 Reindent to more 'pure' Markdown and remove fixed event lib TODO.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-19 21:24:06 +01:00
Joachim Nilsson c2ea2c1193 Reindent to more 'pure' Markdown.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-19 21:12:14 +01:00
Joachim Nilsson 291b22e987 Give up and add actual link to GIT commit.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 23:46:21 +01:00
Joachim Nilsson a091b69dd6 Another try ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 23:45:16 +01:00
Joachim Nilsson 887c84a0d1 Attempt to fix GIT commit auto linking.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 23:44:27 +01:00
Joachim Nilsson 5009d54ab8 Reindent to more 'pure' Markdown.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 23:43:04 +01:00
Joachim Nilsson 840ade6da7 Bump version for next release, fix make dist and rename NEWS --> CHANGELOG
- Bump version for coming 1.11 release
- Update `make dist` to use Kentzo's `git-archive-all` from
  https://github.com/Kentzo/git-archive-all
- Rename NEWS --> CHANGELOG and update for coming release
- Update CHANGELOG with info on the libuEv migration

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 23:22:39 +01:00
Joachim Nilsson 030aa70842 Simplify.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 22:29:34 +01:00
Joachim Nilsson dea3ae857b Steal controlling TTY on fallback console to enable job control.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 22:25:04 +01:00
Joachim Nilsson 9f5172b0d1 Try removing delayed start of TTYs, should not be needed anymore.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 21:40:09 +01:00
Joachim Nilsson e0529a5597 Unblock all signals blocked by finit when starting children
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 21:40:05 +01:00
Joachim Nilsson 425cd17e57 Initial conversion to use libuEv for all event handling.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 00:53:14 +01:00
Joachim Nilsson 0669a9cb81 Fix missing #include for copyfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-18 00:46:06 +01:00
Joachim Nilsson 5e040449c4 Add libuEv as submodule for event handling.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-07 02:59:21 +01:00
Joachim Nilsson 074686b520 Use vfork() instead of fork() before exec()
If running on older Linux systems, or any BSD UNIX, vfork()
is more efficient when we are about to call exec() anyway.

For more info on vfork() vs fork(), see Stack Exchange:
http://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork-and-vfork

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-06 23:38:47 +01:00
Joachim Nilsson d40f52357e Restructure and add section on Watchdog process supervision
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-06 21:45:14 +01:00
Joachim Nilsson 076f77a31b Update TODO: more on inetd and at support.
Also a minor fix to the README.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-06 20:54:52 +01:00
Joachim Nilsson 8f1c16a8a5 Update TODO with section on Cron.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-01 02:04:50 +01:00
Joachim Nilsson b149dbc73e Update TODO
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2015-01-01 00:11:44 +01:00
241 changed files with 23187 additions and 6595 deletions
+45
View File
@@ -0,0 +1,45 @@
Contributor Code of Conduct
===========================
As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all
people who contribute through reporting issues, posting feature
requests, updating documentation, submitting pull requests or patches,
and other activities.
We are committed to making participation in this project a
harassment-free experience for everyone, regardless of level of
experience, gender, gender identity and expression, sexual orientation,
disability, personal appearance, body size, race, ethnicity, age,
religion, or nationality.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic
addresses, without explicit permission
* Other unethical or unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit,
or reject comments, commits, code, wiki edits, issues, and other
contributions that are not aligned to this Code of Conduct. By adopting
this Code of Conduct, project maintainers commit themselves to fairly
and consistently applying these principles to every aspect of managing
this project. Project maintainers who do not follow or enforce the Code
of Conduct may be permanently removed from the project team.
This code of conduct applies both within project spaces and in public
spaces when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may
be reported by opening an issue or contacting one or more of the project
maintainers.
This Code of Conduct is adapted from the [Contributor Covenant][1],
[version 1.2.0][2].
[1]: http://contributor-covenant.org
[2]: http://contributor-covenant.org/version/1/2/0/
+79
View File
@@ -0,0 +1,79 @@
Contributing to Finit
=====================
We welcome any and all help in the form of bug reports, fixes, patches
for new features -- *preferably as GitHub pull requests*. Other methods
are of course also possible: emailing the maintainer a patch or even a
raw file, or simply emailing a feature request or an alert of a problem.
For email questions/requests/alerts there is always the risk of memory
exhaustion on the part of the maintainer(s).
If you are unsure of what to do, or how to implement an idea or bugfix,
open an issue with `"[RFC: Unsure if this is a bug ... ?"`, or similar,
so we can discuss it. Talking about the code first is the best way to
get started before submitting a pull request.
Either way, when sending an email, patch, or pull request, start by
stating the version the change is made against, what it does, and why.
Please take care to ensure you follow the project coding style and the
commit message format. If you follow these recommendations you help
the maintainer(s) and make it easier for them to include your code.
Coding Style
------------
> **Tip:** Always submit code that follows the style of surrounding code!
First of all, lines are allowed to be longer than 72 characters these
days. In fact, there exist no enforced maximum, but keeping it around
100 chars is OK.
The coding style itself is strictly Linux [KNF][].
Commit Messages
---------------
Commit messages exist to track *why* a change was made. Try to be as
clear and concise as possible in your commit messages, and always, be
proud of your work and set up a proper GIT identity for your commits:
git config --global user.name "Jane Doe"
git config --global user.email jane.doe@example.com
Example commit message from the [Pro Git][gitbook] online book, notice
how `git commit -s` is used to automatically add a `Signed-off-by`:
Brief, but clear and concise summary of changes
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as
the subject of an email and the rest of the text as the body. The
blank line separating the ummary from the body is critical (unless
you omit the body entirely); tools like rebase can get confused if
you run the two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
Signed-off-by: Jane Doe <jane.doe@example.com>
Code of Conduct
---------------
It is expected of everyone engaging in the project to, in the words of
Bill & Ted; [be excellent to each other][conduct].
[github]: https://github.com/troglobit/finit/
[KNF]: https://en.wikipedia.org/wiki/Kernel_Normal_Form
[gitbook]: https://git-scm.com/book/ch5-2.html
[conduct]: CODE-OF-CONDUCT.md
+3
View File
@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: [troglobit]
+12
View File
@@ -0,0 +1,12 @@
# Security Policy
## Supported Versions
finit is a small project, as such we have no possibility to support older versions.
The only supported version is the latest released on GitHub:
<https://github.com/troglobit/finit/releases>
## Reporting a Vulnerability
Contact the project's main author and owner to report and discuss vulnerabilities.
+44 -3
View File
@@ -1,6 +1,47 @@
*~
*.o
.*.d
*.so
*.gz
*.map
finit
ID
GPATH
GRTAGS
GSYMS
GTAGS
# GNU configure and build system
/aux
/.deps
/autom4te.cache
/aclocal.m4
/ar-lib
/compile
/config.cache
/config.h
/config.mk
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/ltmain.sh
/missing
/Makefile
/Makefile.in
/stamp-h1
/test-driver
/test-suite.log
# TroglOS build system
/.config
/.stamp
/.unpacked
# WeOS build system
/.autoconf
/.automake
/.built
+47 -6
View File
@@ -1,21 +1,62 @@
# Travis CI integration -- https://travis-ci.org/troglobit/finit
# Defaults to GNU GCC and autotools: ./configure && make && make test
language: c
# Use docker for quicker builds, it now allows https://docs.travis-ci.com/user/apt/
sudo: false
# Test build with both GCC and Clang (LLVM)
compiler:
- gcc
- clang
# The secure: declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
env:
global:
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- PKG_CONFIG_PATH=/tmp/lib/pkgconfig
- CFLAGS="-W -Wall -Wextra"
- secure: "eOiuHs02lG2Uv146K9dMqucGTWUJFEhpz1oAtwe+kPrRXsXWc20hYMO+DSpMgD05vSvNeQA6p7h7LdRFQ+/g/Obj27TsOE+RKkUvRAtdwzxnKVyii9C/nmML8cFw7rIA0VS8O9mAkVYeyDxNDupBp3e9DPCibhKPvqCvioTnyy4="
addons:
apt:
packages:
- tree
coverity_scan:
project:
name: "troglobit/finit"
description: "finit | Fast Init Replacement"
description: "finit | Fast & Extensible init for Linux"
notification_email: troglobit@gmail.com
build_command: "make"
branch_pattern: master
build_command_prepend: "./autogen.sh && ./configure --prefix= --disable-doc --disable-contrib --with-watchdog"
build_command: "make"
branch_pattern: dev
script: make
install:
- wget https://github.com/troglobit/libuev/releases/download/v2.3.2/libuev-2.3.2.tar.xz
- wget https://github.com/troglobit/libite/releases/download/v2.3.1/libite-2.3.1.tar.gz
- tar xf libuev-2.3.2.tar.xz
- tar xf libite-2.3.1.tar.gz
- (cd libuev-2.3.2 && ./configure --prefix=/tmp && make && make install-strip)
- (cd libite-2.3.1 && ./configure --prefix=/tmp && make && make install-strip)
# Custom build script for the time being, no "make test" yet
script:
- ./autogen.sh
- ./configure --prefix= --enable-static
- make clean
- make V=1 -j5
- ./configure --prefix= --enable-x11-common-plugin --with-watchdog --with-keventd
- cat config.log
- make clean
- make V=1 -j5
- make install-strip DESTDIR=/tmp/finit
- tree /tmp/finit
- ldd /tmp/finit/sbin/finit
- size /tmp/finit/sbin/finit
- size /tmp/finit/sbin/initctl
- size /tmp/finit/sbin/reboot
- LD_LIBRARY_PATH=/tmp/lib /tmp/finit/sbin/initctl -h
- unshare -V
- nsenter -V
- chroot --version
- 'LD_LIBRARY_PATH=/tmp/lib make distcheck || (cat finit-4.0-beta1/_build/sub/test/test-suite.log; exit 1)'
+8 -1
View File
@@ -1,5 +1,12 @@
Current Maintainer(s):
* Joachim Nilsson <troglobit@gmail.com>
* Joachim Wiberg <troglobit@gmail.com>
Major Contributors:
* Tobias Waldekranz <tobias@waldekranz.com>
* Mattias Walström <mattias.walstrom@westermo.se>
* Jonas Johansson <jonas.johansson@westermo.se>
* Jacques de Laval <jacques@de-laval.se>
* Magnus Malm <magnusmalm@gmail.com>
Original Author(s):
* Claudio Matsuoka <cmatsuoka@gmail.com>
+999
View File
@@ -0,0 +1,999 @@
Change Log
==========
All relevant changes are documented in this file.
[4.1][UNRELEASED]
-----------------
Bug fix release. Also disables handlers for `SIGINT` and `SIGPWR`, a
new set of `sys` conditions are instead generated which can be used to
trigger external programs.
### Changes
* Change behavior on SIGUSR1 to be compatible with sysvinit and systemd.
Previously SIGUSR1 caused Finit to halt, like BusyBox init. This had
"interesting" side effects on Debian systems when coexisting with
sysvinit (upgrading/reinstalling causes scripts to `kill -USR1 1`)
* Change how `contrib/debian/install.sh` sets up a Grub boot entry for
finit. We now modify the $SUPPORTED_INITS variable in `10_linux`
* Disable default kernel ctrl-alt-delete handler and let Finit instead
catch `SIGINT` from kernel to be able to perform a proper reboot.
There is no default command for this, you need to set up a task that
triggers on `<sys/key/ctrlaltdel>` to issue `initctl reboot`
* Added keventd to provide `<sys/pwr/ac>` condition to Finit. keventd
is currently only responsible for monitoring `/sys/class/power_supply`
for changes to active AC mains power online status. Enable keventd
with `configure --with-keventd`
* For handling power fail events (from UPS and similar) a process may
send `SIGPWR` to PID 1. Finit no longer redirects this to `SIGUSR1`
(poweroff). There is no default command for this, you need to set up
a task that triggers on `<sys/pwr/fail>` to issue `initctl poweroff`
* Built-in Finit getty is now a standalone program
* Default termios for TTYs now enable `IUTF8` on input
* If `/bin/login` is not found, Finit now tries `sulogin` before it
falls back to an unauthenticated `/bin/sh`
* Dropped (broken) support for multiple consoles. Finit now follows
the default console selected by the kernel, `/dev/console`
* Finit no longer parses `/proc/cmdline` for its options. Instead all
options are by default now read from `argv[]`, like a normal program,
this is also what the kernel does by default. Please note, this may
not work if your systems boots with an initramfs (ymmv), for such
cases, see `configure --enable-kernel-cmdline`
* The following plugins are now possible to disable (for containers):
`rtc.so`, `urandom.so`, you may also want to disable `hotplug.so`.
They are all enabled by default, as in Finit 4.0, but may be moved
to external tools or entries in `finit.conf` in Finit 5.0
### Fixes
* Stricter interface name validation in netlink plugin, modeled after
the kernel. Suggested by Coverity Scan
* Fix problem of re-registering a service as a task. Previously, if a
fundamental change, like type, was made to an active service/run/task
it did not take. Only possible workaround was to remove from config
* initctl: drop warning when removing a non-existing usr condition
* initctl: drop confusing `errno 0` when timing out waiting for reply
* Ensure services in plugins and from Finit main belong to a cgroup
* Ensure init top-level cgroup remains a leaf group
* Fix tty parse error for detecting use of external getty
* Fix default `name:` and `:ID` for tty's, e.g. `ttyS0` now gives
`tty:S0` as expected. This was default for built-in getty already
* Fix max username (32 chars) in bundled Finit getty
* The `contrib/*/install.sh` scripts failed to run from tarball
* Finit no longer forcibly mounts; `/dev`, `/proc`, or `/sys`, instead
it checks first if they are already mounted (devtmpfs or container)
* Fix `/etc/fstab` parser to properly check for 'ro' to not remount the
root filesystem at boot. The wrong field was read, so a root mounted
by an initramfs, or by lxc for a container, had their root remounted
* Fix #170: detect loss of default route when interfaces go down. This
emulates the missing kernel netlink message to remove the condition
net/default/route to allow stopping dependent services
* Fix #171: restore automatic mount of `/dev/shm`, `/dev/pts`, `/run`
and `/tmp`, unless mounted already by `/etc/fstab`. This is what most
desktop systems expect PID 1 to do. Here we also make sure to mount
`/run/lock` as a tmpfs as well, with write perms for regular users,
this prevents regular users from filling up `/run` and causing DoS.
* Fix #173: netlink plugin runs out of socket buffer space;
finit[1]: nl_callback():recv(): No buffer space available
Fixed by adding support for resync with kernel on `ENOBUFS`. See
netlink(7) for details. As a spin-off the plugin now supports any
number of interfaces and routes on a system. On resync, the following
message is now logged, as a warning:
finit[1]: nl_callback():busy system, resynchronizing with kernel.
* Fix #174: loss of log messages using combo of prio and facility, e.g.,
`logit(LOG_CONSOLE | LOG_NOTICE, ...)`, by Jacques de Laval, Westermo
* Fix #175: ensure Finit does not acquire a controlling TTY when checking
if a device is a TTY before starting a getty. This fixes an old bug
where Ctrl-C after logout from a shell could cause PID 1 to get SIGINT,
which in turn could lead to a system reboot
[4.0][] - 2021-04-26
--------------------
This release became v4.0, and not v3.2, because of incompatible changes
to service conditions. There are other significant changes as well, so
make sure to read the whole change log when upgrading.
### Changes
* The stand-alone `reboot` tool has been replaced with a symlink to
`initctl`, like its siblings: halt, shutdown, poweroff, and suspend.
Calling `reboot` & C:o now defaults to the corresponding `initctl cmd`
with a fallback to sending signals as per traditional SysV init. The
`-f` (force) flag remains, where `reboot(2)` is called directly
* Introducing Finit progress 𝓜𝓸𝓭𝓮𝓻𝓷
* The `inictl cond set|clear COND` have changed completely. Constrained
to a flat `<usr/...>` namespace and automatically activated by a new
`usr.so` plugin that checks services for usr condition changes
* Removed built-in inetd super server. If you need this functionality,
use an external inetd, like xinetd, instead. A pull request for a
stand-alone inetd, like watchdogd and getty, is most welcome!
* Incompatible `configure` script changes, i.e., no guessing `--prefix`
and other paths. Also, many options have been changed, renamed, or
flipped defaults, or even dropped altogether. There are examples in
the documentation and the `contrib/` section
* Service conditions change from the non-obvious `<svc/path/to/foo>` to
`<pid/foo:id>`. Not only does this give simpler internal semantics,
it hopefully also makes it clear that one service's `pid:!foo` pidfile
is another service's `<pid/foo>` condition, issue #143
* Initial support for cgroups v2:
- services runs in a cgroup named after their respective *.conf file
- top-level groups are; init, user, and system
- all top-level groups can be configured from finit *.conf files
- each service can tweak the cgroup settings
- Use `initctl [top|ps|cgroup]` commands to inspect runtime state
- https://twitter.com/b0rk/status/1214341831049252870?s=20
* Major refactor of Finit's `main()` function to be able to start the
event loop earlier. This also facilitated factoring out functionality
previously hard-coded in Finit, e.g., starting the bundled watchdogd,
various distro packed udevd and other hotplugging tools
* A proper rescue mode has been added. It is started extremely early
and is protected with a bundled `suslogin`. Exiting rescue mode now
brings up the system as a normal boot, as one expects
* Support for `sysv` start/stop scripts as well as monitoring forking
services, stared using `sysv` or `service` stanza
* Support for custom `kill:DELAY`, default 3 sec.
* Support for custom `halt:SIGNAL`, default SIGTERM
* Support for `pre:script` and `post:script`, allows for setup and
teardown/cleanup before and after a service runs, issue #129
* Support for `env:file` in `/etc/default/foo` or `/etc/conf.d/foo`, see
the contrib section for examples that utilize this feature. Variables
expanded from env files, and the env files themselves, are tracked for
changes to see if a service .conf file is "dirty" and needs restart on
`initctl reload`
* Support for tracking custom PID files, using `pid:!/path/to/foo.pid`,
useful with new `sysv` or `service` which fork to background
* Support starting run/task/services without absolute path, trust `$PATH`
* Add support for `--disable-doc` and `--disable-contrib` to speed up
builds and work around issue with massively parallel builds
* Support for `@console` also for external getty
* Support for `notty` option to built-in getty, for board bring-up
* Support for `rescue` option to built-in getty, for rescue shells
* Add `-b`, batch mode, for non-interactive use to `initctl`
* Prefer udev to handle `/dev/` if mdev is also available
* Redirect dbus daemon output to syslog
* Set `$SHELL`, like `$PATH`, to a sane default value, needed by BusyBox
* Finit no longer automatically reloads its `*.conf` files after running
`/etc/rc.local` or run-parts. Use `initctl reload` instead.
* `initctl` without an argument or option now defaults to list services
* Convert built-in watchdog daemon to standalone mini watchdogd, issue #102
* Improved watchdog hand-over, now based on `svc_t` and not PID
* Extended bootstrap, runlevel S, timeout: 10 --> 120 sec. before services
not allowed in the runtime runlevel are unconditionally stopped
* Removed `HOOK_SVC_START` and `HOOK_SVC_LOST`, caused more problems
than they were worth. Users are encouraged to use accounting instead
* Skip displaying "Restarting ..." progress for bootstrap processes
* Added a simple work queue mechanism to queue up work at boot + runtime
- Postpone deletion of `svc_t` until any `SIGKILL` timer has elapsed
- As long as a stepped service changes state we queue another step all
event, because services may depend on each other
* Require new libuEv API: `uev_init1()` to reduce event cache so that
the kernel can invalidate deleted events before enqueing to userspace
* Rename `hwclock.so` plugin to `rtc.so` since it now is stand-alone
from the `hwclock` tool. Note: the kernel can also be set to load
and store RTC to/from system clock at boot/halt as well, issue #110
* New plugin to support cold plugging devices, auto-loading of modules
at boot. Detects required modules by reading `/sys/devices/*`
* New plugin for `/etc/modules-load.d/` by Robert Andersson, Atlas Copco
* New `name:foo` support for services, by Robert Andersson, Atlas Copco
* New `manual:yes` support for services, by Robert Andersson, Atlas Copco
* New `log:console` support for services, by Robert Andersson, Atlas Copco
* Support for `:ID` as a string, by Jonas Johansson, Westermo
* Support for auto-reload, instead of having to do `initctl reload`,
when a service configuration has changed. Disabled by default, but
can be enabled with `./configure --enable-auto-reload`
* Support for logging security related events, e.g., runlevel change,
star/stop or failure to start services, by Jonas Holmberg, Westermo
* Mount devtpts with recommended `ptxmode=0666`
* Mount /run tmpfs with nosuid,nodev,noexec for added security
* Support for `console` as alias for `@console` in tty stanzas
* Drop `--enable-rw-roots` configure option, use `rw` for your `/`
partition in `/etc/fstab` instead to trigger remount at boot
* Drop default tty speed (38400) and use 0 (kernel default) instead
* Make `:ID` optional, use NULL/zero internally this allows ...
* Handle use-cases where multiple services share the same PID filem
and thus the same condition path, e.g. different instances for
different runlevels. Allow custom condition path with `name:foo`
syntax, creates conditions w/o a path, and ...
* Always append `:ID` qualifier to conditions if set for a service
* The IPC socket has moved from `/run/finit.sock` to `/run/finit/socket`
officially only supported for use by the `initctl` tool
* The IPC socket now uses `SOCK_SEQPACKET` instead of `SOCK_STREAM`.
Recommend using watchdogd v3.4, or later, which support this
* Improved support for modern `/etc/network/interfaces`, which has
include statements. No more native `ifup` of individual interfaces,
Finit now calls `ifup -a`, or `ifdown -a`, delegating all details to
the operating system. Also, this is now done in the background, by
popular request
### Fixes
* Fix #96: Start udevd as a proper service
* Ensure we track run commands as well as task/service, once per runlevel
* Ensure run/tasks also go to stopping state on exit, like services,
otherwise it is unnecessarily hard to restart them
* Fix missing OS/Finit title bug, adds leading newline before banner
* Remove "Failed connecting to watchdog ..." error message on systems
that do not have a watchdog
* Fix #100: Early condition handling may not work if `/var/run` does
not yet exist (symlink to `/run`). Added compat layer for access
* Fix #101: Built-in inetd removed
* Fix #102: Start built-in watchdogd as a regular service
* Fix #103: Register multiple getty if `@console` resolves to >1 TTY,
* Fix #105: Only remove /etc/nologin when moving from runlevel 0, 1, 6
Fixed by Jonas Johansson, Westermo
* Fix #109: Support for PID files in sub-directories to `/var/run`
* Handle rename of PID files, by Robert Andersson, Atlas Copco
* Fix #110: automatic modprobe of RTC devices, built-in hwclock
* Fix #120: Redirect `stdin` to `/dev/null` for services by default
* Fix #122: Switch to `nanosleep()` to achieve "signal safe" sleep,
fixed by Jacques de Laval, Westermo
* Fix #124: Lingering processes in process group when session leader
exits. E.g., lingering `logit` processes when parent dies
* Fix #127: Show all runparts scripts as they start, like rc.local, fixed
by Jacques de Laval, Westermo
* Fix service name matching, e.g. for condition handling, may match with
wrong service, by Jonas Holmberg, Westermo
* Run all run-parts scripts using `/bin/sh -c foo` just like the standard
run-parts tool. Found by Magnus Malm, Westermo
* Fix `initctl [start | restart]`, should behave the same for services
that have crashed. Found by Mattias Walström, Westermo
* Wait for bootstrap phase to complete before cleaning out any bootstrap
processes that have stopped, they may be restarted again
* Reassert condition when an unmodified run/task/service goes from
WAITING back to RUNNING again after a reconfiguration event.
Found and fixed by Jonas Johansson, Westermo
* Restore Ctrl-D and Ctrl-U support in built-in getty
* Remove service condition when service is deleted
* Fix C++ compilation issues, by Robert Andersson, Atlas Copco
* Build fixes for uClibc
* Provide service description for built-in watchdog daemon
* Fix #138: Handle `SIGPWR` like `SIGSUR2`, i.e., power off the system
* Drop the '%m' GNUism, for compat with older musl libc
* Fix #139: call `tzset()` on `initctl reload` to activate system
timezone changes (for logging)
[3.1][] - 2018-01-23
--------------------
Improvements to `netlink.so` plugin, per-service `rlimit` support,
improved integration with `watchdogd`, auto-detect TTY console. Much
improved debug, rescue and logging support. Also, many fixes to both
big and small issues, most notably in the condition handling, which no
longer is sensitive to time skips.
This version requires at least libuEv v2.1.0 and libite v2.0.1
### Changes
* Support for more kernel command line settings:
- splash, enable boot progress
- debug, like `--debug` but also enable kernel debug
- single, single user mode (no network)
- rescue, new rescue mode
* Support for `IFF_RUNNING` to netlink plugin => `net/IFNAME/running`
* Support for restarting `initctl` API socket on `SIGHUP`
* Greatly updated `initctl status <JOB|NAME>` command
* Support for `rlimit` per service/run/task/inetd/tty, issue #45
* Support for setting `hard` and `soft` rlimit for a resource at once
* Support for auto-detecting serial console using Linux SysFS, the new
`tty @console` eliminates the need to keep track of different console
devices across embedded platforms: `/dev/ttyS0`, `/dev/ttyAMA0`, etc.
* Add TTY `nologin` option. Bypasses login and skips immediately to a
root shell. Useful during board bringup, in developer builds, etc.
* Support for calling run/tasks on Finit internal HOOK points, issue #18
* Removed support for long-since deprecated `console DEV` setting
* Cosmetic change to login, pressing enter at the `Press enter to ...`
prompt will now replace that line with the login issue text
* Calling `initctl` without any arguments or options now defaults to
show status of all enabled services, and run/task/inetd jobs
* Cosmetic change to boot messages, removed `Loading plugins ...`, start
of inetd services, and `Loading configuration ...`. No end user knows
what those plugins and configurations are, i.e. internal state+config
* Change kernel WDT timeout (3 --> 30 sec) for built-in watchdog daemon
* Advise watchdog dawmon on shutdown and reboot using `SIGPWR` and then
`SIGTERM`. It is recommended the daemon start a timer on the first
signal, in case the shutdown process somehow hangs.
* Handle `/etc/` OverlayFS, reload /etc/finit.d/*.conf after `mount -a`
* initctl: Add support for printing previous runlevel
* initctl: Support short forms of all commands
* initctl: Support for `initctl touch <CONF>` to be used with `reload`
* initctl: Improved output of `initctl show <SVC>`
* Support reloading `/etc/finit.conf`. The main finit.conf file
previously did not support reloading at runtime, as of v3.1 all
configuration directives supported in `/etc/finit.d/*.conf` are now
supported in `/etc/finit.conf`
* Change `.conf` dependency + reload handling. Finit no longer relies
on mtime of `.conf` files, instead an inotify handler tracks file
changes for time *insensitive* dependency tracking
* Change condition handling to not rely on mtime but a generation id.
* New configure script option `--enable-redirect` to automatically
redirect `stdout` and `stderr` of all applications to `/dev/null`
* New `pid` sub-option to services when a service does not create a PID
file, or when the PID file has another name. Issue #95
* Greatly improved `log` sub-option to service/run/tasks, selectively
redirect `stdout` and `stderr` using the new tool `logit` to either
syslog or a logfile. Issue #44
* Support for automatic log rotation of logfiles created by `log`
option. Use `configure --disable-logrotate` on systems with a
dedicated log rotation service. Issue #44
* Support for disabling service/run/task progress with empty ` --`
description. Note: no description separator gives a default desc.
* Create `/etc/mtab` symlink if missing on system (bootmisc plugin)
* New hook: `hook/mount/post` runs after `mount -a` but before the
`hook/mount/all`, where `bootmisc.so` runs. This provides the
possibility of running a second stage mount command before files in
`/run` and similar are created
* Skip `gdbserver` when unleashing the grim reaper at shutdown
* Distribute and install `doc/` and `contrib/` directories
### Fixes
* Reset TTY before restarting it. A program may manipulate the TTY in
various ways before the user logs out, Finit needs to reset the TTY to
a sane state before restarting it. Issue #84
* On .conf parse errors, do *not* default to set TTY speed 38400, reuse
current TTY speed instead
* Fix run/tasks, must be guaranteed to run once per declared runlevel.
All run/tasks on `[S]` with a condition `<...>` failed to run. Finit
now tracks run/tasks more carefully, waiting for them to finish before
switching to the configured runlevel at boot. Issue #86
* Allow inetd services to be registered with a unique ID, e.g. `:161`,
issue #87. Found by Westermo
* inetd: drop UDP packets from blocked interfaces, issue #88
* Handle obscure inter-plugin dependency issue by calling the netlink
plugin before the pidfile plugin on `HOOK_SVC_RECONF` events
* Handle event loop failure modes, issue found by Westermo
* Handle API socket errors more gracefully, restart socket
* Do not attempt to load kernel modules more than once at bootstrap
* Remove reboot symlinks properly on uninstall
* Fix regression in condition handling, reconf condition must be kept
as a reference point to previous reconfiguration, or bootstrap.
* Fix nasty race condition with internal service stop, abort kill if the
service has already terminated, otherwise we may do `kill(0, SIGKILL)`
* Fix reconfiguration issue with (very quick) systems that don't have
highres timers
* Fix formatting of runlevel string in `initctl show`
* Allow running `initctl` with `STDOUT` redirected
* Fix regression in `initctl start/stop <ID>`, using name worked not id
* Fix error handling in `initctl start/stop` without any argument
* Fix issue #81 properly, remove use of SYSV shm IPC completely. Finit
now use the API socket for all communication between PID 1 and initctl
* Fix segfault on x86_64 when started with kernel cmdline `--debug`
* Normalize condition paths on systems with `/run` instead of `/var/run`
[3.0][] - 2017-10-19
--------------------
Major release, support for conditions/dependencies between services,
optional built-in watchdog daemon, optional built-in getty, optional
built-in standard inetd services like echo server, rdate, etc.
Also, native support for Debian/BusyBox `/etc/network/interfaces`,
overhauled new configure based build system, logging to `/dev/kmsg`
before syslogd has started, massively improved support for Linux
distributions.
### Changes
* Added basic code of conduct covenant to project
* Added contribution guidelines document
* Removed `finit.conf` option `check DEV`, replaced entirely by automated
call to `fsck` for each device listed in `/etc/fstab`
* Removed deprecated and confusing `startx` and `user` settings. It is
strongly recommended to instead use xdm/gdb/lightdm etc.
* Add support for `initctl log <SVC>`, shows last 10 lines from syslog
* Add `initctl cond dump` for debugging conditions
* Ensure plugins always have a default name, file name
* Reorganization, move all source files to a `src/` sub-directory
* Add support for `initctl <list|enable|disable> <SVC>`, much needed by
distributions. See [doc/distro.md](doc/distro.md) for details
* Remove `UNUSED()` macro, mentioned here because it may have been used
by external plugin developers. Set `-Wno-unused-parameter` instead
* New table headings in `initctl`, using `top` style inverted text
* Allow `initctl show` to use full screen width for service descriptions
* New `HOOK_BANNER` for plugins to override the default `banner()`
* Allow loading TTYs from `/etc/finit.d`
* Improvements to built-in getty, ignore signals like `SIGINT`,
`SIGHUP`, support Ctrl-U to erase to beginning of line
* Add TTY `nowait` and `noclear` options
* Allow using both built-in getty and external getty:
tty [12345] /dev/ttyAMA0 115200 noclear vt220
tty [12345] /sbin/getty -L 115200 /dev/ttyAMA0 vt100
tty [12345] /sbin/agetty -L ttyAMA0 115200 vt100 nowait
* Silent boot is now the default, use `--enable-progress` to get the old
Finit style process progress. I.e., `--enable-silent` is no more
* Support for `configure --enable-emergency-shell`, debug-only mode
* Support for a fallback shell on console if none of the configured TTYs
can be started, `configure --enable-fallback-shell`
* All debug messages to console when Finit `--debug` is enabled
* Prevent login, by touching `/etc/nologin`, during runlevel changes
* A more orderly shutdown. On reboot/halt/poweroff Finit now properly
goes to runlevel 0/6 to first stop all processes.
* Perform sync before remounting as read-only, at shutdown
* Clean up `/tmp`, `/var/run`, and `/var/lock` at boot on systems which
have these directories on persistent storage
* Call udev triggers at boot, on systems with udev
* Add missing `/var/lock/subsys` directory for dbus
* Add support for `poweroff`
* Add support for a built-in miniature watchdog daemon
* Remove GLIBC:isms like `__progname`
* Manage service states based on user defined conditions
* Manage dependencies between services, w/ conditions (pidfile plugin)
* Manage service dependencies on network events (netlink plugin)
* Support for dynamically reloading Finit configuration at runtime
* Refactor to use GNU configure and build system
* New hooks for for detecting lost and started services (lost plugin)
* External libraries, libuEv and libite, now build requirements
* Early logging support to `/dev/kmsg` instead of console
* Support for redirecting stdout/stderr of services to syslog
* Support for managing resource limits for Finit and its processes
* Add optional built-in inetd services: echo server, chargen, etc.
* Add simple built-in getty
* Greatly improved accounting support, both UTMP and WTMP fixes+features
* Improved udev support, on non-embedded systems
* Improved shutdown and file-system unmount support (Debian)
* Support SysV init `/etc/rc.local`
* Inetd protection against UDP looping attacks
* Support systems with `/run` instead of `/var/run` (bootmisc plugin)
* Adopted BusyBox init signals for halt/reboot/poweroff
* SysV init compat support for reboot (setenv)
* Compat support for musl libc
* Add OpenRC-like support for sysctl.d/*.conf
* Add support for Debian/BusyBox `/etc/network/interfaces`
* Add support for running fsck on file systems in `/etc/fstab`
* Added example configs + HowTos for Debian and Alpine Linux
to support latest releases of both distributions
* Lots of documentation updates
### Fixes
* Fix race-condition at configuration reload due to too low resolution.
Thanks to Mattias Walström, Westermo
* Fix to handle long process (PID) dependency chains, re-run reconf
callback until no more applications are in flux.
Thanks to Mattias Walström, Westermo
* Clear `reconf` condition when `initctl reload` has finished
* Skip automatic reload of `/etc/finit.d/*.conf` files when changing
runlevel to halt or reboot
* Fix issue #54: Allow halt and poweroff commands even if watchdog is enabled
* Fix issue #56: Check existence of device before trying to start getty
* Fix issue #60: `initctl` should display error and return error code
for non-existing services should the operator try to start/stop them.
* Fix issue #61: Reassert `net/*` conditions after `initctl reload`
* Fix issue #64: Skip `fsck` on already mounted devices
* Fix issue #66: Log rotate and gzip `/var/log/wtmp`, created by Finit
* Fix issue #72: Check `ifup` exists before trying to bring up networking,
also set `$PATH` earlier to simplify `run()` et al -- no longer any need
to use absolute paths for system tools called from Finit. Thanks to crazy
* Fix issue #73: Remove double `ntohl()` in inetd handling, prevents matches.
Thanks to Petrus Hellgren, Westermo
* Fix issue #76: Reap zombie processes in emergency shell mode
* Fix issue #80: FTBFS on Arch Linux, missing `stdarg.h` in `helpers.h`,
thanks to Jörg Krause
* Fix issue #81: Workaround for systems w/o SYSV shm IPC support in kernel
* Always collect bootstrap-only tasks when done, we will never re-run them.
Also, make sure to never reload bootstrap-only tasks at runtime
* Remove two second block (!) of Finit when stopping TTYs
[2.4][] - 2015-12-04
--------------------
Bug fix release.
### Changes
* Add support for status/show service by `name:id`
* Enforce terse mode after boot, if verbose mode is disabled
* Reenable verbose mode at reboot, if disabled at boot
* Update section mentioning BusyBox getty
* Update debugging documentation
* Allow debug to override terse mode
* Revert confusing change in service state introduced in [v2.3][2.3].
As of [v2.4][2.4] services are listed as "halted" and "stopped", when
they have been halted due to a runlevel changed or stopped by the
user, respectively.
### Fixes
* Fix system freeze at reconfiguration. Changed services that
all support `SIGHUP` caused a freeze due to Finit waiting for
them to stop.
* Make sure to start and/or `SIGHUP` services after reconfiguration
when there was no services to stop.
[2.3][] - 2015-11-28
--------------------
Bug fix release.
### Changes
* Add support for stop/start/restart/reload service by `name:id`
* Refactor service status listed in `initctl show`, show actual status
### Fixes
* Remove bootstrap-only tasks/services when leaving runlevel 'S'
* Fix reference counting issue with already stopped and removed services
when the user performs `initctl reload` to change system configuration
* Revert semantic change in behavior of `initctl restart`: users expect
service to be stopped/started, not reloaded with `SIGHUP` even if the
service supports it
* Fix `NULL` pointer dereference causing kernel panic when user calls
`initctl reload` after change of system configuration
* Fix column alignment in output of `initctl show` for services not in
current runlevel
[2.2][] - 2015-11-23
--------------------
Lots of fixes to handle static builds, but also fixes for dynamic event
handling and reconfiguration at runtime.
### Changes
* Upgrade to libuEv v1.2.4, to handle static builds
* Upgrade to libite (LITE) v1.2.0, to handle static builds
* Clarify how to select different plugins with the configure script
* Improve urandom plugin for embedded systems w/o random seed
* Add `--debug` flag to `initctl`
* The runlevels listed for services in `initctl show` now hightlight the
active runlevel.
* Clarify in the README and in `initctl help` that the GW event to
listen for in service declarations is `GW:UP`
### Fixes
* Build fixes for `configure --disable-inetd`
* Fixed issue #14: Improved support for static Finit builds
* Misc. fixes to silence warnings when building a static Finit
* Default to register services as `SIGHUP`'able, regression in v2.0
* Call `HOOK_SVC_RECONF` only when all processes have been stopped
* On reload/reconf we must wait for all services to stop first
* Only trigger on events that matches the service's specification,
fix by Tobias Waldekranz
[2.1][] - 2015-10-16
--------------------
### Changes
* Add hook point for fstab mount failure
* Set hostname on dynamic reload
* Upgrade to libite v1.1.1
### Fixes
* Fix service callback coredump checks and simplify callback exit
* Do not use `-Os` use `-O2` as default optimization level. Many cross
compiler toolchains are known to have problems with `-Os`
* Do not allow build VERSION to be overloaded by an environment variable
* Fix too small MAX arguments and too few argments in `svc_t` for
reading currently running services with `initctl show`
* Unblock blocked signals after forking off a child
[2.0][] - 2015-09-20
--------------------
Support for multiple instances and event based services, as well as the
introduction of an `initctl` tool.
**Note:** Incompatible change to syntax for custom `inetd` services,
c.f. Finit v[1.12][].
### Changes
* The most notable change is the support for multiple instances. A must
have when running multiple DHCP clients, OpenVPN tunnels, or anything
that means using the same command only with different arguments. Now
simply add a `:ID` after the `service` keyword, where `ID` is a unique
instance number for that service.
service :1 [2345] /sbin/httpd -f -h /http -p 80 -- Web server
service :2 [2345] /sbin/httpd -f -h /http -p 8080 -- Old web server
* Another noteworthy new feature is support for starting/stopping
services on Netlink events:
service :1 [2345] <!IFUP:eth0,GW> /sbin/dropbear -R -F -p 22 -- SSH daemon
Here the first instance `:1` of the SSH daemon is declared to run in
runlevels 2-5, but only if eth0 `IFUP:eth0` is up and a gateway `GW`
is set. When the configuration changes, a new gateway is set, or if
somehow a new `IFUP` event for eth0 is received, then dropbear is not
SIGHUP'ed, but instead stop-started `<!>`. The latter trick applies
to all services, even those that do not define any events.
* Support for reloading `*.conf` files in `/etc/finit.d/` on SIGHUP.
All `task`, `service` and `run` statements can be used in these .conf
files. Use the `telinit q` command, `initctl reload` or simply send
`SIGHUP` to PID 1 to reload them. Finit automatically does reload of
these `*.conf` files when changing runlevel.
* Support for a modern `initctl` tool which can stop/start/reload and
list status of all system services. Also, the old client tool used
to change runlevel is now also available as a symlink: `telinit`.
initctl [-v] <status|stop|start|reload|restart> [JOB]
* Add concept of "jobs". This is a unique identifier, composed of a
service and instance number, `SVC:ID`
initctl <stop|start|reload|restart> JOB
* Support for *deny filters* in `inetd` services.
inetd service/proto[@iface,!iface,...] </path/to/cmd | internal[.service]>
Internal services on a custom port must use the `internal.service`
syntax so Finit can properly bind the inetd service to the correct
plugin. Here follows a few examples:
inetd time/udp wait [2345] internal -- UNIX rdate service
inetd time/tcp nowait [2345] internal -- UNIX rdate service
inetd 3737/tcp nowait [2345] internal.time -- UNIX rdate service
inetd telnet/tcp@*,!eth1,!eth0, nowait [2345] /sbin/telnetd -i -F -- Telnet service
inetd 2323/tcp@eth1,eth2,eth0 nowait [2345] /sbin/telnetd -i -F -- Telnet service
inetd 222/tcp@eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
inetd ssh/tcp@*,!eth0 nowait [2345] /sbin/dropbear -i -R -F -- SSH service
Access to telnet on port `2323` is only possible from interfaces
`eth0`, `eth1` and `eth2`. The standard telnet port (`23`) is
available from all other interfaces, but also `eth2`. The `*`
notation used in the ssh stanza means *any* interface, however, here
`eth0` is not allowed.
**NOTE:** This change breaks syntax compatibility with Finit v[1.12].
* Support for a more user-friendly configure script rather than editing
the top Makefile, or setting environment variables at build time.
* Support for building Finit statically, no external libraries. This
unfortunately means that some plugins cannot be built, at all.
Big thanks goes to James Mills for all help testing this out!
* Support for disabling the built-in inetd server with `configure`.
* Support for two new hook points: `HOOK_SVC_RECONF` and
`HOOK_RUNLEVEL_CHANGE`. See the source for the exact location.
* The `include <FILE>` option now needs an absolute path to `FILE`.
### Fixes
* Rename `patches/` to `contrib/` to simplify integration in 3rd party
build systems.
* Fix for unwanted zombies ... when receiving SIGCHLD we must reap *all*
children. We only receive one signal, but multiple processes may have
exited and need to be collected.
[1.12][] - 2015-03-04
---------------------
The inetd release.
### Changes
* Add support for built-in inetd super server -- launch services on
demand. Supports filtering per interface and custom Inet ports.
* Upgrade to [libuEv] v1.1.0 to better handle error conditions.
* Allow mixed case config directives in `finit.conf`
* Add support for RFC 868 (rdate) time plugin, start as inetd service.
* Load plugins before parsing `finit.conf`, this makes it possible to
extend finit even with configuration commands. E.g., the `time.so`
plugin must be loaded for the `inetd time/tcp internal` service to be
accepted when parsing `finit.conf`.
* Slight change in TTY fallback behavior, if no TTY is listed in the
system `finit.conf` first inspect the `console` setting and only if
that too is unset fall back to `/bin/sh`
* When falling back to the `console` TTY or `/bin/sh`, finit now marks
this fallback as console. Should improve usability in some use cases.
### Fixes
* Revert "Use vfork() instead of fork() before exec()" from v1.11. It
turned out to not work so well after all. For instance, launching
TTYs in a background process completely blocked inetd services from
even starting up listening sockets ... proper fork seems to work fine
though. This is the casue for *yanking* the [1.11] release, below.
* Trap segfaults caused by external plugins/callbacks in a sub-process.
This prevents a single programming mistake in by a 3rd party developer
from taking down the entire system.
* Fix Coverity CID 56281: dlopen() resource leak by storing the pointer.
For the time being we do not support unloading plugins.
* Set hostname early, so bootstrap processes like syslog can use it.
* Only restart *lost daemons* when recovering from a SIGSTOP/norespawn.
[1.11][] - 2015-01-24 [YANKED]
------------------------------
The [libuEv] release.
**Note:** This release has been *yanked* from distribution due to a
regression in launching background processes and TTY's. Fixed in
Finit v[1.12].
### Changes
* Now using the asynchronous libuEv library for handling all events:
signals, timers and listening to sockets or file descriptors.
* Rename NEWS.md --> CHANGELOG.md, with symlinks for `make install`
* Attempt to align with http://keepachangelog.com/ for this file.
* Travis CI now only invokes Coverity Scan from the 'dev' branch. This
means that all development, except documentation updates, must go into
that branch.
### Fixes
* Fix bug with finit dying when no `tty` is defined in `finit.conf`, now
even the fallback shell has control over its TTY, see fix in GIT
commit [dea3ae8] for this.
[1.10][] - 2014-11-27
---------------------
Major bug fix release.
### Changes
* Project now relies on static code analysis from Coverity, so this
release contains many serious bug fixes.
* Convert to use Markdown for README, NEWS and TODO.
* Serious update to README and slight pruning of finished TODO items.
### Fixes
* Fix serious file descriptor and memory leaks in the following
functions. In particular the leaks in `run_interactive()` are very
serious since that function is called every time a service is started
and/or restarted! For details, see the GIT log:
* `helpers.c:run()`
* `helpers.c:run_interactive()`
* `helpers.c:set_hostname()`
* `helpers.c:procname_kill()`
* `svc.c:svc_start()`: Fix swapped arguments to dup2() and add close(fd)
to prevent descriptor leak.
* `svc.c:svc_start()`: Fix out of bounds write to local stack variable,
wrote off-by-one outside array.
* Several added checks for return values to `mknod()`, `mkdir()`,
`remove()`, etc.
[1.9][] - 2014-04-21
--------------------
### Changes
* Add support for an include directive to `.conf` files
* Fallback to `/bin/sh` if user forgets tty setting
* Initial support for restarting lost services during `norespwan`
### Fixes
* Bug fixes, code cleanup
* Handle `SIGHUP` from service callback properly when switching runlevel
* Misc. major (memleak) and minor fixes and additions to `libite/lite.h`
[1.8][] - 2013-06-07
--------------------
### Changes
* Support for runlevels, with a bootstrap runlevel 'S'
* Support for saving previous and current runlevel to UTMP
* Support for new `finit.conf` commands: run, task, and runlevel
* Support for tty and console commands in `finit.conf`, like services
but for launching multiple getty logins
* New tty plugin to monitor TTYs coming and going, like USB TTYs
### Fixes
* Bugfixes to libite
[1.7][] - 2012-10-08
--------------------
### Changes
* Show `__FILE__` in `_d()` debug messages, useful for plugins with
similarily named callbacks. Also, only in debug mode anyway
* Make sure to cleanup recorded PID when a service is lost. Required by
service plugins for their callbacks to work.
* Only clear screen when in verbose mode. Maybe this should be removed
altogether?
### Fixes
* Bugfix: Do not `free()` static string in `finit.conf` parser
[1.6][] - 2012-10-06
--------------------
### Changes
* Skip `.` and `..` in plugin loader and display error when failing to
load plugins
* Support for overriding `/etc/finit.d` with `runparts DIR` in
`finit.conf`
* Revoke support for starting services not starting with a slash.
* Prevent endless restart of non-existing services in `finit.conf`
* Support for sysvinit style startstop scripts in `/etc/finit.d`
### Fixes
* Minor fix to alsa-utils plugin to silence on non-existing cards
[1.5][] - 2012-10-03
--------------------
### Changes
* Use bootmisc plugin to setup standard FHS 2.3 structure in `/var`
* Added `FLOG_WARN()` syslog macro, for plugins
* Add plugin dependency resolver. Checks `plugin_t` for `.depends`
[1.4][] - 2012-10-02
--------------------
### Changes
* Start refactoring helpers.c into a libite.so (-lite). This means
other user space applications/daemons can make use of the neat toolbox
available in finit
* Use short-form -s/-w -u to work with BusyBox hwclock as well
* Use RTLD_GLOBAL flag to tell dynamic loader to load dependent .so
files as well. Lets other plugins use global symbols.
* Greatly simplify svc hook for external plugins and cleanup plugin API.
* And more ... see the GIT log for more details.
### Fixes
* Fix I/O plugin watcher and load plugins earlier for a new hook
[1.3][] - 2012-09-28
--------------------
### Changes
* Cleanup public plugin API a bit and add new pid/pidfile funcs
* Add plugin hook to end of service startup
* Remove finit.h from svc.h, plugins should not need this.
* Move utility macros etc. to helpers.h
* Make `finit.h` daemon internal, only
* Move defines of FIFO, conf and rcS.d to Makefile => correct paths
* Add support for installing required headers in system include dir
* Better support for distributions and packagers with install-exec,
install-data, and install-dev targets in Makefile. Useful if you want
to call targets with different `$DESTDIR`!
* Makefile fixes for installation, paths encoded wrong
* Strip binaries + .so files, support for `$(CROSS)` toolchain strip
* Default install is now to `/sbin/finit` and `/usr/`
* Note change in `$PLUGIN_DIR` environment variable to `$plugindir`
[1.2][] - 2012-09-27
--------------------
### Changes
* Update README with section on building and environment variables
### Fixes
* Fix installation paths encoded in finit binary
[1.1][] - 2012-09-27
--------------------
### Changes
* Rename signal.[ch]-->sig.[ch] to avoid name clash w/ system headers
### Fixes
* Build fixes for ARM eabi/uClibc
[1.0][] - 2012-09-26
--------------------
### Changes
* New plugin based system for all odd extensions
* New service monitor that restarts services if they die
* New maintainer at GitHub http://github.com/troglobit/finit
* Add standard LICENSE and AUTHORS files
* New focus: embedded systems and small headless servers
[0.6][] - 2010-06-14
--------------------
* Don't start consolekit manually, dbus starts it (rtp)
* Unmount all filesystems before rebooting
* Disable `USE_VAR_RUN_RESOLVCONF` for Mandriva
* Unset terminal type in Mandriva before running X
* Remove extra sleep in finit-alt before calling services.sh (caio)
[0.5][] - 2008-08-21
--------------------
* Add option to start dbus and consolekit before the X server
* finit-alt listens to `/dev/initctl` to work with `reboot(8)` (smurfy)
* Write runlevel to utmp, needed by Printerdrake (Pascal Terjan)
* Fix ownership of `/var/run/utmp` (reported by Pascal Terjan)
* Remove obsolete code to load AGP drivers
* Conditional build of `/etc/resolveconf/run` support
* Add support to `/var/run/resolvconf` in Mandriva (blino)
[0.4][] - 2008-05-16
--------------------
* Default username for finit-alt configurable in Makefile
* Create loopback device node in finit-alt (for squashfs)
* Add option to use built-in run-parts instead of `/bin/run-parts`
* Ignore signal instead of setting to an empty handler (Metalshark)
* Handle pam_console permissions in finit-alt for Mandriva
* Add services.sh example and nash-hotplug patch for Mandriva
* Mount `/proc/bus/usb` in Mandriva
* Add runtime debug to finit-alt if finit_debug parameter is specified
* Read configuration from `/etc/finit.conf`
* Run getty with openvt on the virtual terminal
[0.3][] - 2008-02-23
--------------------
* Change poweroff method to `reboot(RB_POWER_OFF)` (Metalshark)
* Remove duplicate `unionctl()` reimplementation error
* Fix string termination in path creation
* Mount `/var/lock` and `/var/run` as tmpfs
[0.2][] - 2008-02-19
--------------------
* Replace `system("touch")` with `touch()` in finit-mod (Metalshark)
* Disable `NO_HCTOSYS` by default to match stock Eeepc kernel
* Drop `system("rm -f")` to clean `/tmp`, its a fresh mounted tmpfs
* Write ACPI sleep state to `/sys/power/state` instead of
`/proc/acpi/sleep` (Metalshark)
* Use direct calls to set loopback instead of `system("ifconfig")`
* Replace `system("cat")` and `system("dd")` with C implementation
* Moved finit-mod and finit-alt helpers to `helpers.c`
* Replace `system("echo;cat")` to draw shutdown splash with C calls
0.1 - 2008-02-14
----------------
* Initial release
[UNRELEASED]: https://github.com/troglobit/finit/compare/4.0...HEAD
[4.1]: https://github.com/troglobit/finit/compare/4.0...4.1
[4.0]: https://github.com/troglobit/finit/compare/3.1...4.0
[3.1]: https://github.com/troglobit/finit/compare/3.0...3.1
[3.0]: https://github.com/troglobit/finit/compare/2.4...3.0
[2.4]: https://github.com/troglobit/finit/compare/2.3...2.4
[2.3]: https://github.com/troglobit/finit/compare/2.2...2.3
[2.2]: https://github.com/troglobit/finit/compare/2.1...2.2
[2.1]: https://github.com/troglobit/finit/compare/2.0...2.1
[2.0]: https://github.com/troglobit/finit/compare/1.12...2.0
[1.12]: https://github.com/troglobit/finit/compare/1.11...1.12
[1.11]: https://github.com/troglobit/finit/compare/1.10...1.11
[1.10]: https://github.com/troglobit/finit/compare/1.9...1.10
[1.9]: https://github.com/troglobit/finit/compare/1.8...1.9
[1.8]: https://github.com/troglobit/finit/compare/1.7...1.8
[1.7]: https://github.com/troglobit/finit/compare/1.6...1.7
[1.6]: https://github.com/troglobit/finit/compare/1.5...1.6
[1.5]: https://github.com/troglobit/finit/compare/1.4...1.5
[1.4]: https://github.com/troglobit/finit/compare/1.3...1.4
[1.3]: https://github.com/troglobit/finit/compare/1.2...1.3
[1.2]: https://github.com/troglobit/finit/compare/1.1...1.2
[1.1]: https://github.com/troglobit/finit/compare/1.0...1.1
[1.0]: https://github.com/troglobit/finit/compare/0.9...1.0
[0.9]: https://github.com/troglobit/finit/compare/0.8...0.9
[0.8]: https://github.com/troglobit/finit/compare/0.7...0.8
[0.7]: https://github.com/troglobit/finit/compare/0.6...0.7
[0.6]: https://github.com/troglobit/finit/compare/0.5...0.6
[0.5]: https://github.com/troglobit/finit/compare/0.4...0.5
[0.4]: https://github.com/troglobit/finit/compare/0.3...0.4
[0.3]: https://github.com/troglobit/finit/compare/0.2...0.3
[0.2]: https://github.com/troglobit/finit/compare/0.1...0.2
[libuEv]: https://github.com/troglobit/libuev
[dea3ae8]: https://github.com/troglobit/finit/commit/dea3ae8
+1 -1
View File
@@ -1,5 +1,5 @@
Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
Copyright (c) 2008-2021 Joachim Wiberg <troglobit@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
-165
View File
@@ -1,165 +0,0 @@
# Finit - Extremely fast /sbin/init replacement w/ I/O, hook & service plugins
#
# Copyright (c) 2008-2010 Claudio Matsuoka <cmatsuoka@gmail.com>
# Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
.PHONY: all install clean distclean dist \
install-exec install-data install-dev \
uninstall-exec uninstall-data uninstall-dev
#VERSION ?= $(shell git tag -l | tail -1)
VERSION ?= 1.10
NAME = finit
PKG = $(NAME)-$(VERSION)
DEV = $(NAME)-dev
ARCHIVE = $(PKG).tar.xz
EXEC = finit reboot
HEADERS = plugin.h svc.h helpers.h queue.h
DISTFILES = LICENSE README NEWS finit.conf services
OBJS = finit.o conf.o helpers.o sig.o svc.o plugin.o tty.o
SRCS = $(OBJS:.o=.c)
DEPS = $(addprefix .,$(SRCS:.c=.d))
# Installation paths, always prepended with DESTDIR if set
TOPDIR = $(shell pwd)
prefix ?= /usr
sysconfdir ?= /etc
sbindir ?= /sbin
libdir ?= /lib
plugindir ?= $(libdir)/finit/plugins
incdir = $(prefix)/include/finit
datadir = $(prefix)/share/doc/finit
mandir = $(prefix)/share/man/man8
# The initctl FIFO, should probably be in /run, not /dev
FINIT_FIFO ?= /dev/initctl
FINIT_CONF ?= $(sysconfdir)/finit.conf
FINIT_RCSD ?= $(sysconfdir)/finit.d
CFLAGS += -W -Wall -Werror -Os
# Disable annoying gcc warning for "warn_unused_result", see GIT 37af997
CPPFLAGS += -U_FORTIFY_SOURCE
CPPFLAGS += -Ilibite -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_GNU_SOURCE
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\"
CPPFLAGS += -DFINIT_FIFO=\"$(FINIT_FIFO)\" -DFINIT_CONF=\"$(FINIT_CONF)\"
CPPFLAGS += -DFINIT_RCSD=\"$(FINIT_RCSD)\" -DPLUGIN_PATH=\"$(plugindir)\"
LDFLAGS += -rdynamic -L$(TOPDIR)/libite
DEPLIBS = libite/libite.so
LDLIBS += -ldl -lite
include common.mk
export libdir plugindir incdir ROOTDIR CPPFLAGS LDFLAGS LDLIBS
all: $(DEPLIBS) $(EXEC)
$(MAKE) -C plugins $@
$(DEPLIBS): Makefile
$(MAKE) -C libite all
$(OBJS): Makefile
finit: $(OBJS) $(DEPLIBS)
reboot: reboot.o $(DEPLIBS)
install-exec: all
@$(INSTALL) -d $(DESTDIR)$(FINIT_RCSD)
@$(INSTALL) -d $(DESTDIR)$(sbindir)
@for file in $(EXEC); do \
printf " INSTALL $(DESTDIR)$(sbindir)/$$file\n"; \
$(STRIPINST) $$file $(DESTDIR)$(sbindir)/$$file; \
done
$(MAKE) -C libite install-exec
$(MAKE) -C plugins install
install-data:
@$(INSTALL) -d $(DESTDIR)$(datadir)
@$(INSTALL) -d $(DESTDIR)$(mandir)
@for file in $(DISTFILES); do \
printf " INSTALL $(DESTDIR)$(datadir)/$$file\n"; \
$(INSTALL) -m 0644 $$file $(DESTDIR)$(datadir)/$$file; \
done
install-dev:
@$(INSTALL) -d $(DESTDIR)$(incdir)
@for file in $(HEADERS); do \
printf " INSTALL $(DESTDIR)$(incdir)/$$file\n"; \
$(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \
done
$(MAKE) -C libite install-dev install-exec
install: install-exec install-data install-dev
uninstall-exec:
-@for file in $(EXEC); do \
printf " REMOVE $(DESTDIR)$(sbindir)/$$file\n"; \
rm $(DESTDIR)$(sbindir)/$$file 2>/dev/null; \
done
-@rmdir $(DESTDIR)$(sbindir) 2>/dev/null
-@rmdir $(DESTDIR)$(FINIT_RCSD) 2>/dev/null
$(MAKE) -C libite uninstall
$(MAKE) -C plugins uninstall
uninstall-data:
@for file in $(DISTFILES); do \
printf " REMOVE $(DESTDIR)$(datadir)/$$file\n"; \
rm $(DESTDIR)$(datadir)/$$file 2>/dev/null; \
done
-@rmdir $(DESTDIR)$(mandir)
-@rmdir $(DESTDIR)$(datadir)
uninstall-dev:
-@$(RM) -rf $(DESTDIR)$(incdir)
uninstall: uninstall-exec uninstall-data uninstall-dev
clean:
-@$(RM) $(OBJS) $(DEPS) $(EXEC)
$(MAKE) -C libite $@
$(MAKE) -C plugins $@
distclean: clean
-@$(RM) $(JUNK) unittest *.o .*.d
$(MAKE) -C libite $@
$(MAKE) -C plugins $@
check:
$(CHECK) *.c plugins/*.c libite/*.c
dist:
@echo "Building xz tarball of $(PKG) in parent dir..."
git archive --format=tar --prefix=$(PKG)/ $(VERSION) | xz >../$(ARCHIVE)
@(cd ..; md5sum $(ARCHIVE) | tee $(ARCHIVE).md5)
dev: distclean
@echo "Building unstable xz $(DEV) in parent dir..."
-@$(RM) -f ../$(DEV).tar.xz*
@(dir=`mktemp -d`; mkdir $$dir/$(DEV); cp -a . $$dir/$(DEV); \
cd $$dir; tar --exclude=.git --exclude=contrib \
-c -J -f $(DEV).tar.xz $(DEV); \
cd - >/dev/null; mv $$dir/$(DEV).tar.xz ../; cd ..; \
rm -rf $$dir; md5sum $(DEV).tar.xz | tee $(DEV).tar.xz.md5)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include $(DEPS)
endif
endif
+31
View File
@@ -0,0 +1,31 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = plugins src test
doc_DATA = README.md LICENSE contrib/finit.conf
EXTRA_DIST = README.md LICENSE ChangeLog.md contrib/finit.conf
if CONTRIB
SUBDIRS += contrib
endif
if DOC
SUBDIRS += doc
endif
# Compat hook
install-dev:
@make -C src install-pkgincludeHEADERS
# Target to run when building a release
release: distcheck
@for file in $(DIST_ARCHIVES); do \
md5sum $$file > ../$$file.md5; \
sha256sum $$file > ../$$file.sha256; \
done
@mv $(DIST_ARCHIVES) ../
@echo
@echo "Resulting release files:"
@echo "================================================================="
@for file in $(DIST_ARCHIVES); do \
printf "$$file \tDistribution tarball\n"; \
printf "$$file.md5\t"; cat ../$$file.md5 | cut -f1 -d' '; \
printf "$$file.sha256\t"; cat ../$$file.sha256 | cut -f1 -d' '; \
done
-1
View File
@@ -1 +0,0 @@
NEWS.md
-206
View File
@@ -1,206 +0,0 @@
NEWS
====
1.10 (2014-11-27)
-----------------
Major bug fix release.
* Project now relies on static code analysis from Coverity, so this
release contains many serious bug fixes.
* Fix serious file descriptor and memory leaks in the following
functions. In particular the leaks in `run_interactive()` are very
serious since that function is called every time a service is
started and/or restarted! For details, see the GIT log:
* `helpers.c:run()`
* `helpers.c:run_interactive()`
* `helpers.c:set_hostname()`
* `helpers.c:procname_kill()`
* `svc.c:svc_start()`: Fix swapped arguments to dup2() and add
close(fd) to prevent descriptor leak.
* `svc.c:svc_start()`: Fix out of bounds write to local stack
variable, wrote off-by-one outside array.
* Several added checks for return values to `mknod()`, `mkdir()`,
`remove()`, etc.
* Convert to use Markdown for README, NEWS and TODO.
* Serious update to README and slight pruning of finished TODO items.
1.9 (2014-04-21)
----------------
* Bug fixes, code cleanup
* Add support for an include directive to `.conf` files
* Fallback to `/bin/sh` if user forgets tty setting
* Handle `SIGHUP` from service callback properly when switching runlevel
* Initial support for restarting lost services during `norespwan`
* Misc. major (memleak) and minor fixes and additions to `libite/lite.h`
1.8 (2013-06-07)
----------------
* Support for runlevels, with a bootstrap runlevel 'S'
* Support for saving previous and current runlevel to UTMP
* Support for new `finit.conf` commands: run, task, and runlevel
* Support for tty and console commands in `finit.conf`, like services
but for launching multiple getty logins
* New tty plugin to monitor TTYs coming and going, like USB TTYs
* Bugfixes to libite
1.7 (2012-10-08)
----------------
* Show `__FILE__` in `_d()` debug messages, useful for plugins with
similarily named callbacks. Also, only in debug mode anyway
* Make sure to cleanup recorded PID when a service is lost. Required
by service plugins for their callbacks to work.
* Bugfix: Do not `free()` static string in `finit.conf` parser
* Only clear screen when in verbose mode. Maybe this should be removed
altogether?
1.6 (2012-10-06)
----------------
* Skip . and .. in plugin loader and display error on failed plugins
* Support for overriding `/etc/finit.d` with `runparts DIR` in
`finit.conf`
* Revoke support for starting services not starting with a slash.
* Prevent endless restart of non-existing services in `finit.conf`
* Support for sysvinit style startstop scripts in `/etc/finit.d`
* Minor fix to alsa-utils plugin to silence on non-existing cards
1.5 (2012-10-03)
----------------
* Use bootmisc plugin to setup standard FHS 2.3 structure in `/var`
* Added `FLOG_WARN()` syslog macro, for plugins
* Add plugin dependency resolver. Checks `plugin_t` for `.depends`
1.4 (2012-10-02)
----------------
* Fix I/O plugin watcher and load plugins earlier for a new hook
* Start refactoring helpers.c into a libite.so (-lite). This means
other user space applications/daemons can make use of the neat toolbox
available in finit
* Use short-form -s/-w -u to work with BusyBox hwclock as well
* Use RTLD_GLOBAL flag to tell dynamic loader to load dependent .so
files as well. Lets other plugins use global symbols.
* Greatly simplify svc hook for external plugins and cleanup plugin API.
* And more ... see the GIT log for more details.
1.3 (2012-09-28)
----------------
* Cleanup public plugin API a bit and add new pid/pidfile funcs
* Add plugin hook to end of service startup
* Remove finit.h from svc.h, plugins should not need this.
* Move utility macros etc. to helpers.h
* Make `finit.h` daemon internal, only
* Move defines of FIFO, conf and rcS.d to Makefile => correct paths
* Add support for installing required headers in system include dir
* Better support for distributions and packagers with install-exec,
install-data, and install-dev targets in Makefile. Useful if you want
to call targets with different `$DESTDIR`!
* Makefile fixes for installation, paths encoded wrong
* Strip binaries + .so files, support for `$(CROSS)` toolchain strip
* Default install is now to `/sbin/finit` and `/usr/`
* Note change in `$PLUGIN_DIR` environemnt variable to `$plugindir`
1.2 (2012-09-27)
----------------
* Fix installation paths encoded in finit binary
* Update README with section on building and enviroment variables
1.1 (2012-09-27)
----------------
* Build fixes for ARM eabi/uClibc
* Rename signal.[ch]-->sig.[ch] to avoid name clash w/ system headers
1.0 (2012-09-26)
----------------
* New plugin based system for all odd extensions
* New service monitor that restarts services if they die
* New maintainer at GitHub http://github.com/troglobit/finit
* Add standard LICENSE and AUTHORS files
* New focus: embedded systems and small headless servers
0.6 (2010-06-14)
----------------
* don't start consolekit manually, dbus starts it (rtp)
* unmount all filesystems before rebooting
* disable `USE_VAR_RUN_RESOLVCONF` for Mandriva
* unset terminal type in Mandriva before running X
* remove extra sleep in finit-alt before calling services.sh (caio)
0.5 (2008-08-21)
----------------
* add option to start dbus and consolekit before the X server
* finit-alt listens to `/dev/initctl` to work with `reboot(8)` (smurfy)
* write runlevel to utmp, needed by Printerdrake (Pascal Terjan)
* fix ownership of `/var/run/utmp` (reported by Pascal Terjan)
* remove obsolete code to load AGP drivers
* conditional build of `/etc/resolveconf/run` support
* add support to `/var/run/resolvconf` in Mandriva (blino)
O.4 (2008-05-16)
----------------
* default username for finit-alt configurable in Makefile
* create loopback device node in finit-alt (for squashfs)
* add option to use built-in run-parts instead of `/bin/run-parts`
* ignore signal instead of setting to an empty handler (Metalshark)
* handle pam_console permissions in finit-alt for Mandriva
* add services.sh example and nash-hotplug patch for Mandriva
* mount `/proc/bus/usb` in Mandriva
* add runtime debug to finit-alt if finit_debug parameter is specified
* read configuration from `/etc/finit.conf`
* run getty with openvt on the virtual terminal
0.3 (2008-02-23)
----------------
* Change poweroff method to `reboot(RB_POWER_OFF)` (Metalshark)
* Remove duplicate `unionctl()` reimplementation error
* Fix string termination in path creation
* Mount `/var/lock` and `/var/run` as tmpfs
0.2 (2008-02-19)
----------------
* replace` system("touch")` with `touch()` in finit-mod (Metalshark)
* disable `NO_HCTOSYS` by default to match stock Eeepc kernel
* drop `system("rm -f")` to clean `/tmp`, its a fresh mounted tmpfs
* write ACPI sleep state to `/sys/power/state` instead of
`/proc/acpi/sleep` (Metalshark)
* use direct calls to set loopback instead of `system("ifconfig")`
* replace `system("cat")` and `system("dd")` with C implementation
* moved finit-mod and finit-alt helpers to `helpers.c`
* replace `system("echo;cat")` to draw shutdown splash with C calls
0.1 (2008-02-14)
----------------
* initial release
-1
View File
@@ -1 +0,0 @@
README.md
+559 -343
View File
@@ -1,36 +1,170 @@
README
======
[![Build Status](https://travis-ci.org/troglobit/finit.png?branch=master)](https://travis-ci.org/troglobit/finit)
[![Coverity Scan Status](https://scan.coverity.com/projects/3545/badge.svg)](https://scan.coverity.com/projects/3545)
[![License Badge][]][License] [![Travis Status]][Travis] [![Coverity Status]][Coverity Scan]
<img align="right" src="img/finit3.png" alt="Finit: Fast Init">
Init is the first process to run once a UNIX kernel has booted, it
always has PID 1 and is responsible for starting up the rest of the
system. Finit is a very small plugin based init with built in
[process supervision](https://en.wikipedia.org/wiki/Process_supervision)
similar to that of D.J. Bernstein's
[daemontools](http://cr.yp.to/daemontools.html) and Gerrit Pape's
[runit](http://smarden.org/runit/). Its focus is on small and embedded
GNU/Linux systems, although fully functional on standard server and
desktop installations.
* [Introduction](#introduction)
* [Features](#features)
* [Bootstrap](doc/bootstrap.md#bootstrap)
* [Runlevels](#runlevels)
* [Syntax](doc/config.md#syntax)
* [Runparts & /etc/rc.local](#runparts--etcrclocal)
* [Hooks, Callbacks & Plugins](doc/plugins.md#hooks-callbacks--plugins)
* [Rebooting & Halting](#rebooting--halting)
* [Commands & Status](#commands--status)
* [Tips & Tricks with the kernel cmdline](doc/cmdline.md)
* [Building](doc/build.md#building)
* [Running](doc/build.md#running)
* [Recovery](doc/build.md#recovery)
* [Debugging](doc/build.md#debugging)
* [Requirements](#requirements)
* [Origin & References](#origin--references)
Finit is fast because it is "scripted" with C and starts services in
parallel. Services are supervised and automatically restarted if they
fail. Services can have callbacks that are called before a service is
(re)started. For instance, before attempting to start a heavily
resource intensive service like IPsec or OpenVPN, a callback can check
if the outbound interface is up and has an IP address, or just check if
the service is disabled -- much like what a SysV init start script
usually does.
To extend finit with new functionality, hooks can be added at certain
points in the boot process that execute in sequence, which is useful for
certain satisfying preconditions or for synchronization purposes. One
can also create plugins to functionality to suit your own needs, the
initctl compatibility plugin that comes with finit is one such plugin.
Introduction
------------
Finit is not only fast, it's arguably one of the easiest to get started
with. A complete system can be booted with one simple configuration
file, `/etc/finit.conf`, see below for syntax.
Finit is a simple alternative to [SysV init][4] and [systemd][6]. It
was reverse engineered from the [EeePC fastinit][] over ten years ago
by [Claudio Matsuoka][] — "gaps filled with frog DNA …"
![Alpine screenshot](img/finit4-screenshot.png)
*Figure 1: Screenshot showing Finit booting [Alpine Linux](https://www.alpinelinux.org/).*
Features include:
* Runlevels
* One-shot tasks, daemons, or SysV init scripts
* Runparts and rc.local
* Process supervision
* Sourcing environment files
* Conditions for network/process/custom dependencies
* Pre/Post script actions
* Tooling to enable/disable services
* Built-in getty
* Built-in watchdog, with support for hand-over to [watchdogd](https://troglobit.com/watchdogd.html)
* Built-in support for Debian/BusyBox `/etc/network/interfaces`
* Cgroups v2, both configuration and monitoring in `initctl top`
* Plugin support for customization
* Proper rescue mode with bundled `sulogin` for protected maintenance shell
Focus is on small and embedded systems, although Finit is fully usable
on server and desktop systems as well. For working examples, see the
[contrib/](contrib/) section with tutorials for:
* [Void Linux](contrib/void/),
* [Alpine Linux](contrib/alpine/), and
* [Debian GNU/Linux](contrib/debian/)
Example
-------
This example `/etc/finit.conf` can also be split up in multiple `.conf`
files in `/etc/finit.d`. Available, but not yet enabled, services can
be placed in `/etc/finit.d/available` and enabled by an operator using
the [initctl](#commands--status) tool.
```ApacheConf
# Fallback if /etc/hostname is missing
host default
# Runlevel to start after bootstrap, 'S', default: 2
runlevel 2
# Max file size for each log file: 100 kiB, rotate max 4 copies:
# log => log.1 => log.2.gz => log.3.gz => log.4.gz
log size=100k count=4
# Services to be monitored and respawned as needed
service [S12345] env:-/etc/conf.d/watchdog watchdog $WATCHDOG_OPTS $WATCHDOG_DEV -- System watchdog daemon
service [S12345] env:-/etc/conf.d/syslog syslogd -n $SYSLOGD_OPTS -- System log daemon
service [S12345] <pid/syslogd> env:-/etc/conf.d/klogd klogd -n $KLOGD_OPTS -- Kernel log daemon
service [2345] env:-/etc/conf.d/lldpd lldpd -d $LLDPD_OPTS -- LLDP daemon (IEEE 802.1ab)
# The BusyBox ntpd does not use syslog when running in the foreground
# So we use this trick to redirect stdout/stderr to a log file. The
# log file is rotated with the above settings. The condition declares
# a dependency on a system default route (gateway) to be set. A single
# <!> at the beginning means ntpd does not respect SIGHUP for restart.
service [2345] log:/var/log/ntpd.log <!net/route/default> ntpd -n -l -I eth0 -- NTP daemon
# For multiple instances of the same service, add :ID somewhere between
# the service/run/task keyword and the command.
service :80 [2345] merecat -n -p 80 /var/www -- Web server
service :8080 [2345] merecat -n -p 8080 /var/www -- Old web server
# Alternative method instead of below runparts, can also use /etc/rc.local
#sysv [S] /etc/init.d/keyboard-setup -- Setting up preliminary keymap
#sysv [S] /etc/init.d/acpid -- Starting ACPI Daemon
#task [S] /etc/init.d/kbd -- Preparing console
# Run start scripts from this directory
# runparts /etc/start.d
# Virtual consoles run BusyBox getty, keep kernel default speed
tty [12345] /sbin/getty -L 0 /dev/tty1 linux nowait noclear
tty [2345] /sbin/getty -L 0 /dev/tty2 linux nowait noclear
tty [2345] /sbin/getty -L 0 /dev/tty3 linux nowait noclear
# Use built-in getty for serial port and USB serial
#tty [12345] /dev/ttyAMA0 noclear nowait
#tty [12345] /dev/ttyUSB0 noclear
# Just give me a shell, I need to debug this embedded system!
#tty [12345] console noclear nologin
```
The `service` stanza, as well as `task`, `run` and others are described
in full in [doc/config.md](doc/config.md). Here's a quick overview of
some of the most common components needed to start a UNIX daemon:
```
service [LVLS] <COND> log env:[-]/etc/default/daemon daemon ARGS -- Daemon daemon
^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | `-- Optional description
| | | | | | `----------- Daemon arguments
| | | | | `-------------------------- Path to daemon
| | | | `---------------------------------------------------- Optional env. file
| | | `-------------------------------------------------------- Redirect output to log
| | `--------------------------------------------------------------- Optional conditions
| `---------------------------------------------------------------------- Optional Runlevels
`------------------------------------------------------------------------------ Monitored application
```
Some components are optional: runlevel(s), condition(s) and description,
making it easy to create simple start scripts and still possible for more
advanced uses as well:
service /usr/sbin/sshd -D
Dependencies are handled using [conditions](doc/conditions.md). One of
the most common conditions is to wait for basic networking to become
available:
service <net/route/default> nginx -- High performace HTTP server
Here is another example where we instruct Finit to not start BusyBox
`ntpd` until `syslogd` has started properly. Finit waits for `syslogd`
to create its PID file, by default `/var/run/syslogd.pid`.
service [2345] log <!pid/syslogd> ntpd -n -N -p pool.ntp.org
service [S12345] syslogd -n -- Syslog daemon
Notice the `log` keyword, BusyBox `ntpd` uses `stderr` for logging when
run in the foreground. With `log` Finit redirects `stdout` + `stderr`
to the system log daemon using the command line `logger(1)` tool.
A service, or task, can have multiple dependencies listed. Here we wait
for *both* `syslogd` to have started and basic networking to be up:
service [2345] log <pid/syslogd,net/route/default> ntpd -n -N -p pool.ntp.org
If either condition fails, e.g. loss of networking, `ntpd` is stopped
and as soon as it comes back up again `ntpd` is restarted automatically.
**Note:** Make sure daemons *do not* fork and detach themselves from the
controlling TTY, usually an `-n` or `-f` flag, or `-D` as in the case
of OpenSSH above. If it detaches itself, Finit cannot monitor it and
will instead try to restart it.
Features
@@ -38,353 +172,435 @@ Features
**Process Supervision**
Start, monitor and restart services if they fail.
Start, monitor and restart services should they fail.
**Getty**
Finit supports external getty but also comes with a limited built-in
Getty, useful for really small systems. A getty sets up the TTY and
waits for user input before handing over to `/bin/login`, which is
responsible for handling the actual authentication.
```conf
tty [12345] /dev/tty1 nowait linux
tty [12345] /dev/ttyAMA0 noclear vt100
tty [12345] /sbin/getty -L /dev/ttyAMA0 vt100
```
Users of embedded systems may want to enable automatic serial console
with the special `@console` device. This works regardless weather the
system uses `ttyS0`, `ttyAMA0`, `ttyMXC0`, or anything else. Finit
figures it out by querying sysfs: `/sys/class/tty/console/active`.
```conf
tty [12345] @console linux noclear
```
Notice the optional `noclear`, `nowait`, and `nologin` flags. The
latter is for skipping the login process entirely. For more information,
see [doc/config.md](doc/config.md#syntax).
**Runlevels**
Finit supports standard runlevels if you want, but you don't need them
for simple installations.
Support for SysV init-style [runlevels][5] is available, in the same
minimal style as everything else in Finit. The `[2345]` syntax can be
applied to service, task, run, and TTY stanzas.
Reserved runlevels are 0 and 6, halt and reboot, respectively just like
SysV init. Runlevel 1 can be configured freely, but is recommended to
be kept as the system single-user runlevel since Finit will not start
networking here. The configured `runlevel NUM` from `/etc/finit.conf`
is what Finit changes to after bootstrap, unless 'single' (or 'S') is
given on the kernel cmdline, in which case runlevel 1 is started.
All services in runlevel S(0) are started first, followed by the desired
run-time runlevel. Run tasks in runlevel S can be started in sequence
by using `run [S] cmd`. Changing runlevels at runtime is done like any
other init, e.g. <kbd>init 4</kbd>, but also using the more advanced
`intictl` tool.
**Plugins**
Extend and modify finit behavior. See examples in plugins/ directory.
Plugin capabilities:
Plugins can *extend* the functionality of Finit and *hook into* the
different stages of the boot process and at runtime. Plugins are
written in C and compiled into a dynamic library loaded automatically by
finit at boot. A basic set of plugins are bundled in the `plugins/`
directory.
* Service callbacks — modify service arguments, run/restart/stop
* Task/Run callbacks — a one-shot commands, executed in sequence
* Hooks — hook into the boot at predefined points to extend finit
* I/O — listen to external events and control finit behavior/services
Capabilities:
Extensions and functionality not purely related to what an /sbin/init
- **Hooks**
Hook into the boot at predefined points to extend Finit
- **I/O**
Listen to external events and control Finit behavior/services
Extensions and functionality not purely related to what an `/sbin/init`
needs to start a system are available as a set of plugins that either
hook into the boot process or respond to various I/O.
/etc/finit.conf
---------------
Contrary to most other script based init alternatives
([SysV init](https://en.wikipedia.org/wiki/Init),
[upstart](http://upstart.ubuntu.com/),
[systemd](http://www.freedesktop.org/wiki/Software/systemd/),
[OpenRC](http://www.gentoo.org/proj/en/base/openrc/) and the likes)
finit reads its configuration from `/etc/finit.conf`. Syntax:
* `check <DEV>`
Run fsck on a file system before mounting it
* `module <MODULE>`
Load a kernel module, with optional arguments
* `network <PATH>`
Script or program to bring up networking, with optional arguments
* `runlevel <N>`
N is the runlevel number 1-9, where 6 is reserved for reboot.
Default is 2.
* `run [LVLS] /path/to/cmd ARGS -- Optional description`
One-shot command to run in sequence when entering a runlevel, with
optional arguments and description. This command is guaranteed to
be completed before running the next command.
* `task LVLS] /path/to/cmd ARGS -- Optional description`
One-shot like 'run', but starts in parallel with the next command
* `service [LVLS] /path/to/daemon ARGS -- Optional description`
Service, or daemon, to be monitored and automatically restarted if
it exits prematurely. Please note that you often need to provide
a --foreground or --no-background argument to most daemons to
prevent them from forking off to the background.
* `runparts <PATH>`
Call run-parts(8) on a directory other than default ``/etc/finit.d``
* `include <CONF>`
Include another configuration file, ``/etc/finit.d``, or runparts
path is prepended to file if the file is not found or an absolute
path is not given
* `tty [LVLS] <DEV | /bin/sh>`
Start a getty on the given TTY device, in the given runlevels. When
no tty setting is given in `finit.conf`, or if `/bin/sh` is given as
argument instead of a device path, a single shell is started on the
default console. Useful for really bare-bones systems
See `finit.h` for the `#define GETTY` that is called, along with the
default baud rate.
* `console <DEV>`
Some embedded systems have a dedicated console port. This command
tells finit to not start getty, but instead print a friendly message
and wait for the user to activate the console with a key press before
starting getty.
When running `make install` no default `/etc/finit.conf` will be
provided since the system requirements differ too much. Try out the
Debian 6.0 example `/usr/share/doc/finit/finit.conf` configuration that
is capable of service monitoring SSH, sysklogd, gdm and a console getty!
For more information, see [doc/plugins.md](doc/plugins.md).
/etc/finit.d
------------
**Automatic Reload**
At the end of the boot, when networking and all services are up, finit
calls its built-in run-parts(8) on the `/etc/finit.d/` directory, if
it exists. Similar to how the `/ec/rc.local` file works in most other
init daemons, only finit runs a directory of scripts. This replaces the
earlier support for a `/usr/sbin/services.sh` script in the original
finit.
By default, Finit monitors `/etc/finit.d/` and `/etc/finit.d/enabled/`
registering any changes to `.conf` files. To activate a change the user
must call `initctl reload`, which reloads all modified files, stops any
removed services, starts new ones, and restarts any modified ones. If the
command line arguments of a service have changed, the process will be
terminated and then started again with the updated arguments. If the arguments
have not been modified and the process supports SIGHUP, the process will
receive a SIGHUP rather than being terminated and started.
For some use-cases the extra step of calling `initctl reload` creates an
unnecessary overhead, which can be removed at build-time using:
configure --enable-auto-reload
**Cgroups**
Finit supports cgroups v2 and comes with the following default groups
in which services and user sessions are placed in:
/sys/fs/cgroup
|-- init/ # cpu.weight:100
|-- system/ # cpu.weight:9800
`-- user/ # cpu.weight:100
Finit itself and its helper scripts and services are placed in the
top-level leaf-node group `init/`, which also is _reserved_.
All run/task/service/sysv processes are placed in their own sub-group
in `system/`. The name of each sub-group is taken from the respective
`.conf` file from `/etc/finit.d`.
All getty/tty processes are placed in their own sub-group in `user/`.
The name of each sub-group is taken from the username.
A fourth group also exists, the `root` group. It is also _reserved_ and
primarily intended for RT tasks. If you have RT tasks they need to be
declared as such in their service stanza like this:
service [...] <...> cgroup.root /path/to/foo args -- description
or
cgroup.root
service [...] <...> /path/to/foo args -- description
service [...] <...> /path/to/bar args -- description
See [doc/config.md](doc/config.md#cgroups) for more information, e.g.,
how to configure per-group limits.
The `initctl` tool has three commands to help debug and optimize the
setup and monitoring of cgroups. See the `ps`, `top`, and `cgroup`
commands for details.
Runparts & /etc/rc.local
------------------------
At the end of the boot, when all bootstrap (`S`) tasks and services have
started, but not networking, Finit calls its built-in [run-parts(8)][]
command on any configured `runparts <DIR>` directory. This happens just
before changing to the configured runlevel (default 2). (Networking is
enabled just prior to changing from single user mode.)
```shell
runparts /etc/rc.d/
```
Right after the runlevel change when all services have started properly,
`/etc/rc.local` is called.
No configuration stanza in `/etc/finit.conf` is required for `rc.local`.
If it exists and is an executable shell script Finit calls it at the very
end of the boot, before calling the `HOOK_SYSTEM_UP`. See more on hooks
in [doc/plugins.md](doc/plugins.md#hooks), and about the system bootstrap
in [doc/bootstrap.md](doc/bootstrap.md).
Runlevels
---------
Basic support for [runlevels](http://en.wikipedia.org/wiki/Runlevel) is
included in Finit from v1.8. By default all services, tasks, run
commands and TTYs listed without a set of runlevels get a default set
`[234]` assigned. The default runlevel after boot is 2.
Basic support for [runlevels][5] is included in Finit from v1.8. By
default all services, tasks, run commands and TTYs listed without a set
of runlevels get a default set `[234]` assigned. The default runlevel
after boot is 2.
To specify an allowed set of runlevels for a `service`, `run` command, `task`,
or `tty`, add `[NNN]` to it in your `finit.conf`, like this:
Finit supports runlevels 0-9, and S, with 0 reserved for halt, 6 reboot
and S for services to only run at bootstrap. Runlevel 1 is the single
user level, where usually no networking is enabled. In Finit this is
more of a policy for the user to define. Normally only runlevels 1-6
are used, and even more commonly, only the default runlevel is used.
run [S] /etc/init.d/acpid start -- Starting ACPI Daemon
task [S] /etc/init.d/kbd start -- Preparing console
service [S12345] /sbin/klogd -n -x -- Kernel log daemon
tty [12345] /dev/tty1
tty [2] /dev/tty2
tty [2] /dev/tty3
tty [2] /dev/tty4
tty [2] /dev/tty5
tty [2] /dev/tty6
To specify an allowed set of runlevels for a `service`, `run` command,
`task`, or `tty`, add `[NNN]` to your `/etc/finit.conf`, like this:
In this example acpid is started once at bootstrap using a conventional
SysV init script. Here the run command was used, meaning the following
task command is not run until the init script has fully completed. Then
the keyboard setup script is called in parallel with spawning klogd as
a monitored service.
```
service [S12345] syslogd -n -x -- System log daemon
run [S] /etc/init.d/acpid start -- Starting ACPI Daemon
task [S] /etc/init.d/kbd start -- Preparing console
service [S12345] <pid/syslogd> klogd -n -x -- Kernel log daemon
Tasks and services are started in parallel, while run commands are run
in the order listed and subsequent commands are not started until a run
command has completed.
tty [12345] /dev/tty1
tty [2] /dev/tty2
tty [2] /dev/tty3
tty [2] /dev/tty4
tty [2] /dev/tty5
tty [2] /dev/tty6
```
Existing finit.conf files that lack runlevel setting will get a default
runlevel assigned, `[234]`.
In this example syslogd is first started, in parallel, and then acpid is
called using a conventional SysV init script. It is called with the run
command, meaning the following task command to start the kbd script is
not called until the acpid init script has fully completed. Then the
keyboard setup script is called in parallel with klogd as a monitored
service.
Again, tasks and services are started in parallel, while run commands
are called in the order listed and subsequent commands are not started
until a run command has completed. Also, task and run commands are run
in a shell, so pipes and redirects can be used.
The following examples illustrate this. Bootstrap task and run commands
are also removed when they have completed, `initctl show` will not list
them.
```
task [S] echo "foo" | cat >/tmp/bar
run [S] echo "$HOME" >/tmp/secret
```
Switching between runlevels can be done by calling init with a single
argument, e.g., `init 5` switches to runlevel 5.
argument, e.g. <kbd>init 5</kbd>, or using `initctl runlevel 5`, both
switch to runlevel 5. When changing runlevels Finit also automatically
reloads all `.conf` files in the `/etc/finit.d/` directory. So if you
want to set a new system config, switch to runlevel 1, change all config
files in the system, and touch all `.conf` files in `/etc/finit.d`
before switching back to the previous runlevel again — that way Finit
can both stop old services and start any new ones for you, without
rebooting the system.
Hooks, Callbacks & Plugins
--------------------------
Rebooting & Halting
-------------------
Finit provides only the bare necessities for starting and supervising
processes, with an emphasis on *bare* -- for your convenience it does
however come with support for hooks, service callbacks and plugins that
can used to extend finit with. For your convenience a set of *optional*
plugins are available:
Traditionally, rebooting and halting a UNIX system is done by changing
its runlevel. Finit comes with its own tooling providing: `shutdown`,
`reboot`, `poweroff`, and `suspend`, but also the `initctl` tool,
detailed in the next section.
* *alsa-utils.so*: Restore and save ALSA sound settings on
startup/shutdown.
* *bootmisc.so*: Setup necessary files for UTMP, tracking logins
at boot.
* *dbus.so*: Setup and start system message bus, D-Bus, at boot.
* *hwclock.so*: Restore and save system clock from/to RTC on
startup/shutdown.
* *initctl.so*: Extends finit with a traditional initctl functionality.
* *resolvconf.so*: Setup necessary files for resolvconf at startup.
* *tty.so*: Watches /dev, using inotify, for new device nodes (TTY's) to
start/stop getty consoles on them on demand.
* *urandom.so*: Setup random seed at startup.
* *x11-common.so*: Setup necessary files for X-Window.
Usually you want to hook into the boot process once, simple hook plugins
like `bootmisc.so` are great for that purpose. They are called at each
hook point in the boot process, useful to insert some pre-bootstrap
mechanisms, like generating configuration files, restoring HW device
state, etc. Available hook points are:
* `HOOK_ROOTFS_UP`: When `finit.conf` has been read and `/` has is
mounted -- very early
* `HOOK_BASEFS_UP`: All of `/etc/fstab` is mounted, swap is available
and default init signals are setup
* `HOOK_NETWORK_UP`: System bootstrap, runlevel S, has completed and
networking is up (`lo` is up and the `network` script has run)
* `HOOK_SVC_UP`: All services in the active runlevel has been launched
* `HOOK_SYSTEM_UP`: All services *and* everything in `/etc/finit.d`
has been launched
* `HOOK_SHUTDOWN`: Called at shutdown/reboot, right before all
services are sent `SIGTERM`
Plugins like `initctl.so` and `tty.so` extend finit by acting on events,
they are called I/O plugins and are called from the finit main loop when
`poll()` detects an event. See the source code for `plugins/*.c` for
more help and ideas.
Callback plugins are called by finit them right before a process is
started, or restarted if it exits. The callback receive a pointer to
the `svc_t` (defined in `svc.h`) of the service, with all command line
parameters free to modify if needed. All the callback needs to do is
respond with one of: `SVC_STOP (0)` tells finit to *not* start the
service, `SVC_START (1)` to start the service, or `SVC_RELOAD (2)` to
have finit signal the process with `SIGHUP`.
For compatibility reasons Finit listens to the same set of signals as
BusyBox init. This is not 100% compatible with SysV init, but clearly
the more common combination for Finit. For more details, see
[doc/signals.md](doc/signals.md).
Rebooting and Halting
---------------------
Finit handles `SIGUSR1` and `SIGUSR2` for reboot and halt, and listens
to `/dev/initctl` so system reboot and halt commands should also work.
This latter functionality is implemented in the optional `initctl.so`
plugin.
Building
--------
The finit build system does not employ the GNU Configure and Build System,
instead standard makefiles are used. The user is encouraged to make source
code changes, using defines and conditionally building plugins instead to
alter the behavior of finit.
The following environment variables are checked by the makefiles and control
what is built and where resulting binaries are installed.
* `ROOTDIR=`: Top directory for building complete system, used in pretty
printing.
* `VERSION=`: Defaults to the currently released version of finit,
e.g., 1.3 but can be overridden by packagers using this variable to
add a suffix or completely alter the version.
* `CFLAGS=`: Default `CFLAGS` are inherited from the build environment.
* `CPPFLAGS=`: Default `CPPFLAGS` are inherited from the build
environment.
* `LDFLAGS=`: Default `LDFLAGS` are inherited from the build
environment.
* `LDLIBS=`: Default `LIBLIBS` are inherited from the build environment.
* `prefix=`: Base prefix path for all files, except `sbinbdir` and
`sysconfdir`. Used in concert with the `DESTDIR` variable.
Defaults to `/usr`.
* `sbindir=`: Path to where resulting binaries should install to. Used
in concert with the `DESTDIR` variable.
Defaults to `/sbin`.
* `sysconfdir=`: Path to where finit configuration files should install
to. Used in concert with the `DESTDIR` variable.
Defaults to `/etc`, but is currently unused.
* `PLUGINS=`: List of stock finit plugins to build and install.
* `plugindir=`: Absolute path to where finit should look for dynamically
loadable plugins at runtime. At installation prepended by `DESTDIR`
and `prefix`.
Defaults to `/lib/finit/plugins`.
* `DESTDIR=`: Used by packagers and distributions when building a
relocatable bundle of files. Always prepended to the `prefix`
destination directory.
**Example**
$ tar xfJ finit-1.3.tar.xz
$ PLUGINS="initctl.so hwclock.so" DESTDIR=/tmp/finit/dst \
make -C finit-1.3/ clean install
make: Entering directory `/home/troglobit/finit-1.3'
CC finit.o
CC conf.o
CC helpers.o
CC sig.o
CC svc.o
CC plugin.o
CC strlcpy.o
LINK finit
CC plugins/initctl.o
PLUGIN plugins/initctl.so
CC plugins/hwclock.o
PLUGIN plugins/hwclock.so
INSTALL /tmp/finit/dst/sbin/finit
INSTALL /tmp/finit/dst/lib/finit/plugins/initctl.so
INSTALL /tmp/finit/dst/lib/finit/plugins/hwclock.so
make: Leaving directory `/home/troglobit/finit-1.3'
In this example the
[finit-1.3.tar.xz](ftp://troglobit.com/finit/finit-1.3.tar.xz)
archive is unpacked to the user's home directory, built and
installed to a temporary staging directory. The environment
variables `DESTDIR` and `PLUGINS` are changed to suit this
particular build.
Running
-------
The default install does not setup finit as the system default
`/sbin/init`, neither does it setup an initial `/etc/finit.conf`.
It is assumed that users of finit are competent enough to either setup
finit as their default `/sbin/init` or alter their respective Grub,
LOADLIN, LILO, U-Boot/Barebox or RedBoot boot loader configuration to
give the kernel the following extra command line:
init=/sbin/finit
Debugging
---------
Add `finit_debug`, or `--debug`, to the kernel command line to
enable trace messages. A console getty is always started, see the file
`finit.h` for more useful compile-time tweaks:
init=/sbin/finit --debug
Credits & Contact
Commands & Status
-----------------
This is the continuation of the [original finit](http://helllabs.org/finit/)
by [Claudio Matsuoka](https://github.com/cmatsuoka), which in turn was
reverse engineered from syscalls of the
[EeePC fastinit](http://wiki.eeeuser.com/boot_process:the_boot_process)
-- "gaps filled with frog DNA ...".
Finit also implements a modern API to query status, and start/stop
services, called `initctl`. Unlike `telinit` the `initctl` tool does
not return until the given command has fully completed.
Finit is currently being developed and maintained by
[Joachim Nilsson](http://troglobit.com) at
[GitHub](http://github.com/troglobit/finit). Please file bug reports, clone it,
or send pull requests for bug fixes and proposed extensions.
```
alpine:~# initctl help
Usage: initctl [OPTIONS] [COMMAND]
Options:
-b, --batch Batch mode, no screen size probing
-c, --create Create missing paths (and files) as needed
-f, --force Ignore missing files and arguments, never prompt
-1, --once Only one lap in commands like 'top'
-p, --plain Use plain table headings, no ctrl chars
-q, --quiet Silent, only return status of command
-t, --no-heading Skip table headings
-v, --verbose Verbose output
-h, --help This help text
Commands:
debug Toggle Finit (daemon) debug
help This help text
version Show Finit version
ls | list List all .conf in /etc/finit.d
create <CONF> Create .conf in /etc/finit.d/available
delete <CONF> Delete .conf in /etc/finit.d/available
show <CONF> Show .conf in /etc/finit.d/available
edit <CONF> Edit .conf in /etc/finit.d/available
touch <CONF> Change .conf in /etc/finit.d/available
enable <CONF> Enable .conf in /etc/finit.d/available
disable <CONF> Disable .conf in /etc/finit.d/enabled
reload Reload *.conf in /etc/finit.d (activate changes)
cond set <COND> Set (assert) user-defined condition +usr/COND
cond clear <COND> Clear (deassert) user-defined condition -usr/COND
cond status Show condition status, default cond command
cond dump Dump all conditions and their status
log [NAME] Show ten last Finit, or NAME, messages from syslog
start <NAME>[:ID] Start service by name, with optional ID
stop <NAME>[:ID] Stop/Pause a running service by name
reload <NAME>[:ID] Reload service by name (SIGHUP or restart)
restart <NAME>[:ID] Restart (stop/start) service by name
status <NAME>[:ID] Show service status, by name
status Show status of services, default command
cgroup List cgroup config overview
ps List processes based on cgroups
top Show top-like listing based on cgroups
runlevel [0-9] Show or set runlevel: 0 halt, 6 reboot
reboot Reboot system
halt Halt system
poweroff Halt and power off system
suspend Suspend system
```
For services *not* supporting `SIGHUP` the `<!>` notation in the .conf
file must be used to tell Finit to stop and start it on `reload` and
`runlevel` changes. If `<>` holds more [conditions](doc/conditions.md),
these will also affect how a service is maintained.
> **Note:** even though it is possible to start services not belonging in
> the current runlevel these services will not be respawned automatically
> by Finit if they exit (crash). Hence, if the runlevel is 2, the below
> Dropbear SSH service will not be restarted if it is killed or exits.
The `status` command is the default, it displays a quick overview of all
monitored run/task/services. Here we call `initctl -p`, suitable for
scripting and documentation:
```
alpine:~# initctl -p
PID IDENT STATUS RUNLEVELS DESCRIPTION
======================================================================
1506 acpid running [--2345----] ACPI daemon
1509 crond running [--2345----] Cron daemon
1489 dropbear running [--2345----] Dropbear SSH daemon
1511 klogd running [S12345----] Kernel log daemon
1512 ntpd running [--2345----] NTP daemon
1473 syslogd running [S12345----] Syslog daemon
alpine:~# initctl -pv
PID IDENT STATUS RUNLEVELS COMMAND
======================================================================
1506 acpid running [--2345----] acpid -f
1509 crond running [--2345----] crond -f -S $CRON_OPTS
1489 dropbear running [--2345----] dropbear -R -F $DROPBEAR_OPTS
1511 klogd running [S12345----] klogd -n $KLOGD_OPTS
1512 ntpd running [--2345----] ntpd -n $NTPD_OPTS
1473 syslogd running [S12345----] syslogd -n
```
The environment variables to each of the services above are read from,
in the case of Alpine Linux, `/etc/conf.d/`. Other distributions may
have other directories, e.g., Debian use `/etc/default/`.
The `status` command takes an optional `NAME:ID` argument. Here we
check the status of `dropbear`, which only has one instance in this
system:
```
alpine:~# initctl -p status dropbear
Status : running
Identity : dropbear
Description : Dropbear SSH daemon
Origin : /etc/finit.d/enabled/dropbear.conf
Environment : -/etc/conf.d/dropbear
Condition(s):
Command : dropbear -R -F $DROPBEAR_OPTS
PID file : !/run/dropbear.pid
PID : 1485
User : root
Group : root
Uptime : 2 hour 46 min 56 sec
Runlevels : [--2345----]
Memory : 1.2M
CGroup : /system/dropbear cpu 0 [100, max] mem [--.--, max]
|- 1485 dropbear -R -F
|- 2634 dropbear -R -F
|- 2635 ash
`- 2652 initctl -p status dropbear
Apr 8 12:19:49 alpine authpriv.info dropbear[1485]: Not backgrounding
Apr 8 12:37:45 alpine authpriv.info dropbear[2300]: Child connection from 192.168.121.1:47834
Apr 8 12:37:46 alpine authpriv.notice dropbear[2300]: Password auth succeeded for 'root' from 192.168.121.1:47834
Apr 8 12:37:46 alpine authpriv.info dropbear[2300]: Exit (root) from <192.168.121.1:47834>: Disconnect received
Apr 8 15:02:11 alpine authpriv.info dropbear[2634]: Child connection from 192.168.121.1:48576
Apr 8 15:02:12 alpine authpriv.notice dropbear[2634]: Password auth succeeded for 'root' from 192.168.121.1:48576
```
Requirements
------------
Finit is capable of running on both desktop/server systems with udev and
embedded systems that usually come with BusyBox mdev. Some systems have
systemd-udev or eudev today instead of the original udev, Finit probes
for all of them at runtime and expects `/dev/` to be a writable file
system using `devtmpfs`. It is also possible to run on a statically set
up `/dev` if needed. It is however not a good idea to have both udev
and mdev installed at the same time, this will lead to unpredictable
results.
At boot Finit calls either `mdev` or `udevd` to populate `/dev`, this is
done slightly differently and on systems with udev you might want to add
the following one-shot task early in your `/etc/finit.conf`:
```conf
run [S] udevadm settle --timeout=120 -- Waiting for udev
```
Finit has a built-in Getty for TTYs, but requires a working `/bin/login`
or `/bin/sh`, if no TTYs are configured in `/etc/finit.conf`.
For a fully operational system `/var`, `/run` and `/tmp` must be set up
properly in `/etc/fstab` -- which is iterated over at boot.
Origin & References
-------------------
This project is based on the [original finit][] by [Claudio Matsuoka][]
which was reverse engineered from syscalls of the [EeePC fastinit][] —
"gaps filled with frog DNA …"
Finit is developed and maintained by [Joachim Wiberg][] at [GitHub][].
Please file bug reports, clone it, or send pull requests for bug fixes
and proposed extensions.
[1]: https://en.wikipedia.org/wiki/Process_supervision
[2]: http://cr.yp.to/daemontools.html
[3]: http://smarden.org/runit/
[4]: http://en.wikipedia.org/wiki/Init
[5]: http://en.wikipedia.org/wiki/Runlevel
[6]: https://www.freedesktop.org/wiki/Software/systemd/
[9]: https://github.com/troglobit/troglos
[RFC862]: https://tools.ietf.org/html/rfc862
[RFC863]: https://tools.ietf.org/html/rfc863
[RFC864]: https://tools.ietf.org/html/rfc864
[RFC867]: https://tools.ietf.org/html/rfc867
[RFC868]: https://tools.ietf.org/html/rfc868
[init]: http://en.wikipedia.org/wiki/Init
[upstart]: http://upstart.ubuntu.com/
[systemd]: http://www.freedesktop.org/wiki/Software/systemd/
[openrc]: http://www.gentoo.org/proj/en/base/openrc/
[run-parts(8)]: http://manpages.debian.org/cgi-bin/man.cgi?query=run-parts
[original finit]: http://helllabs.org/finit/
[EeePC fastinit]: https://web.archive.org/web/20071208212450/http://wiki.eeeuser.com/boot_process:the_boot_process
[Claudio Matsuoka]: https://github.com/cmatsuoka
[Joachim Wiberg]: http://troglobit.com
[GitHub]: https://github.com/troglobit/finit
[License]: https://en.wikipedia.org/wiki/MIT_License
[License Badge]: https://img.shields.io/badge/License-MIT-teal.svg
[Travis]: https://travis-ci.org/troglobit/finit
[Travis Status]: https://travis-ci.org/troglobit/finit.svg?branch=master
[Coverity Scan]: https://scan.coverity.com/projects/3545
[Coverity Status]: https://scan.coverity.com/projects/3545/badge.svg
-1
View File
@@ -1 +0,0 @@
TODO.md
-98
View File
@@ -1,98 +0,0 @@
TODO
====
Unsorted TODO list of features and points of investigation that could be
useful for improving finit. But what is an improvement to finit? Well,
similiar to launchd, the goal of finit is to be a FAST replacement for:
* init
* inetd
* crond
* watchdogd
The main goal is to be FAST. Secondary goals are to be: small, simple
and with a very low dependency on external packages.
Inetd
-----
Simple way of running Internet services on demand, like the old inetd:
inetd SVC [RUNLVL] /path/to/daemon args -- description
Example:
# Inetd services, launched on demand
inetd ssh [2345] /usr/sbin/sshd -i -- SSH Daemon
In keeping with the finit tradition, an optional callback can be setup
to each inetd service. When a client connects the finit will call the
callback with a `struct in_pktinfo` argument which the callback then can
allowed or deny.
Priority
--------
The intent of finit is to monitor not just processes, but also to
be able to supervise the entire system and the behavior of certain
processes that declare themselves to be finit compliant.
* Integrate the ingenious libev to handle all events: signals, polling
fd's, etc. Because "Event driven software improves concurrency" --
Dave Zarzycki, Apple.
See the [launchd video](http://www.youtube.com/watch?v=cD_s6Fjdri8)
for more info!
* Add support for a /dev/watchdog plugin to replace watchdogd
* Integrate watchdog plugin with process/system supervisor to optionally
reboot the system when a process stops responding, or when a respawn
limit has been reached, as well as when system load gets too high.
Configuration
-------------
* Add support for `init <q | reload-configuration>` and `SIGHUP` to
have finit reload its `finit.conf`, but also
* Add support for inotify to automatically reload `finit.conf`
Runlevels
---------
* Implement `initctl stop|start|restart|reload|status <SVC>` and
`service <SVC> stop|start|restart|reload|status` on top
* Add PRE and POST hooks for when switching between runlevels
Miscellaneous
-------------
* Add support for `init -v,--version | version`
* Cleanup move sources from top-level directory to `src/` and `include/`
* Make sure to install `queue.h` to `$(PREFIX)/include/finit/queue.h`
* Move `finit.conf` "check" command to plugin which checks `/etc/fstab`
instead. This is the de-facto practice. But keep the check command
for really low-end systems w/o `/etc/fstab`.
Documentation
-------------
* Write man pages for finit and `finit.conf`, steal from the excellent
`pimd` man pages ...
* Update Debian `finit.conf` example with runlevels, `tty/console` and
dependency handling
Investigation
-------------
* [FHS changes](http://askubuntu.com/questions/57297/why-has-var-run-been-migrated-to-run)
affecting runtime status, plugins, etc.
Executable
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
autoreconf -W portability -vifm
-29
View File
@@ -1,29 +0,0 @@
# Top directory for building complete system, fall back to this directory
ROOTDIR ?= $(TOPDIR)
# Some junk files we always want to be removed when doing a make clean.
JUNK = *~ *.bak *.aux *.dvi *.idx *.ind *.log *.ps *.map .*.d DEADJOE semantic.cache *.gdb *.elf core core.*
MAKE := @$(MAKE)
MAKEFLAGS = --no-print-directory --silent
CHECK := cppcheck $(CPPFLAGS) --quiet --enable=all
INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
# Smart autodependecy generation via GCC -M.
.%.d: %.c
@$(SHELL) -ec "$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< \
| sed 's,.*: ,$*.o $@ : ,g' > $@; \
[ -s $@ ] || rm -f $@"
# Override default implicit rules
%.o: %.c
@printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
%: %.o
@printf " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n"
@$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@)))
%.so: %.o
@printf " PLUGIN $(subst $(ROOTDIR)/,,$(shell pwd)/$@)\n"
@$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
-285
View File
@@ -1,285 +0,0 @@
/* Parser for finit.conf
*
* Copyright (c) 2012 Joachim Nilsson <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <ctype.h>
#include <string.h>
#include "finit.h"
#include "svc.h"
#include "tty.h"
#include "lite.h"
#include "helpers.h"
#define MATCH_CMD(l, c, x) \
(!strncmp(l, c, strlen(c)) && (x = (l) + strlen(c)))
static char *strip_line(char *line)
{
char *ptr;
/* Trim leading whitespace */
while (*line && isblank(*line))
line++;
/* Strip any comment at end of line */
ptr = line;
while (*ptr && *ptr != '#')
ptr++;
*ptr = 0;
return line;
}
/* Convert optional "[!123456789S]" string into a bitmask */
int parse_runlevels(char *runlevels)
{
int i, not = 0, bitmask = 0;
if (!runlevels)
runlevels = "[234]";
i = 1;
while (i) {
int level;
char lvl = runlevels[i++];
if (']' == lvl || 0 == lvl)
break;
if ('!' == lvl) {
not = 1;
bitmask = 0x3FE;
continue;
}
if ('s' == lvl || 'S' == lvl)
lvl = '0';
level = lvl - '0';
if (level > 9 || level < 0)
continue;
if (not)
CLRBIT(bitmask, level);
else
SETBIT(bitmask, level);
}
return bitmask;
}
static int parse_conf(char *file)
{
FILE *fp;
char line[LINE_SIZE] = "";
char cmd[CMD_SIZE];
char *x;
const char *err = NULL;
fp = fopen(file, "r");
if (!fp)
return 1;
/*
* If not standard finit.conf, then we want to show just the base name
* Loading configuration ............. vs
* Loading services configuration ....
*/
if (!string_match (file, FINIT_CONF)) {
/* Remove leading path */
x = strrchr(file, '/');
if (!x) x = file;
else x++;
/* Remove ending .conf */
strlcpy(line, x, sizeof(line));
x = strstr(line, ".conf");
if (x) *x = 0;
/* Add empty space. */
strcat(line, " ");
}
print(0, "Loading %sconfiguration", line);
while (!feof(fp)) {
if (!fgets(line, sizeof(line), fp))
continue;
chomp(line);
_d("conf: %s", line);
/* Skip comments. */
if (MATCH_CMD(line, "#", x))
continue;
/* Do this before mounting / read-write
* XXX: Move to plugin which checks /etc/fstab instead */
if (MATCH_CMD(line, "check ", x)) {
char *dev = strip_line(x);
strcpy(cmd, "/sbin/fsck -C -a ");
strlcat(cmd, dev, sizeof(cmd));
run_interactive(cmd, "Checking file system %s", dev);
continue;
}
if (MATCH_CMD(line, "user ", x)) {
if (username) free(username);
username = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "host ", x)) {
if (hostname) free(hostname);
hostname = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "module ", x)) {
char *mod = strip_line(x);
strcpy(cmd, "/sbin/modprobe ");
strlcat(cmd, mod, sizeof(cmd));
run_interactive(cmd, "Loading kernel module %s", mod);
continue;
}
if (MATCH_CMD(line, "mknod ", x)) {
char *dev = strip_line(x);
strcpy(cmd, "/bin/mknod ");
strlcat(cmd, dev, sizeof(cmd));
run_interactive(cmd, "Creating device node %s", dev);
continue;
}
if (MATCH_CMD(line, "network ", x)) {
if (network) free(network);
network = strdup(strip_line(x));
continue;
}
/* This is the directory from which executable scripts and
* any finit include files are read, default /etc/finit.d/ */
if (MATCH_CMD(line, "runparts ", x)) {
if (rcsd) free(rcsd);
rcsd = strdup(strip_line(x));
continue;
}
/* Parse any include file, use rcsd if absolute path not given */
if (MATCH_CMD(line, "include ", x)) {
char *file = strip_line(x);
strlcpy(cmd, file, sizeof(cmd));
if (!fexist(cmd)) {
/* ... try /etc/finit.d/ as prefix */
snprintf(cmd, sizeof(cmd), "%s/%s", rcsd, file);
if (!fexist(cmd))
continue;
}
parse_conf(cmd);
continue;
}
if (MATCH_CMD(line, "startx ", x)) {
svc_register(SVC_CMD_SERVICE, strip_line(x), username);
continue;
}
if (MATCH_CMD(line, "shutdown ", x)) {
if (sdown) free(sdown);
sdown = strdup(strip_line(x));
continue;
}
/* The desired runlevel to start when leaving
* bootstrap (S). Finit supports 1-9, but most
* systems only use 1-6, where 6 is reserved for
* reboot */
if (MATCH_CMD(line, "runlevel ", x)) {
char *token = strip_line(x);
cfglevel = strtonum(token, 1, 9, &err);
if (err)
cfglevel = RUNLEVEL;
if (cfglevel < 1 || cfglevel > 9 || cfglevel == 6)
cfglevel = 2; /* Fallback */
continue;
}
/* Monitored daemon, will be respawned on exit, as
* long as the (optional) service callback returns
* non-zero */
if (MATCH_CMD(line, "service ", x)) {
svc_register(SVC_CMD_SERVICE, x, NULL);
continue;
}
/* One-shot task, will not be respawned. Only runs if
* the (optional) service callback returns true */
if (MATCH_CMD(line, "task ", x)) {
svc_register(SVC_CMD_TASK, x, NULL);
continue;
}
/* Like task but waits for completion, useful w/ [S] */
if (MATCH_CMD(line, "run ", x)) {
svc_register(SVC_CMD_RUN, x, NULL);
continue;
}
if (MATCH_CMD(line, "console ", x)) {
if (console) free(console);
console = strdup(strip_line(x));
continue;
}
if (MATCH_CMD(line, "tty ", x)) {
tty_register(strip_line(x));
continue;
}
}
fclose(fp);
return 0;
}
int parse_finit_conf(char *file)
{
int result;
username = strdup(DEFUSER);
hostname = strdup(DEFHOST);
rcsd = strdup(FINIT_RCSD);
result = parse_conf(file);
if (!tty_num())
tty_register(FALLBACK_SHELL);
return result;
}
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+268
View File
@@ -0,0 +1,268 @@
AC_INIT(Finit, 4.1-rc2, https://github.com/troglobit/finit/issues, finit, https://troglobit.com/finit.html)
AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE([1.11 foreign dist-xz subdir-objects])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR([src/finit.c])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_FILES([Makefile
contrib/Makefile
contrib/alpine/Makefile contrib/alpine/finit.d/Makefile contrib/alpine/finit.d/available/Makefile
contrib/debian/Makefile contrib/debian/finit.d/Makefile contrib/debian/finit.d/available/Makefile
contrib/void/Makefile contrib/void/finit.d/Makefile contrib/void/finit.d/available/Makefile
doc/Makefile
plugins/Makefile
src/Makefile
test/test.env
test/Makefile])
# Older versions of autoconf (<2.58) do not have AC_CONFIG_MACRO_DIR()
#m4_include([m4/plugin.m4])
#m4_include([m4/expand.m4])
AC_CONFIG_MACRO_DIR([m4])
# Handle building plugins either as dynamically loadable, or built-in
LT_INIT([shared disable-static dlopen aix-soname=both disable-fast-install])
# Checks for programs.
AC_PROG_CC
AC_PROG_LN_S
AC_PROG_INSTALL
AC_PROG_MKDIR_P
# Configuration.
AC_HEADER_STDC
AC_CHECK_HEADERS([fstaby.h termios.h sys/ioctl.h])
AC_CHECK_FUNCS([strstr getopt getfsenty])
# Check for uint[8,16,32]_t
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
# Check for pkg-config first, warn if it's not installed
PKG_PROG_PKG_CONFIG
# Check for required libraries
PKG_CHECK_MODULES([uev], [libuev >= 2.2.0])
PKG_CHECK_MODULES([lite], [libite >= 2.2.0])
# Check for configured Finit features
AC_ARG_ENABLE(auto_reload,
AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[
enable_auto_reload=no])
AC_ARG_ENABLE(kernel_cmdline,
AS_HELP_STRING([--enable-kernel-cmdline], [Parse init args from /proc/cmdline (don't use!)]),,[
enable_kernel_cmdline=no])
AC_ARG_ENABLE(redirect,
AS_HELP_STRING([--disable-redirect], [Disable redirection of service output to /dev/null]),,[
enable_redirect=yes])
AC_ARG_ENABLE(logrotate,
AS_HELP_STRING([--disable-logrotate], [Disable built-in rotation of /var/log/wtmp, default enabled]),,[
enable_logrotate=yes])
AC_ARG_ENABLE(doc,
AS_HELP_STRING([--disable-doc], [Disable build and install of doc/ section]),,[
enable_doc=yes])
AC_ARG_ENABLE(contrib,
AS_HELP_STRING([--disable-contrib], [Disable build and install of contrib section]),,[
enable_contrib=yes])
# Check for extra plugins to enable
enable_all_plugins=auto
AC_PLUGIN([alsa-utils], [no], [Save and restore ALSA sound settings using alsactl])
AC_PLUGIN([dbus], [no], [Setup and start system message bus, D-Bus])
AC_PLUGIN([modules-load], [no], [Scans /etc/modules-load.d for modules to load])
AC_PLUGIN([resolvconf], [no], [Setup necessary files for resolvconf])
AC_PLUGIN([x11-common], [no], [Console setup (for X)])
AC_PLUGIN([netlink], [yes], [Basic netlink plugin for IFUP/IFDN and GW events. Can be replaced with externally built plugin that links with libnl or similar.])
AC_PLUGIN([hotplug], [yes], [Setup and start udev or mdev hotplug daemon])
AC_PLUGIN([rtc], [yes], [Save and restore RTC using hwclock])
AC_PLUGIN([urandom], [yes], [Setup and save random seed at boot/shutdown])
# Check for extra arguments or packages
AC_ARG_WITH(heading,
AS_HELP_STRING([--with-heading=GREET], [Display GREET instead of Finit version at boot]),
[heading=$withval], [heading=yes])
AC_ARG_WITH(config,
AS_HELP_STRING([--with-config=CONFIG], [Finit bootstrap config file, default /etc/finit.conf]),
[conf=$withval], [conf=yes])
AC_ARG_WITH(rcsd,
AS_HELP_STRING([--with-rcsd=DIR], [Finit rcS.d/ directory, default /etc/finit.d]),
[rcsd=$withval], [rcsd=yes])
AC_ARG_WITH(rc-local,
AS_HELP_STRING([--with-rc-local=FILE], [SysV init /etc/rc.local file, default /etc/rc.local]),
[rclocal=$withval], [rclocal=yes])
AC_ARG_WITH(sysconfig,
AS_HELP_STRING([--with-sysconfig=DIR], [System environment directory, sourced by .conf files, default /etc/default & /etc/conf.d]),
[sysconfig=$withval], [sysconfig=default])
AC_ARG_WITH(hostname,
AS_HELP_STRING([--with-hostname=NAME], [If /etc/hostname is missing, default: noname]),
[hostname=$withval], [hostname=yes])
AC_ARG_WITH(runlevel,
AS_HELP_STRING([--with-runlevel=N], [Runlevel to switch to after bootstrap, default: 2]),
[runlevel=$withval], [runlevel=yes])
AC_ARG_WITH(random-seed,
AS_HELP_STRING([--with-random-seed=FILE], [Save a random seed for /dev/urandom across reboots, default /var/lib/misc/random-seed]),
[random_seed=$withval], [random_seed=yes])
AC_ARG_WITH(keventd,
AS_HELP_STRING([--with-keventd], [Enable built-in keventd, default: no]),, [with_keventd=no])
AC_ARG_WITH(watchdog,
AS_HELP_STRING([--with-watchdog=[DEV]], [Enable built-in watchdog, default: /dev/watchdog]),
[watchdog=$withval], [with_watchdog=no watchdog=])
### Enable features ###########################################################################
# Create config.h from selected features and fallback defaults
AS_IF([test "x$enable_auto_reload" = "xyes"], [
AC_DEFINE(AUTO_RELOAD, 1, [Finit automatically does `initctl reload` on any .conf change])])
AS_IF([test "x$enable_kernel_cmdline" = "xyes"], [
AC_DEFINE(KERNEL_CMDLINE, 1, [Dumpster diving after init args from /proc/cmdline])])
AS_IF([test "x$enable_redirect" = "xyes"], [
AC_DEFINE(REDIRECT_OUTPUT, 1, [Enable redirection of service output to /dev/null])])
### Disable features ###########################################################################
AS_IF([test "x$enable_logrotate" != "xno"], [
AC_DEFINE(LOGROTATE_ENABLED, 1, [Enable built-in rotation of /var/log/wtmp et al.])])
AM_CONDITIONAL(LOGROTATE, [test "x$enable_logrotate" = "xyes"])
### With features ##############################################################################
AS_IF([test "x$with_config" != "xno"], [
AS_IF([test "x$conf" = "xyes"], [
conf=$sysconfdir/finit.conf])])
AC_EXPAND_DIR(conf_path, "$conf")
AC_DEFINE_UNQUOTED(FINIT_CONF, "$conf_path", [Main Finit configuration file, default /etc/finit.conf])
AC_SUBST(FINIT_CONF, "$conf_path")
AS_IF([test "x$with_rcsd" != "xno"], [
AS_IF([test "x$rcsd" = "xyes"], [
rcsd=$sysconfdir/finit.d])])
AC_EXPAND_DIR(rcsd_path, "$rcsd")
AC_DEFINE_UNQUOTED(FINIT_RCSD, "$rcsd_path", [Finit rcS.d/, default /etc/finit.d])
AC_SUBST(FINIT_RCSD, "$rcsd_path")
AS_IF([test "x$with_rc_local" != "xno"], [
AS_IF([test "x$rclocal" = "xyes"], [
rclocal=$sysconfdir/rc.local])])
AC_EXPAND_DIR(rclocal_path, "$rclocal")
AC_DEFINE_UNQUOTED(FINIT_RC_LOCAL, "$rclocal_path", [Compat SysV /etc/rc.local file to run last at boot.])
AS_IF([test "x$with_sysconfig" != "xno"], [
AS_IF([test "x$sysconfig" != "xdefault"], [
AC_EXPAND_DIR(sysconfig_path, "$sysconfig")
AC_DEFINE_UNQUOTED(FINIT_SYSCONFIG, "$sysconfig_path",
[System environment, default /etc/default & /etc/conf.d])])])
AS_IF([test "x$with_heading" != "xno"], [
AS_IF([test "x$heading" = "xyes"], [
heading="$PACKAGE_NAME v$PACKAGE_VERSION"])])
AC_DEFINE_UNQUOTED(INIT_HEADING, "$heading", [Displayed by Finit at boot])
AS_IF([test "x$with_hostname" != "xno"], [
AS_IF([test "x$hostname" = "xyes"], [
hostname=noname])])
AC_DEFINE_UNQUOTED(DEFHOST, "$hostname", [For /etc/hostname])
AS_IF([test "x$with_runlevel" != "xno"], [
AS_IF([test "x$runlevel" = "xyes"], [
runlevel=2
AC_DEFINE_UNQUOTED(RUNLEVEL, $runlevel, [Default runlevel to start after S])])
AC_DEFINE_UNQUOTED(RUNLEVEL, $runlevel, [Runlevel to start after S])])
AS_IF([test "x$with_random_seed" != "xno"], [
AS_IF([test "x$random_seed" = "xyes"], [
random_seed=/var/lib/misc/random-seed])
AC_EXPAND_DIR(random_path, "$random_seed")
AC_DEFINE_UNQUOTED(RANDOMSEED, "$random_path", [Improve random at boot by seeding it with sth from before.])])
AS_IF([test "x$with_keventd" != "xno"], [with_keventd=yes])
AS_IF([test "x$with_watchdog" != "xno"], [
AS_IF([test "x$watchdog" = "xyes"], [
watchdog=/dev/watchdog])
with_watchdog=yes
AC_DEFINE_UNQUOTED(WDT_DEVNODE, "$watchdog", [Built-in watchdog device node])], [
watchdog=])
# Control build with automake flags
AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"])
AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"])
AM_CONDITIONAL(WATCHDOGD, [test "x$with_watchdog" != "xno"])
AM_CONDITIONAL(DOC, [test "x$enable_doc" = "xyes"])
AM_CONDITIONAL(CONTRIB, [test "x$enable_contrib" = "xyes"])
# Override default libdir, used for plugins and rescue.conf
pkglibdir=$libdir/finit
AC_SUBST(pkglibexecdir)
AC_EXPAND_DIR(pkglibexecdir, "$libexecdir/finit")
AC_DEFINE_UNQUOTED(FINIT_LIBPATH_, "$pkglibexecdir", [Finit libexec path])
AC_EXPAND_DIR(plugin_path, "$libdir/finit/plugins")
AC_SUBST(plugin_path)
AC_DEFINE_UNQUOTED(PLUGIN_PATH, "$plugin_path", [Finit plugin path])
AC_EXPAND_DIR(rescue_conf, "$libdir/finit/rescue.conf")
AC_DEFINE_UNQUOTED(RESCUE_CONF, "$rescue_conf", [Finit rescue mode .conf])
AC_EXPAND_DIR(sample_conf, "$libdir/finit/sample.conf")
AC_DEFINE_UNQUOTED(SAMPLE_CONF, "$sample_conf", [Finit sameple.conf for initctl create])
# Generate all files
AC_OUTPUT
cat <<EOF
------------------ Summary ------------------
$PACKAGE_NAME version $PACKAGE_VERSION
Prefix................: $prefix
Exec prefix...........: $eprefix
Sysconfdir............: `eval echo $sysconfdir`
Localstatedir.........: `eval echo $localstatedir`
Finit config file.....: $conf_path
Finit config.d path...: $rcsd_path
Finit plugin path.....: $plugin_path
Compat rc.local path..: $rclocal_path
System environment....: ${sysconfig_path:-${sysconfig}}
Random seed path......: $random_path
C Compiler............: $CC $CFLAGS $CPPFLAGS $LDFLAGS $LIBS
Linker................: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
Behavior:
Boot heading..........: $heading
Plugins...............: $plugins
Optional features:
Install doc/..........: $enable_doc
Install contrib/......: $enable_contrib
Built-in keventd......: $with_keventd
Built-in watchdogd....: $with_watchdog $watchdog
Built-in logrotate....: $enable_logrotate
Redirect output.......: $enable_redirect
Default hostname......: $hostname
Default runlevel......: $runlevel
------------- Compiler version --------------
$($CC --version || true)
-------------- Linker version ---------------
$($LD --version || true)
---------------------------------------------
Check the above options and compile with:
${MAKE-make}
EOF
+2
View File
@@ -0,0 +1,2 @@
Makefile
Makefile.in
+5
View File
@@ -0,0 +1,5 @@
SUBDIRS = alpine debian void
bin_SCRIPT = service
docsdir := @docdir@/contrib
docs_DATA = README.md finit.conf procmon.sh
EXTRA_DIST = $(docs_DATA)
+12
View File
@@ -0,0 +1,12 @@
Finit Examples
==============
This section provides configuration examples and helpful tools to
install and try out Finit on various Linux distributions.
* [Alpine](alpine/)
* [Debian](debian/)
If you have ideas on how to simplify, extend, or even add new example
configurations for other distributions you are most welcome! :)
+5
View File
@@ -0,0 +1,5 @@
SUBDIRS = finit.d
docsdir := @docdir@/contrib/alpine
docs_DATA = README.md finit.conf alpine-release build.sh install.sh rc.local
EXTRA_DIST = $(docs_DATA)
+48
View File
@@ -0,0 +1,48 @@
HowTo: Finit on Alpine Linux 3.4-3.6
====================================
HowTo use Finit to boot an [Alpine Linux][] system. It is assumed that
the user has already installed make, a compiler, C library header files,
and other tools needed to build a GNU configure based project.
To start with you need to first install [libuEv][] and [libite][]. They
default to install to `/usr/local`, but unlike Debian and Ubuntu based
distros, Alpine's `pkg-config` does not look for libraries and header
files there. So the `PKG_CONFIG_LIBDIR` environment variable must be
used, or change the install prefix to `/usr`.
The bundled [build.sh](build.sh) script can be used to configure and
build finit:
alpine:~# cd finit
alpine:~/finit# ./contrib/alpine/build.sh
Then run the [install.sh](install.sh) script to install all necessary
files, including the sample `finit.conf` and `finit.d/*.conf` files.
More on that below.
alpine:~/finit# ./contrib/alpine/install.sh
The install script is non-destructive by default, you have to answer
*Yes* twice to set up Finit as the system default init. Pay close
attention to the last question:
*** Install Finit as the system default Init (y/N)?
If you answer `No`, simply by pressing enter, you can change the symlink
yourself later on, to point to `finit` instead of `/bin/busybox`:
alpine:~/finit# cd /sbin
alpine:/sbin# rm init
alpine:/sbin# ln -s finit init
Before rebooting, make sure to set up a [/etc/finit.conf](finit.conf),
and [/etc/finit.d/](finit.d/) for your services. Samples are included
in this directory. Notice the symlinks in `/etc/finit.d/`, which can be
managed by the operator at runtime using `initctl enable SERVICE`. You
can also use a standard [/etc/rc.local](rc.local) for one-shot tasks and
initialization like keyboard language etc.
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
[Alpine Linux]: https://www.alpinelinux.org/
+1
View File
@@ -0,0 +1 @@
3.6.2
+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh -e
echo
echo "*** Configuring Finit for Alpine Linux"
if [ ! -e configure ]; then
echo " The configure script is missing, maybe you're using a version from GIT?"
echo " Attempting to run the autogen.sh script, you will need these tools:"
echo " autoconf, automake, libtool, pkg-config ..."
echo
./autogen.sh
fi
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
--prefix=/usr --exec-prefix= \
--sysconfdir=/etc --localstatedir=/var \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --with-watchdog \
--with-heading="Alpine Linux" --with-keventd
echo
echo "*** Building ..."
echo
make
if [ $? -ne 0 ]; then
echo
echo "*** The build failed for some reason"
echo
exit 1
fi
echo
echo "*** Done"
echo
+26
View File
@@ -0,0 +1,26 @@
# /etc/finit.conf: Example for Alpine Linux
# See /etc/finit.d/*.conf and `initctl list` for other services
## Runlevel to start after bootstrap, runlevel 'S'
# Default is 2
#runlevel 2
# Top-level cgroups and their default settings. All groups mandatory
# but more can be added, max 8 groups in total currently. The cgroup
# 'root' is also available, reserved for RT processes. Settings are
# as-is, only one shorthand 'mem.' exists, other than that it's the
# cgroup v2 controller default names.
#cgroup init cpu.weight:100
#cgroup user cpu.weight:100
#cgroup system cpu.weight:9700
# Task to run if ctrl-alt-del is pressed. This condition is asserted by
# Finit upon receiving SIGINT (from the kernel).
#task <sys/key/ctrlaltdel> [12345789] initctl reboot -- Rebooting system
# Task to run if the kernel gets a power fail condition is pressed.
# Asserted by Finit upon receiving SIGPWR (from the kernel).
#task <sys/pwr/fail> [12345789] initctl poweroff -- Shutting down system
## Bootstrap services and tasks
# Can be listed here or in /etc/finit.d/*.conf
+23
View File
@@ -0,0 +1,23 @@
SUBDIRS = available
docsdir := @docdir@/contrib/alpine/finit.d
d_LINKS = acpid.conf crond.conf dropbear.conf getty.conf \
keymap.conf modules.conf ntpd.conf \
klogd.conf syslogd.conf
install-exec-hook:
@$(MKDIR_P) $(DESTDIR)$(docsdir)/available
@$(MKDIR_P) $(DESTDIR)$(docsdir)/enabled
@for file in $(d_LINKS); do \
lnk=$(DESTDIR)$(docsdir)/enabled/$$file; \
src=available/$$file; \
rm -f $$lnk; \
$(LN_S) ../$$src $$lnk; \
done
uninstall-hook:
@for file in $(d_LINKS); do \
lnk=$(DESTDIR)$(docsdir)/enabled/$$file; \
src=available/$$file; \
$(RM) -f $$lnk; \
done
@@ -0,0 +1,4 @@
docsdir := @docdir@/contrib/alpine/finit.d/available
docs_DATA = acpid.conf crond.conf dropbear.conf getty.conf keymap.conf \
lxdm.conf modules.conf ntpd.conf syslog.conf watchdog.conf
EXTRA_DIST = $(docs_DATA)
@@ -0,0 +1,3 @@
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
# Depends on syslogd having started. Redirect any output to log.
service [2345] <pid/syslogd> log acpid -f -- ACPI daemon
@@ -0,0 +1 @@
service [2345] <pid/syslogd> env:-/etc/conf.d/crond crond -f -S $CRON_OPTS -- Cron daemon
@@ -0,0 +1,2 @@
# Start SSH daemon as soon as basic networking comes up
service [2345] env:-/etc/conf.d/dropbear dropbear -R -F $DROPBEAR_OPTS -- Dropbear SSH daemon
@@ -0,0 +1,5 @@
# Consoles to start getty on when system is up
tty [12345] /dev/ttyS0 noclear
tty [12345] /dev/tty1 noclear nowait
tty [2345] /dev/tty2 noclear nowait
tty [2345] /dev/tty3 noclear nowait
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] env:/etc/conf.d/loadkmap zcat $KEYMAP | loadkmap -- Loading keymap
@@ -0,0 +1 @@
service [2345] lxdm -- Lightweight Login Manager
@@ -0,0 +1,7 @@
## Linux kernel modules to load
#module fbcon
#module button
#module evdev
#module mousedev
#module 8139cp
module softdog
@@ -0,0 +1,2 @@
# Busybox ntpd has no option to use syslog when running in foreground
service [2345] <pid/syslogd> env:-/etc/conf.d/ntpd log ntpd -n $NTPD_OPTS -- NTP daemon
@@ -0,0 +1,4 @@
# Start syslogd as soon as possible, should always run
# Start klogd as soon as possible, but after syslogd
service [S12345] env:-/etc/conf.d/syslog syslogd -n $SYSLOGD_OPTS -- Syslog daemon
service [S12345] <pid/syslogd> env:-/etc/conf.d/klogd klogd -n $KLOGD_OPTS -- Kernel log daemon
@@ -0,0 +1 @@
service [S123456789] env:-/etc/conf.d/watchdog watchdog $WATCHDOG_OPTS $WATCHDOG_DEV -- System watchdog
+56
View File
@@ -0,0 +1,56 @@
#!/bin/sh
if [ "x`id -u`" != "x0" ]; then
echo
echo "*** This script must run as root"
echo
exit 1
fi
# Adjust base directory
if [ -e alpine-release ]; then
cd ../..
elif [ ! -e configure.ac ]; then
echo "*** Please run this script from the Finit base directory."
exit 1
fi
echo
echo "*** Install Finit on Alpine Linux"
echo "========================================================================"
echo "/sbin/finit - PID 1"
echo "/lib/finit/plugins/* - All enabled Finit plugins"
echo "/etc/finit.conf - Finit configuration file"
echo "/etc/finit.d/ - Finit services"
echo
read -p "Do you want to continue (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo
echo "*** Installing Finit files ..."
make install
cd /usr/share/doc/finit/contrib/alpine
for file in finit.conf rc.local; do
install -vbD $file /etc/$file
done
cp -va finit.d /etc/
read -p "*** Install Finit as the system default Init (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo "*** Updating /sbin/init symlink --> finit ..."
cd /sbin
rm init
ln -s finit init
rm halt shutdown suspend
ln -s reboot halt
ln -s reboot shutdown
ln -s reboot suspend
fi
echo "*** Done"
echo
else
echo
echo "*** Aborting install."
echo
fi
+8
View File
@@ -0,0 +1,8 @@
#!/bin/sh
# This script is executed once at boot, at the very end,
# right before starting the TTYs.
#
# Each line is run in sequence.
#
# NOTE: Remeber to set the executable bit!
#
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
if [ "x`id -u`" != "x0" ]; then
echo
echo "*** This script must run as root"
echo
exit 1
fi
read -p "Do you really want to uninstall Finit (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo
echo "*** Removing all Finit files ..."
rm -rf /usr/share/doc/finit
rm -rf /etc/finit.conf
rm -rf /etc/finit.d
rm -rf /lib/finit
if [ -e /etc/rc.local ]; then
echo "*** Skipping /etc/rc.local, not sure if we installed it ..."
fi
echo "*** Restoring BusyBox as /sbin/init ..."
cd /sbin
rm init
ln -s /bin/busybox init
rm halt shutdown reboot suspend
ln -s /bin/busybox halt
ln -s /bin/busybox shutdown
ln -s /bin/busybox reboot
ln -s /bin/busybox suspend
echo "*** Done"
echo
else
echo
echo "*** Aborting uninstall."
echo
fi
+4
View File
@@ -0,0 +1,4 @@
SUBDIRS = finit.d
docsdir := @docdir@/contrib/debian
docs_DATA = README.md finit.conf os-release build.sh install.sh
EXTRA_DIST = $(docs_DATA)
+62
View File
@@ -0,0 +1,62 @@
HowTo: Finit on Debian GNU/Linux
================================
HowTo use Finit to boot a Debian GNU/Linux system. It is assumed that
the user has already installed a compiler, C library header files, and
other tools needed to build a GNU configure based project. I.e., at
the very least:
root@debian:~# apt install build-essential
Like the [Alpine HowTo](../alpine/), you need to install [libuEv][] and
[libite][], but since this is Debian — which takes infinite care of its
users ♥ ♥ ♥ we don't need to worry about `pkg-config`, except for having
it installed so it can locate the uEv and lite libraries.
> With Debian everything just works!™
... just make sure to install the following, so `ifup` and other basic
tools pre-systemd work as intended.
root@debian:~# apt install initscripts console-setup
> **Note:** as of Debian 11 (Bullseye), libuev and libite are part of
> the main section of Debian. So just install the -dev packages :)
The following script can then be used to configure, build, install and
set up your system to run Finit:
user@debian:~/finit$ contrib/debian/build.sh
However, since `/sbin/init` already exists on your system, the script
creates another entry in your GRUB config by updating `$SUPPORTED_INITS`
in `/etc/grub.d/10_inux` and run `update-grub`. On reboot you will find
a (finit) entry in the "Advanced options for Debian GNU/Linux" section.
It is of course also possible to change the default init to Finit:
user@debian:~/finit# cd /sbin
user@debian:/sbin# sudo mv init oldinit
user@debian:/sbin# sudo ln -s finit init
Before rebooting, check the default [/etc/finit.conf](finit.conf) and
`/etc/finit.d/*.conf` files. The build + install script above provides
a few sample `.conf` files. See `initctl ls` after boot for a list of
enabled and available services, you can then use `enable` and `disable`
comands to `initctl`, followed by `reload` to activate your changes.
You can also use a standard [/etc/rc.local](rc.local) for one-shot tasks
and initialization like keyboard language etc.
If you want to use the X Window system, `sudo apt install elogind`
(Bullseye and later). Followed by `initctl reload` (enabled by default)
and logout/login again. The elogind daemon ensures a regular non-root
user can start and interact with an X session, otherwise keyboard and
mouse won't work. When you're happy, you can enable the lightdm.conf,
change the default runlevel to 3, and presto! you have a desktop again.
Have fun!
/Joachim ツ
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
+65
View File
@@ -0,0 +1,65 @@
#!/bin/sh
#
# This script configures Finit for Debian, which needs a few more plugins
# and tweaks than an embedded system usually does.
#
# Usage:
# user@jessie:~/finit$ contrib/debian/build.sh
#
echo
echo "*** Configuring Finit for Debian"
if [ ! -e configure ]; then
echo " The configure script is missing, maybe you're using a version from GIT?"
echo " Attempting to run the autogen.sh script, you will need these tools:"
echo " autoconf, automake, libtool, pkg-config ..."
echo
./autogen.sh
fi
echo
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
./configure \
--prefix=/usr --exec-prefix= \
--sysconfdir=/etc --localstatedir=/var \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --with-keventd \
--with-random-seed=/var/lib/urandom/random-seed \
--with-heading="Debian GNU/Linux"
if [ $? -ne 0 ]; then
echo
echo "*** Configure script failed, have you installed libuEv and libite?"
echo
exit 1
fi
echo
echo "*** Building ..."
echo
make
if [ $? -ne 0 ]; then
echo
echo "*** The build failed for some reason"
echo
exit 1
fi
echo
echo "*** Done"
echo
read -p "*** Run (sudo) install script (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
sudo contrib/debian/install.sh
else
echo
echo "*** Use 'sudo contrib/debian/install.sh' later to install Finit"
echo
fi
+26
View File
@@ -0,0 +1,26 @@
# /etc/finit.conf: Example for Debian GNU/Linux
# See /etc/finit.d/*.conf and `initctl list` for other services
## Runlevel to start after bootstrap, runlevel 'S'
# Default is 2
#runlevel 2
# Top-level cgroups and their default settings. All groups mandatory
# but more can be added, max 8 groups in total currently. The cgroup
# 'root' is also available, reserved for RT processes. Settings are
# as-is, only one shorthand 'mem.' exists, other than that it's the
# cgroup v2 controller default names.
#cgroup init cpu.weight:100
#cgroup user cpu.weight:100
#cgroup system cpu.weight:9700
# Task to run if ctrl-alt-del is pressed. This condition is asserted by
# Finit upon receiving SIGINT (from the kernel).
#task <sys/key/ctrlaltdel> [12345789] initctl reboot -- Rebooting system
# Task to run if the kernel gets a power fail condition is pressed.
# Asserted by Finit upon receiving SIGPWR (from the kernel).
#task <sys/pwr/fail> [12345789] initctl poweroff -- Shutting down system
## Bootstrap services and tasks
# Can be listed here or in /etc/finit.d/*.conf
+24
View File
@@ -0,0 +1,24 @@
SUBDIRS = available
docsdir := @docdir@/contrib/debian/finit.d
d_LINKS = acpid.conf apparmor.conf avahi-demon.conf \
bluetooth.conf console-setup.conf elogind.conf \
getty.conf keyboard-setup.conf modules.conf \
rsyslogd.conf sshd.conf
install-exec-hook:
@$(MKDIR_P) $(DESTDIR)$(docsdir)/available
@$(MKDIR_P) $(DESTDIR)$(docsdir)/enabled
@for file in $(d_LINKS); do \
lnk=$(DESTDIR)$(docsdir)/enabled/$$file; \
src=available/$$file; \
rm -f $$lnk; \
$(LN_S) ../$$src $$lnk; \
done
uninstall-hook:
@for file in $(d_LINKS); do \
lnk=$(DESTDIR)$(docsdir)/enabled/$$file; \
src=available/$$file; \
$(RM) -f $$lnk; \
done
@@ -0,0 +1,7 @@
docsdir := @docdir@/contrib/debian/finit.d/available
docs_DATA = acpid.conf apparmor.conf avahi-daemon.conf bluetooth.conf \
console-setup.conf elogind.conf getty.conf \
keyboard-setup.conf lightdm.conf modules.conf sntpd.conf \
rsyslogd.conf sshd.conf syslogd.conf xdm.conf
EXTRA_DIST = $(docs_DATA)
@@ -0,0 +1,3 @@
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
# Depends on a syslog daemon having started. Redirect any output to log.
service [2345] <pid/syslogd> env:-/etc/default/acpid log acpid -f $OPTIONS -- ACPI daemon
@@ -0,0 +1 @@
task [2345] <sys/pwr/ac,pid/syslogd> halt:usr1 env:-/etc/default/anacron anacron -d -q $ANACRON_ARGS -- Anacron jobs
@@ -0,0 +1,2 @@
sysv [S] /etc/init.d/apparmor -- AppArmor initialization
@@ -0,0 +1 @@
service [2345] env:-/etc/default/avahi-daemon avahi-daemon -s $AVAHI_DAEMON_OPTS -- Avahi mDNS/DNS-SD Stack
@@ -0,0 +1,3 @@
# To ignore errors like "org.freedesktop.hostname1", update the env file with
# "--noplugin=hostname", i.e. append to BLUETOOTHD_OPTS
service [2345] log:null env:-/etc/default/bluetooth /usr/libexec/bluetooth/bluetoothd -n $BLUETOOTHD_OPTS -- Bluetooth service
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] /lib/console-setup/console-setup.sh -- Setting up console font and keymap
@@ -0,0 +1 @@
service [2345] <sys/pwr/ac,pid/syslogd> env:-/etc/default/cron cron -f $EXTRA_OPTS -- Background job processing daemon
@@ -0,0 +1,4 @@
# On some systems, bootstrap can be really quick and cause elogind
# to not start before a user has managed to log in. To prevent
# this, add <pid/elogind> as condition to your TTYs in getty.conf
service [2345] <pid/syslogd> /lib/elogind/elogind -- Login manager
@@ -0,0 +1,7 @@
# Consoles to start getty on when system is up
tty [12345] /dev/tty1 linux noclear nowait
tty [2345] /dev/tty2 linux nowait
tty [2345] /dev/tty3 linux nowait
tty [2345] /dev/tty4 linux nowait
tty [2345] /dev/tty5 linux nowait
tty [2345] /dev/tty6 linux nowait
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] /lib/console-setup/keyboard-setup.sh -- Setting up console keyboard layout
@@ -0,0 +1 @@
service [3] lightdm -- Light Display Manager
@@ -0,0 +1,8 @@
## Linux kernel modules to load
#module fbcon
#module button
#module evdev
#module loop
#module psmouse
#module mousedev
#module 8139cp
@@ -0,0 +1,3 @@
# Start rsyslogd as soon as possible, should always run
# Provides pid/syslogd condition
service [S12345] name:syslogd env:-/etc/default/rsyslog rsyslogd -n $RSYSLOGD_OPTIONS -- Reliable syslog daemon
@@ -0,0 +1,2 @@
# Simple NTP client (SNTP)
service [2345] <net/route/default> env:-/etc/default/sntpd sntpd -n $SNTPD_OPTIONS -- SNTP client
@@ -0,0 +1,2 @@
# Start SSH daemon as soon as basic networking comes up
service [2345] <net/lo/up> env:-/etc/default/ssh /usr/sbin/sshd -D $SSHD_OPTS -- OpenSSH daemon
@@ -0,0 +1,2 @@
# Start sysklogd as soon as possible, should always run if enabled
service [S123456789] env:-/etc/default/syslogd syslogd -F $SYSLOGD_OPTIONS -- System logging daemon
@@ -0,0 +1,4 @@
# Here we use XDM since it has few dependencies (relatively speaking).
# It is also an example of a service without a -- description.
# service [3] lxdm -- Lightweight Login Manager
service [3] xdm -nodaemon -- X Display Manager
+61
View File
@@ -0,0 +1,61 @@
#!/bin/sh
if [ "x`id -u`" != "x0" ]; then
echo
echo "=> Unfortunately this script must run as root (sudo) <="
echo
exit 1
fi
# Adjust base directory
grep -q Debian os-release 2>/dev/null
if [ $? -eq 0 ]; then
cd ../..
elif [ ! -e configure.ac ]; then
echo "*** Please run this script from the Finit base directory."
exit 1
fi
echo
echo "*** Install Finit on Debian GNU/Linux"
echo "========================================================================"
echo "/sbin/finit - PID 1"
echo "/lib/finit/plugins/* - All enabled Finit plugins"
echo "/etc/finit.conf - Finit configuration file"
echo "/etc/finit.d/ - Finit services"
echo "/etc/grub.d/10_linux - Add Finit to Grub's SUPPORTED_INITS"
echo
read -p "Do you want to continue (y/N)? " yorn
echo
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo "Installing Finit files ..."
make install
cd /usr/share/doc/finit/contrib/debian
for file in finit.conf; do
install -vbD $file /etc/$file
done
cp -va finit.d /etc/
echo "*** Setting up a GRUB boot entry ..."
fn=/etc/grub.d/10_linux
if [ -e $fn ]; then
if `grep SUPPORTED_INITS $fn |head -1 |grep -q finit`; then
echo "Already installed, done."
else
echo "Adding Finit to list of SUPPORTED_INITS ..."
sed -i 's/SUPPORTED_INITS="[^"]*/& finit:\/sbin\/finit/' $fn
update-grub
fi
else
echo "Cannot find $fn, you'll have to set up your bootloader on your own."
fi
echo
echo "*** Done"
echo
else
echo
echo "*** Aborting install."
echo
fi
+8
View File
@@ -0,0 +1,8 @@
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
+85
View File
@@ -0,0 +1,85 @@
# Sample finit.conf to demonstrate the syntax
#
host testbed
# Linux kernel modules to load
module button
module evdev
module loop
module psmouse
# Top-level cgroups and their default settings. All groups mandatory
# but more can be added, max 8 groups in total currently. The cgroup
# 'root' is also available, reserved for RT processes. Settings are
# as-is, only one shorthand 'mem.' exists, other than that it's the
# cgroup v2 controller default names.
cgroup init cpu.weight:100
cgroup user cpu.weight:100
cgroup system cpu.weight:9700 cpu.max:50000
# Example extra cgroup
cgroup maint cpu.weight:100
# Runlevel to start after bootstrap, runlevel 'S'
runlevel 2
# Network bringup script
network service networking start
# Max file size for each log file: 100 kiB, rotate max 4 copies:
# log => log.1 => log.2.gz => log.3.gz => log.4.gz
log size:100k count:4
# Virtual consoles to start getty on
tty /dev/tty1
tty /dev/tty2
tty /dev/tty3
# Task to run if ctrl-alt-del is pressed. This condition is asserted by
# Finit upon receiving SIGINT (from the kernel).
task <sys/key/ctrlaltdel> [12345789] initctl reboot -- Rebooting system
# Task to run if the kernel gets a power fail condition is pressed.
# Asserted by Finit upon receiving SIGPWR (from the kernel).
task <sys/pwr/fail> [12345789] initctl poweroff -- Shutting down system
# Alternative method instead of runparts
#task [S] /etc/init.d/keyboard-setup start -- Setting up preliminary keymap
#task [S] /etc/init.d/acpid start -- Starting ACPI Daemon
#task [S] /etc/init.d/kbd start -- Preparing console
#run [2] /etc/init.d/networking start -- Start networking
# Services to be monitored and respawned as needed
# klgod and syslogd are placed in the maint cgroup
cgroup.maint
service [2345] <pid/syslogd> klogd -n -- Kernel logging server
service [2345] syslogd -n -- Syslog server
# gdm in the system cgroup (default when read from it's own .conf file)
cgroup.system
service [3] cgroup:cpu.weight:250,mem.max:10M gdm -- GNOME Display Manager
# Start SSH daemon with opts from /etc/default/ssh (if available), move
# to user cgroup with cpu.weight:250. Default for services is system
# group. Default weight in user group is 100 (above). Max length of
# cgroup argument is (currently) 63 chars.
#
# Notice alternative syntax where current cgroup is only set for this
# particular service.
service [2345] cgroup.user:cpu.weight:250,mem.max:10M env:-/etc/default/ssh /usr/sbin/sshd -D $SSHD_OPTS -- OpenSSH daemon
# The BusyBox ntpd does not use syslog when running in the foreground
# So we use this trick to redirect stdout/stderr to a log file. The
# log file is rotated with the above settings. The condition declares
# a dependency on a system default route (gateway) to be set. A single
# <!> at the beginning means ntpd does not respect SIGHUP for restart.
service [2345] <!net/route/default> log:/var/log/ntpd.log ntpd -n -l -I eth0 -- NTP daemon
# Run start scripts from this directory
# runparts /etc/start.d
# For multiple instances of the same service, add :ID somewhere between
# the service/run/task keyword and the command.
service :80 [2345] /sbin/httpd -f -h /http -p 80 -- Web server
service :8080 [2345] /sbin/httpd -f -h /http -p 8080 -- Old web server
-65
View File
@@ -1,65 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: keyboard-setup
# Required-Start: mountkernfs
# Required-Stop:
# Should-Start: keymap udev
# X-Start-Before: checkroot
# Default-Start: S
# Default-Stop:
# X-Interactive: true
# Short-Description: Set preliminary keymap
# Description: Set the console keyboard as early as possible
# so during the file systems checks the administrator
# can interact. At this stage of the boot process
# only the ASCII symbols are supported.
### END INIT INFO
set -e
# This script is not used by keyboard-configuration. It is used
# jointly by console-setup and console-setup-mini
test -f /bin/setupcon || exit 0
if [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
else
log_action_begin_msg () {
echo -n "$@... "
}
log_action_end_msg () {
if [ "$1" -eq 0 ]; then
echo done.
else
echo failed.
fi
}
fi
case "$1" in
stop)
# keyboard-setup isn't a daemon
;;
start|force-reload|restart|reload)
case `readlink /proc/self/fd/2` in
/dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
log_action_begin_msg "Setting preliminary keymap"
if setupcon -k; then
log_action_end_msg 0
else
log_action_end_msg $?
fi
;;
*)
exit 0
;;
esac
;;
*)
echo 'Usage: /etc/init.d/keyboard-setup {start|reload|restart|force-reload|stop}'
exit 1
;;
esac
-81
View File
@@ -1,81 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: acpid
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# X-Start-Before: kdm gdm xdm hal
# X-Stop-After: kdm gdm xdm hal
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start the Advanced Configuration and Power Interface daemon
# Description: Provide a socket for X11, hald and others to multiplex
# kernel ACPI events.
### END INIT INFO
set -e
ACPID="/usr/sbin/acpid"
DEFAULTS="/etc/default/acpid"
# Check for daemon presence
[ -x "$ACPID" ] || exit 0
OPTIONS=""
MODULES=""
# Include acpid defaults if available
[ -r "$DEFAULTS" ] && . "$DEFAULTS"
# Get lsb functions
. /lib/lsb/init-functions
# As the name says. If the kernel supports modules, it'll try to load
# the ones listed in "MODULES".
load_modules() {
[ -f /proc/modules ] || return 0
if [ "$MODULES" = "all" ]; then
MODULES="$(sed -rn 's#^(/lib/modules/[^/]+/)?kernel/(drivers|ubuntu)/acpi/([^/]+/)*(.*)\.ko:.*#\4#p' "/lib/modules/$(uname -r)/modules.dep")"
fi
if [ -z "$MODULES" ]; then
return
fi
log_begin_msg "Loading ACPI kernel modules..."
# work around a bug in initramfs which leaks this env var Launchpad #291619
# and a bug in modprobe --all --quiet which doesn't load all modules and
# exits with non-zero exit status Debian #504088
unset MODPROBE_OPTIONS
modprobe --all --use-blacklist $MODULES 2>/dev/null
log_end_msg $?
}
case "$1" in
start)
load_modules || true
log_begin_msg "Starting ACPI services..."
start-stop-daemon --start --quiet --oknodo --exec "$ACPID" -- $OPTIONS
log_end_msg $?
;;
stop)
log_begin_msg "Stopping ACPI services..."
start-stop-daemon --stop --quiet --oknodo --retry 2 --exec "$ACPID"
log_end_msg $?
;;
restart)
$0 stop
sleep 1
$0 start
;;
reload|force-reload)
log_begin_msg "Reloading ACPI services..."
start-stop-daemon --stop --signal 1 --exec "$ACPID"
log_end_msg $?
;;
status)
status_of_proc "$ACPID" acpid
;;
*)
log_success_msg "Usage: /etc/init.d/acpid {start|stop|restart|reload|force-reload|status}"
exit 1
esac
-259
View File
@@ -1,259 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: kbd
# Required-Start: $remote_fs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# X-Interactive: true
# Description: Set console screen modes and fonts
# Short-Description: Prepare console
### END INIT INFO
# This is the boot script for the `kbd' package.
# It loads parameters from /etc/kbd/config and maybe loads
# default font and map.
# (c) 1997 Yann Dirson
PKG=kbd
if [ -r /etc/$PKG/config ]; then
. /etc/$PKG/config
fi
if [ -d /etc/$PKG/config.d ]; then
for i in `run-parts --list /etc/$PKG/config.d `; do
. $i
done
fi
# do some magic with the variables for compatibility with the config
# file of console-tools
for vc in '' `set | grep "^.*_vc[0-9][0-9]*=" | sed 's/^.*\(_vc[0-9][0-9]*\)=.*/\1/'`
do
eval [ '"'\${SCREEN_FONT$vc}'"' ] && eval CONSOLE_FONT$vc=\${CONSOLE_FONT$vc:-\${SCREEN_FONT$vc}}
eval [ '"'\${SCREEN_FONT_MAP$vc}'"' ] && eval FONT_MAP$vc=\${FONT_MAP$vc:-\${SCREEN_FONT_MAP$vc}}
eval [ '"'\${APP_CHARSET_MAP$vc}'"' ] && eval CONSOLE_MAP$vc=\${CONSOLE_MAP$vc:-\${APP_CHARSET_MAP$vc}}
done
. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin
SETFONT_OPT="-v"
if which setupcon >/dev/null
then
HAVE_SETUPCON=yes
fi
# set DEVICE_PREFIX depending on devfs/udev
if [ -d /dev/vc ]; then
DEVICE_PREFIX="/dev/vc/"
else
DEVICE_PREFIX="/dev/tty"
fi
# determine the system charmap
ENV_FILE=''
[ -r /etc/environment ] && ENV_FILE="/etc/environment"
[ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
[ "$ENV_FILE" ] && CHARMAP=$(set -a && . "$ENV_FILE" && locale charmap)
if [ "$CHARMAP" = "UTF-8" -a -z "$CONSOLE_MAP" ]
then
UNICODE_MODE=yes
fi
reset_vga_palette ()
{
if [ -f /proc/fb ]; then
# They have a framebuffer device.
# That means we have work to do...
echo -n "]R"
fi
}
unicode_start_stop ()
{
vc=$1
if [ -n "$UNICODE_MODE" -a -z "`eval echo \\$CONSOLE_MAP_vc$vc`" ]; then
action=unicode_start
else
action=unicode_stop
fi
if [ "${CONSOLE_FONT}" ]; then
$action "${CONSOLE_FONT}" < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
else
$action < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
fi
}
setup ()
{
# be sure the main program is installed
which setfont >/dev/null || return
VT="no"
# If we can't access the console, quit
CONSOLE_TYPE=`fgconsole 2>/dev/null` || return
if [ ! $CONSOLE_TYPE = "serial" ]; then
readlink /proc/self/fd/0 | grep -q -e /dev/vc -e '/dev/tty[^p]' -e /dev/console
if [ $? -eq 0 ]; then
VT="yes"
reset_vga_palette
fi
fi
[ $VT = "no" ] && return
# start vcstime
if [ "${DO_VCSTIME}" = "yes" ] && which vcstime >/dev/null; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Starting clock on text console"
vcstime &
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
if [ -d /etc/init ] && which initctl >/dev/null; then
# Upstart
LIST_CONSOLES=`cd /etc/init; find -name 'tty*.conf' -printf '%f ' | sed -e 's/[^0-9 ]//g'`
else
# traditional SysV init
LIST_CONSOLES=`sed -e '/^ *#/d' /etc/inittab | grep -e '\<tty[0-9]*\>' | awk -F: '{printf "%s ", $1}'`
fi
# Global default font+map
if [ -z "${HAVE_SETUPCON}" -a "${CONSOLE_FONT}" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up general console font"
sfm="${FONT_MAP}" && [ "$sfm" ] && sfm="-u $sfm"
acm="${CONSOLE_MAP}" && [ "$acm" ] && acm="-m $acm"
# Set for the first 6 VCs (as they are allocated in /etc/inittab)
for vc in $LIST_CONSOLES
do
if ! ( unicode_start_stop $vc \
&& setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm ${CONSOLE_FONT} $acm )
then
[ "$VERBOSE" != "no" ] && log_action_end_msg 1
break
fi
done
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# Default to Unicode mode for new VTs?
if [ -f /sys/module/vt/parameters/default_utf8 ]; then
if [ -n "$UNICODE_MODE" ]; then
echo 1
else
echo 0
fi > /sys/module/vt/parameters/default_utf8
fi
# Per-VC font+sfm
PERVC_FONTS="`set | grep "^CONSOLE_FONT_vc[0-9]*=" | tr -d \' `"
if [ -z "${HAVE_SETUPCON}" -a "${PERVC_FONTS}" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC fonts"
for font in ${PERVC_FONTS}
do
# extract VC and FONTNAME info from variable setting
vc=`echo $font | cut -b16- | cut -d= -f1`
eval font=\$CONSOLE_FONT_vc$vc
# eventually find an associated SFM
eval sfm=\${FONT_MAP_vc${vc}}
[ "$sfm" ] && sfm="-u $sfm"
if ! ( unicode_start_stop $vc \
&& setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm $font )
then
[ "$VERBOSE" != "no" ] && log_action_end_msg 1
break
fi
done
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# Per-VC ACMs
PERVC_ACMS="`set | grep "^CONSOLE_MAP_vc[0-9]*=" | tr -d \' `"
if [ -z "${HAVE_SETUPCON}" -a "${PERVC_ACMS}" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC ACM's"
for acm in ${PERVC_ACMS}
do
# extract VC and ACM_FONTNAME info from variable setting
vc=`echo $acm | cut -b15- | cut -d= -f1`
eval acm=\$CONSOLE_MAP_vc$vc
if ! setfont -C "${DEVICE_PREFIX}$vc" ${SETFONT_OPT} -m "$acm"; then
[ "$VERBOSE" != "no" ] && log_action_end_msg 1
break
fi
done
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# screensaver stuff
setterm_args=""
if [ "$BLANK_TIME" ]; then
setterm_args="$setterm_args -blank $BLANK_TIME"
fi
if [ "$BLANK_DPMS" ]; then
setterm_args="$setterm_args -powersave $BLANK_DPMS"
fi
if [ "$POWERDOWN_TIME" ]; then
setterm_args="$setterm_args -powerdown $POWERDOWN_TIME"
fi
if [ "$setterm_args" ]; then
setterm $setterm_args
fi
# Keyboard rate and delay
KBDRATE_ARGS=""
if [ -n "$KEYBOARD_RATE" ]; then
KBDRATE_ARGS="-r $KEYBOARD_RATE"
fi
if [ -n "$KEYBOARD_DELAY" ]; then
KBDRATE_ARGS="$KBDRATE_ARGS -d $KEYBOARD_DELAY"
fi
if [ -n "$KBDRATE_ARGS" ]; then
[ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting keyboard rate and delay"
kbdrate -s $KBDRATE_ARGS
[ "$VERBOSE" != "no" ] && log_action_end_msg 0
fi
# Inform gpm if present, of potential changes.
if [ -f /var/run/gpm.pid ]; then
kill -s WINCH `cat /var/run/gpm.pid` 2> /dev/null
fi
# Allow user to remap keys on the console
if [ -z "${HAVE_SETUPCON}" -a -r /etc/$PKG/remap ]; then
dumpkeys < ${DEVICE_PREFIX}1 | sed -f /etc/$PKG/remap | loadkeys --quiet
fi
# Set LEDS here
if [ -n "$LEDS" ]; then
for i in $LIST_CONSOLES
do
setleds -D $LEDS < $DEVICE_PREFIX$i
done
fi
}
case "$1" in
start|reload|restart|force-reload)
if [ -n "$HAVE_SETUPCON" ]
then
log_action_msg "Setting console screen modes"
else
log_action_msg "Setting console screen modes and fonts"
fi
setup
[ -z "$HAVE_SETUPCON" ] || log_action_msg "Skipping font and keymap setup (handled by console-setup)"
;;
stop)
;;
*)
setup
;;
esac
:
+15
View File
@@ -0,0 +1,15 @@
# This is a basic /etc/fstab that mounts up all of the virtual filesystems
# that older versions of Finit used to mount internally. It can serve as a
# starting point for systems running Busybox's mount implementation. Make
# sure that CONFIG_FEATURE_MOUNT_HELPERS enabled; as this is required
# create the /dev/{pts,shm} directories.
devtmpfs /dev devtmpfs defaults 0 0
mkdir#-p /dev/pts helper none 0 0
devpts /dev/pts devpts mode=620,ptmxmode=0666 0 0
mkdir#-p /dev/shm helper none 0 0
tmpfs /dev/shm tmpfs mode=0777 0 0
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0
tmpfs /run tmpfs mode=0755,nosuid,nodev 0 0
sysfs /sys sysfs defaults 0 0
+51
View File
@@ -0,0 +1,51 @@
#!/bin/sh
USAGE="Usage: $0 processName"
LOG_FILE="/tmp/memusage.csv"
ELAPSED_TIME=0
PERIOD=1 # seconds
if [ $# -ne 1 ]; then
echo $USAGE
exit 1
fi
echo "ElapsedTime,VmSize,VmRSS" > $LOG_FILE
# Monitor memory usage forever until script is killed
while :
do
SUM_VM_SIZE=0
SUM_RSS_SIZE=0
# In case the monitored process has not yet started
# keep searching until its PID is found
PROCESS_PIDS=""
while :
do
PROCESS_PIDS=`/bin/pidof $1`
if [ "$PROCESS_PIDS.X" != ".X" ]; then
break
fi
done
for PID in ${PROCESS_PIDS} ; do
VM_SIZE=`awk '/VmSize/ {print $2}' < /proc/$PID/status`
if [ "$VM_SIZE.X" = ".X" ]; then
continue
fi
#echo exprVM_ $SUM_VM_SIZE + $VM_SIZE
SUM_VM_SIZE=`expr $SUM_VM_SIZE + $VM_SIZE`
VM_RSS=`awk '/VmRSS/ {print $2}' < /proc/$PID/status`
if [ "$VM_RSS.X" = ".X" ]; then
continue
fi
SUM_RSS_SIZE=`expr $SUM_RSS_SIZE + $VM_RSS`
done
echo "$ELAPSED_TIME sec, $SUM_VM_SIZE KB, $SUM_RSS_SIZE KB"
echo "$ELAPSED_TIME,$SUM_VM_SIZE,$SUM_RSS_SIZE" >> $LOG_FILE
sleep $PERIOD
VM_SIZE=""
VM_RSS=""
# Needs to get actual elapsed time instead of doing this
ELAPSED_TIME=`expr $ELAPSED_TIME + $PERIOD`
done
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
JOB=$1
CMD=$2
usage() {
echo "Usage: service [job# | name] <stop | start | restart | status | show>"
exit 1
}
if [ $# -eq 0 ]; then
initctl show
exit 0
fi
case $CMD in
stop)
;;
start)
;;
restart)
;;
status)
;;
show)
;;
*)
usage
;;
esac
initctl $2 $1
+4
View File
@@ -0,0 +1,4 @@
SUBDIRS = finit.d
docsdir := @docdir@/contrib/void
docs_DATA = README.md finit.conf build.sh install.sh rc.local xbps
EXTRA_DIST = $(docs_DATA)
+62
View File
@@ -0,0 +1,62 @@
HowTo: Finit on Void Linux
==========================
HowTo use Finit to boot an [Void Linux][] system. It is assumed that
the user has already installed make, a compiler, C library header files,
and other tools needed to build a GNU configure based project.
To start with you need to first install [libuEv][] and [libite][]. They
default to install to `/usr/local`, but unlike Debian and Ubuntu based
distros, Void's `pkg-config` does not look for libraries and header
files there. So the `PKG_CONFIG_LIBDIR` environment variable must be
used, or change the install prefix to `/usr`.
The bundled [build.sh](build.sh) script can be used to configure and
build finit:
void:~# cd finit
void:~/finit# ./contrib/void/build.sh
Then run the [install.sh](install.sh) script to install all necessary
files, including the sample `finit.conf` and `finit.d/*.conf` files.
More on that below.
void:~/finit# ./contrib/void/install.sh
The install script is (supposed to be) non-destructive by default, you
have to answer *Yes* twice to set up Finit as the system default init.
Pay close attention to the last question:
*** Install Finit as the system default Init (y/N)?
If you answer `No`, simply by pressing enter, you can change the symlink
yourself later on, to point to `finit` instead of `runit`:
void:~/finit# cd /sbin
void:/sbin# rm init
void:/sbin# ln -s finit init
Another option is to change the Grub defaults, in `/etc/default/grub`:
#GRUB_CMDLINE_LINUX_DEFAULT="loglevel=4 slub_debug=P page_poison=1"
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=4 init=/sbin/finit"
Alternatively, you can simply modify the default Grub entry at boot, or
set up an alternative Grub entry to include:
linux /boot/vmlinuz-X.YY.Z ... init=/sbin/finit
If you modify a Grub configuration file, remember to run:
update-grub
Before rebooting, make sure to set up a [/etc/finit.conf](finit.conf),
and [/etc/finit.d/](finit.d/) for your services. Samples are included
in this directory. Notice the symlinks in `/etc/finit.d/`, which can be
managed by the operator at runtime using `initctl enable SERVICE`. You
can also use a standard [/etc/rc.local](rc.local) for one-shot tasks and
initialization like keyboard language etc.
[libuEv]: https://github.com/troglobit/libuev
[libite]: https://github.com/troglobit/libite
[Void Linux]: https://www.voidlinux.eu/
+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh -e
echo
echo "*** Configuring Finit for Void Linux"
if [ ! -e configure ]; then
echo " The configure script is missing, maybe you're using a version from GIT?"
echo " Attempting to run the autogen.sh script, you will need these tools:"
echo " autoconf, automake, libtool, pkg-config ..."
echo
./autogen.sh
fi
# The plugins are optional, but you may need D-Bus and X11 if you want
# to run X-Window, the other configure flags are however required.
PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig ./configure \
--prefix=/usr --exec-prefix= \
--sysconfdir=/etc --localstatedir=/var \
--enable-dbus-plugin --enable-x11-common-plugin \
--enable-alsa-utils-plugin --with-watchdog \
--with-heading="Void Linux" --with-keventd
echo
echo "*** Building ..."
echo
make
if [ $? -ne 0 ]; then
echo
echo "*** The build failed for some reason"
echo
exit 1
fi
echo
echo "*** Done"
echo
+26
View File
@@ -0,0 +1,26 @@
# /etc/finit.conf: Example for Void Linux
# See /etc/finit.d/*.conf and `initctl list` for other services
## Runlevel to start after bootstrap, runlevel 'S'
# Default is 2
#runlevel 2
# Top-level cgroups and their default settings. All groups mandatory
# but more can be added, max 8 groups in total currently. The cgroup
# 'root' is also available, reserved for RT processes. Settings are
# as-is, only one shorthand 'mem.' exists, other than that it's the
# cgroup v2 controller default names.
#cgroup init cpu.weight:100
#cgroup user cpu.weight:100
#cgroup system cpu.weight:9700
# Task to run if ctrl-alt-del is pressed. This condition is asserted by
# Finit upon receiving SIGINT (from the kernel).
#task <sys/key/ctrlaltdel> [12345789] initctl reboot -- Rebooting system
# Task to run if the kernel gets a power fail condition is pressed.
# Asserted by Finit upon receiving SIGPWR (from the kernel).
#task <sys/pwr/fail> [12345789] initctl poweroff -- Shutting down system
## Bootstrap services and tasks
# Can be listed here or in /etc/finit.d/*.conf
+21
View File
@@ -0,0 +1,21 @@
SUBDIRS = available
docsdir := @docdir@/contrib/void/finit.d
d_LINKS = acpid.conf dhcpcd.conf getty.conf sshd.conf uuidd.conf
install-exec-hook:
@$(MKDIR_P) $(DESTDIR)$(docsdir)/available
@$(MKDIR_P) $(DESTDIR)$(docsdir)/enabled
@for file in $(d_LINKS); do \
lnk=$(DESTDIR)$(docsdir)/enabled/$$file; \
src=available/$$file; \
rm -f $$lnk; \
$(LN_S) ../$$src $$lnk; \
done
uninstall-hook:
@for file in $(d_LINKS); do \
lnk=$(DESTDIR)$(docsdir)/enabled/$$file; \
src=available/$$file; \
$(RM) -f $$lnk; \
done
@@ -0,0 +1,5 @@
docsdir := @docdir@/contrib/void/finit.d/available
docs_DATA = acpid.conf crond.conf dhcpcd.conf dmeventd.conf getty.conf \
keymap.conf lxdm.conf modules.conf ntpd.conf \
sshd.conf syslog.conf uuidd.conf
EXTRA_DIST = $(docs_DATA)
@@ -0,0 +1,3 @@
# Handle PWR button to shutdown/reboot -- useful in Qemu (virt-manager)
# Depends on syslogd having started. Redirect any output to log.
service [2345] acpid -f -- ACPI daemon
@@ -0,0 +1 @@
service [2345] <pid/syslogd> crond -f -S -c /etc/crontabs -- Cron daemon
@@ -0,0 +1 @@
service [2345] dhcpcd -B -M -- DHCP client
@@ -0,0 +1 @@
service [S12345] dmeventd -f -- Device mapper event daemon
@@ -0,0 +1,4 @@
# Consoles to start Finit built-in getty on when system is up
tty [12345] /dev/tty1 noclear nowait
tty [2345] /dev/tty2 noclear nowait
tty [2345] /dev/tty3 noclear nowait
@@ -0,0 +1,2 @@
# Oneshot task to run once at bootstrap
task [S] zcat /etc/keymap/se.bmap.gz | loadkmap -- Loading keymap
+1
View File
@@ -0,0 +1 @@
service [2345] lxdm -- Lightweight Login Manager
@@ -0,0 +1,7 @@
## Linux kernel modules to load
#module fbcon
#module button
#module evdev
#module mousedev
#module 8139cp
module softdog
+2
View File
@@ -0,0 +1,2 @@
# Silly Busybox ntpd has no option to use syslog when running in foreground
service [2345] <pid/syslogd> log ntpd -n -N -p pool.ntp.org -- NTP daemon
+2
View File
@@ -0,0 +1,2 @@
# Start SSH daemon as soon as basic networking comes up
service [2345] /usr/sbin/sshd -D -- OpenSSH daemon
@@ -0,0 +1,4 @@
# Start syslogd as soon as possible, should always run
# Start klogd as soon as possible, but after syslogd
service [S12345] syslogd -n -- Syslog daemon
service [S12345] <pid/syslogd> klogd -n -- Kernel log daemon
@@ -0,0 +1 @@
service @uuidd:uuidd [2345] uuidd -F -- UUID generation daemon
+53
View File
@@ -0,0 +1,53 @@
#!/bin/sh
if [ "x`id -u`" != "x0" ]; then
echo
echo "*** This script must run as root"
echo
exit 1
fi
# Adjust base directory
if [ -e xbps ]; then
cd ../..
elif [ ! -e configure.ac ]; then
echo "*** Please run this script from the Finit base directory."
exit 1
fi
echo
echo "*** Install Finit on Void Linux"
echo "========================================================================"
echo "/sbin/finit - PID 1"
echo "/lib/finit/plugins/* - All enabled Finit plugins"
echo "/etc/finit.conf - Finit configuration file"
echo "/etc/finit.d/ - Finit services"
echo "/etc/grub.d/40_custom - Add menu entry to the Grub boot loader"
echo
read -p "Do you want to continue (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo
echo "*** Installing Finit files ..."
make install
cd /usr/share/doc/finit/contrib/void
for file in finit.conf rc.local; do
install -vbD $file /etc/$file
done
cp -va finit.d /etc/
read -p "*** Install Finit as the system default Init (y/N)? " yorn
if [ "x$yorn" = "xy" -o "x$yorn" = "xY" ]; then
echo "*** Updating /sbin/init symlink --> finit ..."
cd /sbin
rm init
ln -s finit init
fi
echo "*** Done"
echo
else
echo
echo "*** Aborting install."
echo
fi
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
# This script is executed once at boot, at the very end,
# right before starting the TTYs.
#
# Each line is run in sequence.
#
# NOTE: Remeber to set the executable bit!
View File
+2
View File
@@ -0,0 +1,2 @@
Makefile
Makefile.in
+4
View File
@@ -0,0 +1,4 @@
docsdir := @docdir@/doc
docs_DATA = config.md conditions.md distro.md plugins.md \
service.md signals.md svc-machine.png cmdline.md
EXTRA_DIST = $(docs_DATA)
+1
View File
@@ -0,0 +1 @@
config.md

Some files were not shown because too many files have changed in this diff Show More