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>
chomp():
Removed first \n instead of last \n
set_hostname():
If /etc/hostname exists we need to realloc the size of
the current hostname variable. Also, only try to set
the hostname if !NULL
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The ROOTDIR variable was only set in the top-level Makefile,
so when building from a subdirectory the output was slightly
garbled. Moved ROOTDIR declaration to common.mk.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
- 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>
More inspiration and courage from the launchd Google Talk video!
Fascinating stuff about replacing init/inetd/cron/watchdogd that
I've been thinking about for ages!
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit adds a line: "Loading kernel modules ..." before increasing
indentation level of module loading messages.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
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>
This commit adds support for specifying TTY and console to be used
for starting a getty to login to the system
Add the following to your finit.conf to use this feature:
tty ttyS0
tty ttyUSB0
console ttyS0
Signed-off-by: Mattias Walström <lazzer@gmail.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit adds a statistics counter to the finit svc_t process struct
which is incremented every time a process is restarted by the service
monitor.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This patch reorders the shutdown/reboot handler slightly and fixes
a bug in sleep(). It seems the sleep() syscall was interrupted by
receiving lots of SIGCHLD. Unsurprisingly since we just sent all
processes SIGTERM, but unfortunate since that was too short time
to deliver SIGTERM to watchdogd.
We now call sleep() again, as long as it returns a non-zero value,
until at most two (2) seconds have passed. During this time we
basically pend for watchdogd to do its job and let the WDT reboot
the system. If the two second timeout passes we send SIGKILL and
forcibly reboot(RB_AUTOBOOT) the system.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
When using the simple rsync() or copyfile() functions of libite some
error codes should not be interpreted as error. I.e., if a file or
directory already exists when attempting to create it.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The ROOTDIR variable is used for pretty formatting during compilation.
Some users might want to have this display the build from the top of
their tree instead of the finit build tree.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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.
This is a bugfix to 785c21d, which introduced the new runparts
directive in finit.conf
- Do not attempt to free() a static string, use same approach as
username and hostname.
- Do not overwrite hostname, set the correct variable if runparts
directive is found in finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Many callbacks check their svc->pid to determine SVC_RELOAD or SVC_START,
they rely on it to be updated. When a service is lost we must therefore
clear its recorded PID before asking the callback what to do.
Also, swap comparison in debug code for dumping service arguments ...
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
The run_parts() implementation used variable arguments in a bad way,
resulting in it not working properly. Replaced va_*() code with a
simple cmd argument that's passed to each script called.
Also, the opendir()/readdir() code has been replaced with scandir()
using regular alphasort(). This simplifies the code somewhat as well.
Otherwise, minor cleanups.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Sometimes people type in the wrong path to a service directive in
finit.conf, or the executable isn't installed. This commit makes
sure to check if the command exists before attempting to start it.
This also means that we now require service commands to start with
/ to indicate an absolute path. We used to search the PATH for a
suitable executable, using execvp(), but that's rather insecure as
well, so we now use only execv().
Also, added support for adding "start" or "stop" to entries found
in /etc/finit.d starting with SNNname, or KNNname, where NN is a
number. This makes it possible to simply import sysvinit style
start scripts from /etc/rcS.d and /etc/rcN.d/.
The alsa-utils plugin also had some minor fixes, added -g option
to ignore non-existing soundcards and fixed cut-paste bug on the
_d() debug messages.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
Fix from field testing. Need to skip "." and ".." directory entries
when loading plugins from /lib/finit/plugins. Also, trigger an error
when a required plugin fails to load. We need to print to console
since syslogd has not started yet.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This has been something I wanted to avoid, but then I stumbled so hard
on it myself I simply had to add it. With this commit finit actually
comes of age -- it's now possible to do anything a modern init can --
only faster! :-)
Included in this commit is the OpenBSD version of sys/queue.h, which
unline all versions of the same file on Linux has the _FOREACH_SAFE
macros for iterating over a linked list.
The plugins are now in a TAILQ, loaded in alphabetic order and, unless
the dependency resolver says otherwise, added last in the queue. So,
naming your plugins according to standard sysvinit rules: S01, S02,
etc. takes care of the most basic dependency resolution. When that is
not sufficient, simply add a line ".depends = { "other_plugin",
"another_plugin" }," to your plugin_t definition. Be careful though
for circular dependencies, we don't check for those.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This was missing from the 1.4 release due to it being hidden in one
of my private plugins. Sorry!
Also, add another log macro. Warnings are quite useful things to have.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
- Use RTLD_GLOBAL flag to tell dynamic loader to load dependent .so
files as well. Also lets other plugins use globally scoped symbols.
- Check for plugin hooks as well before dismissing plugin as unused.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit removes a lot of unnecessary overhead for handling external
service plugins. Instead of traversing the plugin array every time a
service callback should run we set the plugin callback in the svc_t when
the plugin is registered.
Also, make sure to check for norespawn/SIGSTOP in svc_reload() as well.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Improve upon API names, both internal and external, to make it clearer
where methods are located and clarify responsibility.
Add new Makefile target "dev" to create untagged development snapshots.
Bump version for upcoming release.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>