Commit Graph
125 Commits
Author SHA1 Message Date
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 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 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 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 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
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
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
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 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 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 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 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 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 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 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 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 45bdadebb6 Minor cleanup
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-07-18 17:30:14 +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 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 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 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 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 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 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 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 8bcc34ce91 Remove Emacs version-control handling
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2016-03-21 15:41:51 +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 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 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
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 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