Fix #317: make sure hook scripts don't run twice

Also fixes #316

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-11-23 21:44:31 +01:00
1 parent 67ea42c87b
commit c84ababbd4
1 file changed
+9 -4
+9 -4
View File
@@ -50,7 +50,8 @@
return p; \ return p; \
} }
static char *plugpath = NULL; /* Set by first load. */ static int plugloaded = 0; /* Set while plugins are loaded */
static char *plugpath = NULL; /* Set by first load. */
static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins); static TAILQ_HEAD(plugin_head, plugin) plugins = TAILQ_HEAD_INITIALIZER(plugins);
#ifndef ENABLE_STATIC #ifndef ENABLE_STATIC
@@ -222,8 +223,8 @@ void plugin_run_hook(hook_point_t no, void *arg)
plugin_t *p, *tmp; plugin_t *p, *tmp;
#ifdef HAVE_HOOK_SCRIPTS_PLUGIN #ifdef HAVE_HOOK_SCRIPTS_PLUGIN
if (!cond_is_available()) { if (!cond_is_available() && !plugloaded) {
dbg("conditions not available, calling script script based hooks only!"); dbg("conditions not available, calling script based hooks only!");
plugin_script_run(no); plugin_script_run(no);
} }
#endif #endif
@@ -238,7 +239,7 @@ void plugin_run_hook(hook_point_t no, void *arg)
/* Conditions are stored in /run, so don't try to signal /* Conditions are stored in /run, so don't try to signal
* conditions for any hooks before filesystems have been * conditions for any hooks before filesystems have been
* mounted. */ * mounted. */
if (no >= HOOK_MOUNT_ERROR) if (no >= HOOK_MOUNT_ERROR && no <= HOOK_SHUTDOWN)
cond_set_oneshot(hook_cond[no]); cond_set_oneshot(hook_cond[no]);
service_step_all(SVC_TYPE_RUNTASK); service_step_all(SVC_TYPE_RUNTASK);
@@ -472,6 +473,8 @@ int plugin_init(uev_ctx_t *ctx)
} }
free(paths); free(paths);
} }
plugloaded = 1;
#endif #endif
return init_plugins(ctx); return init_plugins(ctx);
@@ -488,6 +491,8 @@ void plugin_exit(void)
warn("Failed unloading plugin %s: %s", p->name, error ? error : "unknown error"); warn("Failed unloading plugin %s: %s", p->name, error ? error : "unknown error");
} }
} }
plugloaded = 0;
#endif #endif
} }