Commit Graph
60 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 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
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 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 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 60df2043ac sm: handle runlevel change
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
2016-05-18 10:18:40 +02: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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 f6f2895524 Add support for a fallback shell if no tty is setup
Try to do better by the user, by default, if no tty is specified in the
finit.conf.  This way the user will at least have a way to interact with
the system and repair it.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-19 22:58:20 +02:00
Joachim Nilsson 62287f8fcc Add support for including .conf files.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2014-04-19 22:56:19 +02:00
Joachim Nilsson bf40278131 Delay start of TTYs to let system stabilize at boot.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-06-06 18:19:27 +02:00
Joachim Nilsson 0f60aa2289 Refactor TTY code to honor runlevels and use I/O plugin to watch /dev
Add support for runlevels to tty command and support for reading baud
rate and TERM variable from finit.conf.

The tty-watcher thread has been converted to a standard I/O plugin.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-06-06 18:19:26 +02:00
Joachim Nilsson 6448d6ccfa Coding style and whitespace fixes
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-06-04 09:25:11 +02:00
Joachim Nilsson 25cc9f3b9b Improve runlevel support by adding a bootstrap phase, also adds task/run cmd
Most systems need an early bootstrap phase for one-shot tasks and
necessary one-time probing.  This phase usually runs well before any
networking is setup.  This commit adds support for that 'S' runlevel,
and also extends the number of possible total runlevels to nine.

For the one-shot tasks that run in bootstrap two new finit.conf cmds
have been added:

   - task: For one-shot tasks that can be started in parallell
   - run:  For one-shot tasks that must run in sequence

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-06-04 09:25:05 +02:00
Joachim Nilsson e776838de9 Rename USE_UDEV & MDEV to SETUP_DEVFS and USE_MESSAGE_BUS to HAVE_DBUS
USE_UDEV,MDEV   => Unique SETUP_DEVFS for embedded or distro usage.
USE_MESSAGE_BUS => HAVE_DBUS

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-06-04 07:21:08 +02:00
Joachim Nilsson f690767507 Refactor .conf file parser and add support for runlevel N
This commit is a refactor of how arguments to finit.conf file settings
are parsed.  Not all settings are run directly, but only need the arg
for future use.  The code should be a lot easier to understand now.

Also, added support for specifying the desired runlevel in finit.conf

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-05-22 12:42:56 +02:00
Joachim Nilsson 5ba7bc1fdf Cleanup and simplify boot process messages
- Remove indentation of module loading and device node creation
- Clarify that we load kernel modules
- Clarify that we load Finit plugins
- Remove cls()
- Remove verbose condition for echo()
- Make banner a separate function with optional distribution banner
- Add a few neat ANSI escape sequences for cls(), clreol(), delline(), etc.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-05-21 12:52:06 +02:00
Mattias Walström 5d04a72a61 Add support for toggling the debug mode at runtime
This commit adds support for -d, --debug option to init, which can
be used to toggle the finit debug mode at runtime.

Signed-off-by: Mattias Walström <lazzer@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-05-19 19:01:44 +02:00
Joachim Nilsson c3b76fdccf Add basic support for runlevels and bugfix FIFO I/O plugins
Like most other init implementations do, when entering runlevel 1, finit
creates the file /etc/nologin to prevent users from logging in during
single-user mode, this file is then removed upon leaving runlevel 1.

Also, bugfix how FIFO I/O plugins are handled in finit.  A FIFO will
need to be reopened by the server side when the client closes the pipe.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2013-05-19 19:01:44 +02:00
Mattias Walström 5961748b2a Add basic support to specify login TTYs in configuration
This also adds support for monitor /dev for TTYs appering after boot,
USB-to-serial converters for example.

Some limitations: Baudrate (and other settings) is hardcoded for now,
should be read from config file.
2013-01-22 21:17:20 +01:00
Joachim Nilsson 785c21d27b Support for overriding built-in default FINIT_RCSD in finit.conf
This commit adds support for the "runparts <DIR>" directive to
finit.conf.  Enabling the user to override the built-in default,
which by default is /etc/finit.d.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2012-10-05 18:50:21 +02:00
Joachim Nilsson 65c9e7ebc6 Fix I/O plugin watcher, load plugins earlier to enable a new early hook!
Restructure start by calling the plugin loader earlier. This makes it
possible to run hooks even earlier.  This also adds a new hook:
HOOK_ROOTFS_UP which runs as soon as the system root (/) is available.

Another very notable change is the slow refactor of helpers.c into a finit
helper library called libite.so (-lite). This is a light-weight

Also, lots of misc. fixes all over the place. Signal handling still really
needs to be looked into once more!

Makefile:
        Add dependency handling for parallell build
        Add libite library

ChangeLog:
        Update with new 1.4 release. There is a lot of fixes!

libite/:
        Collection of utility functions and C library extensions for
        finit & its plugins

reboot.c:
        New reboot tool. Simply sends SIGINT to PID 1

finit.h:
        Cleanup old LISTEN_INITCTL define, code is in an optional plugin now

finit.c:
        Let mdev/udev run *after* cls()
        Add useful debug statement for /proc/cmdline
        Earlier plugin load => new early hook point
        Show OK/FAIL for total plugin load, not for each plugin => speedup

helpers.h:
        Rename syslog macros to prevent common name clashes (DEBUG/ERROR)
        Add __FILE__ to _e(), _d() and _pe() macros

helpers.c:
        In ifconfig() the addr and mask arguments are now optional
        The copyfile() has been moved to libite.so
        Temporarily remove const directive from some functions to build
        Use DFLSIG() macro in run_getty() to simplify code

plugin.h:
        Add new HOOK_ROOTFS_UP hook

plugin.c:
        Fix init_plugins() to actually register the plugin's I/O fd
        Skip verbose listing of all plugins in plugin_load_all()

svc.c:
        svc_start(): Dito

plugins/Makefile:
        Inherit CFLAGS and LDFLAGS, but make sure to filter out -rdynamic
        from LDFLAGS, it's used by the daemon, only

plugins/initctl.c:
        New includes after helpers.h refactor

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2012-10-02 08:25:50 +02:00
Joachim Nilsson 149ed0e81c Minor header comment updates and bump version to 1.3
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2012-09-28 15:59:15 +02:00
Joachim Nilsson 06759d3544 Streamline plugin include files plugin.h, svc.h, and helpers.h
Move utility macros from finit.h to helpers.h and continue refactoring
and streamlining of public plugin API.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2012-09-27 22:10:07 +02:00
Joachim Nilsson c49d89dfe0 Revert new experimental libev backend due to time constraints
Due to time constraints I had to revert the new libev backend to the
service, I/O and signals monitor.  Employed instead is the tried and
tested signals based service monitor, with a small extension for an
additional I/O monitor using poll() for the I/O plugins to use.

Tried restoring the startx finit.conf directive on top of the service
implementation. However, it's currently not usable to run /usr/bin/startx
for any other user than root. I recommend using the examples/finit.conf
and run /usr/sbin/gdm instead.

finit.c:
        New run_loop() function, replaces libev ev_run().

helpers.c:
        Refactor start_process() into svc_start().

plugin.c:
        Add fds[] array for use in the io_monitor() called by the
        new run_loop().

signal.c:
        Ignore SIGCHLD. Handled by waitpid() in svc_monitor() now,
        which is called by the new run_loop().

svc.c:
        svc_register(): Optional @username parsing for the command line.
        svc_monitor(): Replaced libev callback with waitpid()
        svc_start(): Refactored to use most of helpers.c:start_process()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2012-09-26 12:18:54 +02:00