mirror of
https://github.com/troglobit/finit.git
synced 2026-10-15 10:29:35 +00:00
Fix #315: add environment variables to hook scripts
All hook scripts are called with at least one environment variable set, FINIT_HOOK_NAME, useful when reusing the same hook script for multiple hook points. It is set to the string name, also used by the path, e.g., hook/net/up. For all hook points from hook/sys/shutdown and later, FINIT_SHUTDOWN is also set, to one of: halt, poweroff, reboot. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
d4ee44e27f
commit
70c2939596
7 files changed
+61
-6
No files matched your search
+24
-2
@@ -42,6 +42,7 @@
|
||||
#include "plugin.h"
|
||||
#include "private.h"
|
||||
#include "service.h"
|
||||
#include "sig.h"
|
||||
|
||||
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd > 0)
|
||||
#define SEARCH_PLUGIN(str) \
|
||||
@@ -203,12 +204,33 @@ static const char *hscript_paths[] = HOOK_TYPES;
|
||||
|
||||
void plugin_script_run(hook_point_t no)
|
||||
{
|
||||
const char *hook_name = hscript_paths[no];
|
||||
const char *env[] = {
|
||||
"FINIT_HOOK_NAME", hook_name,
|
||||
"FINIT_SHUTDOWN", NULL,
|
||||
NULL,
|
||||
};
|
||||
char path[CMD_SIZE] = "";
|
||||
|
||||
strlcat(path, PLUGIN_HOOK_SCRIPTS_PATH, sizeof(path));
|
||||
strlcat(path, hscript_paths[no] + 4, sizeof(path));
|
||||
strlcat(path, hook_name + 4, sizeof(path));
|
||||
|
||||
run_parts(path, NULL, 0);
|
||||
if (no >= HOOK_SHUTDOWN) {
|
||||
switch (halt) {
|
||||
case SHUT_OFF:
|
||||
env[3] = "poweroff";
|
||||
break;
|
||||
case SHUT_HALT:
|
||||
env[3] = "halt";
|
||||
break;
|
||||
case SHUT_REBOOT:
|
||||
env[3] = "reboot";
|
||||
break;
|
||||
}
|
||||
} else
|
||||
env[2] = NULL;
|
||||
|
||||
run_parts(path, NULL, env, 0);
|
||||
}
|
||||
#else
|
||||
void plugin_script_run(hook_point_t no)
|
||||
|
||||
Reference in new issue
Block a user