diff --git a/doc/plugins.md b/doc/plugins.md index dce92469..5324829d 100644 --- a/doc/plugins.md +++ b/doc/plugins.md @@ -168,6 +168,12 @@ hook points: * `HOOK_BASEFS_UP`, `hook/mount/all`: All of `/etc/fstab` is mounted, swap is available and default init signals are setup +* `HOOK_SVC_PLUGIN`, `hook/svc/plugin`: Called in `conf_init()` right + before loading `/etc/finit.conf`. For plugins to register any early + run/task/services, please do NOT use any earlier hook point. That + will cause uninitialized rlimits that lead to unpredictable results + when Finit later tries to start the run/task/service. + * `HOOK_NETWORK_UP`, `hook/net/up`: System bootstrap, runlevel S, has completed and networking is up (`lo` is up and the `network` script has run) diff --git a/plugins/dbus.c b/plugins/dbus.c index 6b1ea8a0..a7feae36 100644 --- a/plugins/dbus.c +++ b/plugins/dbus.c @@ -163,11 +163,8 @@ static void setup(void *arg) } static plugin_t plugin = { - .name = __FILE__, - .hook[HOOK_BASEFS_UP] = { - .cb = setup - }, - .depends = { "bootmisc", }, + .name = __FILE__, + .hook[HOOK_SVC_PLUGIN] = { .cb = setup }, }; PLUGIN_INIT(plugin_init) diff --git a/plugins/hotplug.c b/plugins/hotplug.c index 5eb5e6e2..701c33bc 100644 --- a/plugins/hotplug.c +++ b/plugins/hotplug.c @@ -91,11 +91,8 @@ static void setup(void *arg) } static plugin_t plugin = { - .name = __FILE__, - .hook[HOOK_BASEFS_UP] = { - .cb = setup - }, - .depends = { "bootmisc", "modprobe" }, + .name = __FILE__, + .hook[HOOK_SVC_PLUGIN] = { .cb = setup }, }; PLUGIN_INIT(plugin_init) diff --git a/plugins/modules-load.c b/plugins/modules-load.c index b6efbfcc..2a4a461c 100644 --- a/plugins/modules-load.c +++ b/plugins/modules-load.c @@ -212,10 +212,8 @@ static void load(void *arg) } static plugin_t plugin = { - .name = __FILE__, - .hook[HOOK_BASEFS_UP] = { - .cb = load - }, + .name = __FILE__, + .hook[HOOK_SVC_PLUGIN] = { .cb = load }, }; PLUGIN_INIT(plugin_init) diff --git a/src/conf.c b/src/conf.c index a167075a..5a13a637 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1209,6 +1209,9 @@ int conf_init(uev_ctx_t *ctx) /* Initialize global rlimits, e.g. for built-in services */ memcpy(global_rlimit, initial_rlimit, sizeof(global_rlimit)); + dbg("Allow plugins to register early runlevel 1 run/task/services ..."); + plugin_run_hooks(HOOK_SVC_PLUGIN); + /* Read global rlimits and global cgroup setup from /etc/finit.conf */ parse_conf(finit_conf, 0); diff --git a/src/finit.c b/src/finit.c index 2f642fe9..807bf2b5 100644 --- a/src/finit.c +++ b/src/finit.c @@ -476,6 +476,9 @@ static void fs_mount_all(void) dbg("Finalize, ensure common file systems are available ..."); fs_finalize(); + + dbg("Base FS up, calling hooks ..."); + plugin_run_hooks(HOOK_BASEFS_UP); } /* @@ -789,7 +792,11 @@ int main(int argc, char *argv[]) */ fs_mount_all(); - /* Bootstrap conditions, needed for hooks */ + /* + * Base FS up, enable standard SysV init signals and + * Bootstrap conditions, needed for hooks + */ + sig_setup(&loop); cond_init(); /* @@ -821,12 +828,6 @@ int main(int argc, char *argv[]) if (whichp(FINIT_LIBPATH_ "/keventd")) service_register(SVC_TYPE_SERVICE, "[123456789] cgroup.init " FINIT_LIBPATH_ "/keventd -- Finit kernel event daemon", global_rlimit, NULL); - /* Base FS up, enable standard SysV init signals */ - sig_setup(&loop); - - dbg("Base FS up, calling hooks ..."); - plugin_run_hooks(HOOK_BASEFS_UP); - /* * Set up inotify watcher for /etc/finit.conf, /etc/finit.d, and * their deps, to figure out how to bootstrap the system. diff --git a/src/plugin.h b/src/plugin.h index 2e1ce538..fbb56a0d 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -72,6 +72,7 @@ CHOOSE(HOOK_MOUNT_ERROR, "hook/mount/error"), \ CHOOSE(HOOK_MOUNT_POST, "hook/mount/post"), \ CHOOSE(HOOK_BASEFS_UP, "hook/mount/all"), \ + CHOOSE(HOOK_SVC_PLUGIN, "hook/svc/plugin"), \ CHOOSE(HOOK_NETWORK_UP, "hook/net/up"), \ CHOOSE(HOOK_SVC_UP, "hook/svc/up"), \ CHOOSE(HOOK_SYSTEM_UP, "hook/sys/up"), \