mirror of
https://github.com/troglobit/finit.git
synced 2026-10-08 16:34:45 +07:00
Load plugins before finit.conf is parsed, needed by internal inetd services
This patch is slightly sub-optimal, since it will causes us to load all availble plugins, not just those referenced by finit.conf. However, in the short term perspective we need to reference internal inted services provided by plugins from finit.conf, so the dependency order is clear. In the midterm perspective we want to add support for SIGHUP to reload finit.conf, but not plugins. So again, this is an OK patch. One fix would be to allow loading of all plugins, parse finit.conf and then unload all unused plugins before continuing. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user