diff --git a/finit.c b/finit.c index f6af17de..0efec2d1 100644 --- a/finit.c +++ b/finit.c @@ -184,19 +184,17 @@ int main(int argc, char* argv[]) */ run_interactive(SETUP_DEVFS, "Populating device tree"); + /* + * Load plugins first, finit.conf may contain references to + * features implemented by plugins. + */ + print_result(plugin_load_all(&ctx, PLUGIN_PATH)); + /* * Parse configuration file */ parse_finit_conf(FINIT_CONF); - /* - * Load plugins. Must run after finit.conf has registered - * all services, or service plugins won't have anything to - * hook on to. - */ - print_desc("Loading plugins", NULL); - print_result(plugin_load_all(&ctx, PLUGIN_PATH)); - /* * Mount filesystems */ diff --git a/plugin.c b/plugin.c index 8bd3215d..484a0768 100644 --- a/plugin.c +++ b/plugin.c @@ -43,13 +43,12 @@ static void check_plugin_depends(plugin_t *plugin); int plugin_register(plugin_t *plugin) { - int i, inuse = 0; - if (!plugin) { errno = EINVAL; return 1; } + /* Setup default name if none is provided */ if (!plugin->name) { Dl_info info; @@ -65,37 +64,15 @@ int plugin_register(plugin_t *plugin) return 0; } + /* Resolve plugin dependencies */ check_plugin_depends(plugin); - if (is_io_plugin(plugin)) - inuse++; - - if (plugin->svc.cb) { - svc_t *svc = svc_find(plugin->name); - - if (svc) { - inuse++; - svc->cb = plugin->svc.cb; - svc->dynamic = plugin->svc.dynamic; - svc->dynamic_stop = plugin->svc.dynamic_stop; - } - } - - for (i = 0; i < HOOK_MAX_NUM; i++) { - if (plugin->hook[i].cb) - inuse++; - } - - if (!inuse) { - _d("No service \"%s\" loaded, and no I/O or finit hooks, skipping plugin.", basename(plugin->name)); - return 1; - } - TAILQ_INSERT_TAIL(&plugins, plugin, link); return 0; } +/* Not called, at the moment plugins cannot be unloaded. */ int plugin_unregister(plugin_t *plugin) { TAILQ_REMOVE(&plugins, plugin, link); @@ -282,6 +259,7 @@ int plugin_load_all(uev_ctx_t *ctx, char *path) DIR *dp = opendir(path); struct dirent *entry; + print_desc("Loading plugins", NULL); if (!dp) { _e("Failed, cannot open plugin directory %s: %s", path, strerror(errno)); return 1; diff --git a/svc.c b/svc.c index ca1d4b6e..69e97979 100644 --- a/svc.c +++ b/svc.c @@ -378,6 +378,13 @@ int svc_register(int type, char *line, char *username) while ((cmd = strtok(NULL, " "))) strlcpy(svc->args[i++], cmd, sizeof(svc->args[0])); svc->args[i][0] = 0; + + plugin = plugin_find(svc->cmd); + if (plugin && plugin->svc.cb) { + svc->cb = plugin->svc.cb; + svc->dynamic = plugin->svc.dynamic; + svc->dynamic_stop = plugin->svc.dynamic_stop; + } } svc->runlevels = parse_runlevels(runlevels);