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>
Updates to README include changed environment variables and a
clarification of why there is no default /etc/finit.conf after make
install.
Also, the /etc/finit.d directory is now created, as expected, by
make install.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
- 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/
- Use the 'plugindir' environemnt variable instead of 'PLUGIN_DIR'
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Break up install/uninstall targets in top Makefile into separate
install-exec, install-data, and install-dev for packagers and
distributions wishing to call Makefile with different DESTDIR's
depending on building -bin or -devel package.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Minor cleanup of Makefile and added support for installing necessary
header files, for developing external plugins, to system include path.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
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>
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>
The installation path for plugins was encoded wrong in the finit binary
if *not* unset, i.e., "prefix=".
Updated the README with information on all build related environment
variables. Much of it is perhaps only needed for packagers and
distributions.
New version bump, v1.2 already.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit fixes the following warning on an ARM eabi/uClibc system.
helpers.c:86: error: dereferencing pointer 'a' does break strict-aliasing rules
The fix is trivial. Simply set IPv4 addressing scheme in the
struct ifreq instead of the struct sockaddr_in, whic is just
a pointer into the same ifreq anyway.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Tried to solve the signal.h name clash by using #include_next, but
seeing as this is not recommended[1] and breaks builds on some cross
compilers, the files were simply renamed: signal.[ch] --> sig.[ch]
[1] - http://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This change is purely for people interacting with the GitHub interface.
The README itself is written in the plain text reST format.
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>
New function helpers.c:run_getty() refactored from main(). Used to
start a default console getty.
Removed startx finit.conf option, superseded by service statement,
see examples/finit.conf for a working use case.
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>
finit.conf:
Use this as /etc/finit.conf on a Debian 6.0 based system with X
installed and sysklogd instead of rsyslogd. Works.
services:
Alternative method for extending the finit boot procedure. Simply
place this script file in an /etc/finit.d/ directory. The script
uses the standard run-parts tool to chain load other start scripts.
helpers.c:
o New functions:
- run(): home grown system() replacement
- run_interactive(): display progress and status when called
o Bugfix start_process(), make sure to use same signal setup for
children as in run() and run_interactive(). Also, use execvp()
instead of execv() to allow searching $PATH for executables.
finit.h:
o Move signal specific code to new signal.h.
o Bypass verbosity setting to let echo() always print to screen.
finit.c:
o Make run_parts() the default, remove external deps, it works.
o Use run() and run_interactive() to speed up execution further
on embedded systems where forking is expensive.
o Kernel cmdline "quiet" should not close STDIO since this makes
it impossible to run some daemons and start scripts. Instead,
we let "quiet" toggle the finit verbosity setting.
o Remove kernel cmdline "--verbose" (Upstart compat), to be used
to enable verbose finit when kernel should be quiet.
o Setup kernel specific settings in /etc/sysctl.conf
o Fix D-Bus startup problems. Probably what caused X from not
working initially. Silly rabbit.
o Use system() workaround to start X, cannot get it to start
at all using run() or run_interactive() at the moment.
signal.h:
New file, header file for signal.c. Was about time.
signal.c:
Remove blocking of SIGCHLD from sig_setup(), instead we setup
SIGCHLD early in sig_init() to handle fork() in run() & C:o.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
finit.c:
o New service and shell_service stanzas for finit.conf
o Run service_startup() before /etc/finit.d/ hooks
o Run service_monitor() at end of startup
helpers.c:
o Several new functions:
- print_desc() displays a service starting up
- print_result() shows if service started OK or not
- start_process() is used by the services framework
svc.c:
Generic API for managing svc_t structures
ipc.o:
TIPC based framework for communicating with the service monitor.
E.g., to relay (re)configuration signals from a Web/CLI
front-end via finit to one or many setup daemons, and back.
services.c:
Service monitor framework
strlcpy.c:
Secure strncpy() replacement from OpenBSD under the free ISC License.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Update license and copyright information details in all files.
Much cleanup by moving hard coded strings/data to #defines and using more
common default values for each such #define.
finit.c:
o Make sdown[], startx[] allocated strings by default NULL
o This fixes the issues where the shutdown handler segfaulted
o Add ability to handle NULL input to build_cmd() by allocating space
o Ignore kernel cmdline "quiet" if in debug mode
o Add support for "network" stanza in finit.conf
o Mount -n to skip removing /etc/mtab
o Call swapon to enable swap if enabled in /etc/fstab
o Cleanup /tmp, /var/run and /var/lock
o Move sig_setup() *after* mount, sig_init() otoh runs early
o Start initctl monitor before forking off startx/getty process
o The startx process is now the console process. Only a getty is
started when in debug mode. Otherwise only X is started if it
is properly setup in /etc/finit.conf
o NOTE: Currently X evdev does not work!
o Support for /usr/sbin/services.sh has been replaced with finit
now instead supporting builtin run-parts for /etc/finit.d/
helpers.c:
o Bug fixes in run_parts() and also added chdir(oldpwd) at bottom.
o New functions:
- getuser() similar to getgroup()
- cls() clear screen, only runs when not in debug mode
- set_procname() used to set name "console" on console process
- set_hostname() encapsulates /etc/hostname and sethostname()
signal.c:
o Split sig_setup() in two: sig_init() and sig_setup()
The former to be called as soon as possible, while latter is
supposed to run when the base filesystem is properly up.
o Remove hard coded distribution specific progress bar write()
o Add debug messages to do_shutdown()
o Remove any lingering sync files in sig_setup()
initctl.c:
o Add debug messages and a new default: case to catch stray runlevels
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Cleanup device creation and initial mount by assuming that the kernel
has devtmpfs enabled. This is the default for most modern GNU/Linux
distributions. See http://lwn.net/Articles/331818/ for more info.
Also, since finit is targeted at deeply embedded systems hooks for the
BusyBox udev replacement, mdev has been added. If MDEV is defined in
the build it will take care of both hotplugging of devices and initial
setup of /dev
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Check for "--verbose", as well as "finit_debug", on kernel command
line to enable debugging of finit. The former is a compatibility
option with upstart, see http://upstart.ubuntu.com/wiki/Debugging
Add the following to the kernel command line to enable:
"init=/sbin/finit --verbose"
Without the quote characters.
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
finit.c:
Skip standard UNIX comment character '#' if it appears at the
beginning of a row in finit.conf
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>