Convert finit to use libev and fix so plugin ctors runs on dlopen().

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>
This commit is contained in:
Joachim Nilsson committed 2012-09-25 14:23:23 +02:00
1 parent 5dda9051ac
commit 0e02429e75
25 files changed
+620 -1073

No files matched your search

+21 -17
View File
@@ -30,10 +30,15 @@
#include "finit.h"
#include "helpers.h"
#include "private.h"
#include "plugin.h"
#include "service.h"
#include "svc.h"
#include "signal.h"
/* Match one command. */
#define MATCH_CMD(l, c, x) \
(!strncmp(l, c, strlen(c)) && (x = (l) + strlen(c)))
int debug = 0;
int verbose = 1;
char *sdown = NULL;
@@ -157,7 +162,7 @@ static void parse_finit_conf(char *file)
continue;
}
if (MATCH_CMD(line, "service ", x)) {
if (service_register (x))
if (svc_register(x))
_e("Failed, too many services to monitor.\n");
continue;
}
@@ -168,6 +173,8 @@ static void parse_finit_conf(char *file)
int main(int UNUSED(args), char *argv[])
{
struct ev_loop *loop = ev_default_loop(0);
/*
* Initial setup of signals, ignore all until we're up.
*/
@@ -204,9 +211,6 @@ int main(int UNUSED(args), char *argv[])
cls();
echo("finit " VERSION " (built " __DATE__ " " __TIME__ " by " WHOAMI ")");
_d("Loading plugins ...");
load_plugins(PLUGIN_PATH);
/*
* Parse configuration file
*/
@@ -237,9 +241,13 @@ int main(int UNUSED(args), char *argv[])
sig_setup();
/*
* Most user-level hooks run here, unless they are service hooks
* Load plugins and run first level hooks.
*/
run_hooks(HOOK_POST_SIGSETUP);
_d("Loading plugins ...");
load_plugins(loop, PLUGIN_PATH);
_d("Running first level hooks ...");
run_hooks(HOOK_BASEFS_UP);
/*
* Network stuff
@@ -259,21 +267,17 @@ int main(int UNUSED(args), char *argv[])
/*
* Hooks that rely on loopback, or basic networking being up.
*/
run_hooks(HOOK_POST_NETWORK);
run_hooks(HOOK_NETWORK_UP);
/*
* Start service monitor framework
*/
_d("Starting services from %s", FINIT_CONF);
service_startup();
_d("Starting all static services from %s", FINIT_CONF);
svc_start_all();
/* Run startup scripts in /etc/finit.d/, if any. */
run_parts(FINIT_RCSD);
#ifdef LISTEN_INITCTL
listen_initctl();
#endif
if (!fork()) {
/* child process */
int i;
@@ -341,12 +345,12 @@ int main(int UNUSED(args), char *argv[])
/*
* Hooks that should run at the very end
*/
run_hooks(HOOK_PRE_RUNLOOP);
run_hooks(HOOK_SYSTEM_UP);
/*
* Enter main service monitor loop -- restarts services that dies.
* Enter main loop to monior /dev/initctl and services
*/
service_monitor();
ev_run(loop, 0);
return 0;
}