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>
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>
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>
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>
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>
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>
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>
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>
This commit adds support for calling plugin hooks when all services
have been started properly. Useful for, e.g., a 3rd party service
monitor to trigger further events on.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
Lots of cleanup and simplification of the main code in this commit.
Most notably libev has been added to take care of the main loop and
monitor services. Still TODO is migrating to use the libev signal
handling.
Convert initctl.c:listen_initctl() to a plugin instead. This also
meant introducing a new form of I/O plugin to finit, also handled
by libev.
Load plugins *after* we've setup the base filesystem (BASEFS) in case
plugins reside on a filesystem not reachable before "mount -a" has run.
This also has the side effect of lining up nicely with the first level
plugin hooks.
If a plugin wants to hook up with a loded service we connect them by
their respective numeric IDs in plugin_register(). I.e., the service
monitor checks if a service has a registered callback, which in turn
decides if a service should be started, stopped or reloaded.
Rip out old EeePC distribution defines from finit.h, none of it really
applies anymore. If you need distribution specific settings this is
the place to put them.
Make hookpoint names (#defines) clearer: after BASEFS, after networking,
after all setup, etc.
Use #inlude_next <signal.h> in signal.h to include system header file!
Simplify service monitor: move essential code to svc.c and rip out
the TIPC dependency. Write your own service.so plugin, or wait for
a more complete example of how to extend service monitoring using
the primitives in svc.c
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>