mirror of
https://github.com/troglobit/finit.git
synced 2026-10-17 10:49:34 +00:00
Greatly simplify svc hook for external plugins
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>
This commit is contained in:
1 parent
f55f68d032
commit
5116cd66ef
5 files changed
+44
-67
No files matched your search
@@ -32,7 +32,6 @@
|
||||
#include "private.h"
|
||||
#include "helpers.h"
|
||||
#include "plugin.h"
|
||||
#include "svc.h"
|
||||
|
||||
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd >= 0)
|
||||
|
||||
@@ -69,11 +68,13 @@ int plugin_register(plugin_t *plugin)
|
||||
}
|
||||
|
||||
if (plugin->svc.cb) {
|
||||
svc_t *svc = svc_find_by_name(plugin->name);
|
||||
svc_t *svc = svc_find(plugin->name);
|
||||
|
||||
if (svc) {
|
||||
plugin->svc.id = svc_id(svc);
|
||||
inuse++;
|
||||
svc->cb = plugin->svc.cb;
|
||||
svc->dynamic = plugin->svc.dynamic;
|
||||
svc->dynamic_stop = plugin->svc.dynamic_stop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +92,15 @@ int plugin_unregister(plugin_t *plugin)
|
||||
{
|
||||
LIST_REMOVE(plugin, link);
|
||||
|
||||
if (plugin->svc.cb) {
|
||||
svc_t *svc = svc_find(plugin->name);
|
||||
|
||||
if (svc) {
|
||||
svc->cb = NULL;
|
||||
svc->dynamic = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX: Unfinished, add cleanup code here! */
|
||||
|
||||
return 0;
|
||||
@@ -109,21 +119,6 @@ void plugin_run_hooks(hook_point_t no)
|
||||
}
|
||||
}
|
||||
|
||||
/* Run registered plugin service callback for the given svc ID */
|
||||
svc_cmd_t plugin_svc_enabled(svc_t *svc, int event, void *arg)
|
||||
{
|
||||
plugin_t *p;
|
||||
|
||||
/* Find matching plugin, pick first matching fd */
|
||||
PLUGIN_ITERATOR(p) {
|
||||
if (p->svc.id == svc_id(svc))
|
||||
return p->svc.cb(svc, event, arg);
|
||||
}
|
||||
|
||||
/* Unknown service, default to start (since it's in finit.conf) */
|
||||
return SVC_START;
|
||||
}
|
||||
|
||||
/* Generic libev I/O callback, looks up correct plugin and calls its callback */
|
||||
static void generic_io_cb(int fd, int events)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user