Fix #302: add support for running scripts at shutdown

This change adds support for running hook scripts at two new hook points
during the shutdown process:

 - HOOK_SVC_DN: after all services and non-reserved processes have been
   killed (and collected)
 - HOOK_SYS_DN: after all file systems have been unmounted, *just prior*
   to Finit calling reboot() to shut down or reboot the system

See doc/plugins.md for details and an example.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-11-07 07:01:21 +01:00
parent 5f74adad06
commit d810ac00bc
5 changed files with 74 additions and 11 deletions
+29
View File
@@ -195,11 +195,40 @@ int plugin_exists(hook_point_t no)
return 0;
}
#ifdef HAVE_HOOK_SCRIPTS_PLUGIN
#define CHOOSE(x, y) y
static const char *hscript_paths[] = HOOK_TYPES;
#undef CHOOSE
void plugin_script_run(hook_point_t no)
{
char path[CMD_SIZE] = "";
strlcat(path, PLUGIN_HOOK_SCRIPTS_PATH, sizeof(path));
strlcat(path, hscript_paths[no] + 4, sizeof(path));
run_parts(path, NULL);
}
#else
void plugin_script_run(hook_point_t no)
{
(void)no;
}
#endif
/* Some hooks are called with a fixed argument */
void plugin_run_hook(hook_point_t no, void *arg)
{
plugin_t *p, *tmp;
if (!cond_is_available()) {
#ifdef HAVE_HOOK_SCRIPTS_PLUGIN
warnx("conditions not available, calling script script based hooks only!");
plugin_script_run(no);
#endif
return;
}
PLUGIN_ITERATOR(p, tmp) {
if (p->hook[no].cb) {
dbg("Calling %s hook n:o %d (arg: %p) ...", basename(p->name), no, arg ?: "NIL");