plugins/modules-load: change default, load modules in runlevel S

Instead of waiting until runlevel 2, 3, 4, or 5 to load modules with
this plugin, we should load modules as soon as possible, i.e., in
runlevel S.  This also means that Finit will clean up all the tasks
so we don't have to see them in `initctl status`.

To allow users to revert to the old behavior, we add a new setting

    set runlevel 2345

that per modules-load.d/file changes the runlevel for all modprobe
commands.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2022-12-10 13:29:53 +01:00
parent 7108b0e789
commit 19847d2997
2 changed files with 28 additions and 8 deletions
+20 -4
View File
@@ -64,9 +64,9 @@
#endif
#define MODPROBE_PATH "/sbin/modprobe"
#define SERVICE_LINE \
"cgroup.init name:modprobe.%s :%d [2345] %s %s %s -- Kernel module: %s"
"cgroup.init name:modprobe.%s :%d [%s] %s %s %s -- Loading module %s"
#define SERVICE_LINE_NOINDEX \
"cgroup.init name:modprobe.%s [2345] %s %s %s -- Kernel module: %s"
"cgroup.init name:modprobe.%s [%s] %s %s %s -- Loading module %s"
static int modules_load(const char *file, int index)
{
@@ -74,6 +74,7 @@ static int modules_load(const char *file, int index)
char *modprobe_path;
int num = 0;
char *line;
char *lvl;
FILE *fp;
strlcpy(module_path, MODULES_LOAD_PATH "/", sizeof(module_path));
@@ -87,11 +88,18 @@ static int modules_load(const char *file, int index)
modprobe_path = strdup(MODPROBE_PATH);
if (!modprobe_path) {
fail:
warnx("failed allocating memory in modules-load plugin.");
fclose(fp);
return -1;
}
lvl = strdup("S");
if (!lvl) {
free(modprobe_path);
goto fail;
}
while ((line = fparseln(fp, NULL, NULL, NULL, 0))) {
char cmd[CMD_SIZE * 2], *mod, *args, *set;
@@ -124,6 +132,13 @@ static int modules_load(const char *file, int index)
goto next;
}
if ((val = fgetval(set, "runlevel", "= \t"))) {
free(lvl);
lvl = val;
free(set);
goto next;
}
if ((val = fgetval(set, "modprobe", "= \t"))) {
if (access(val, X_OK)) {
warn("%s: cannot use %s", module_path, val);
@@ -148,9 +163,9 @@ static int modules_load(const char *file, int index)
goto next;
if (!index)
snprintf(cmd, sizeof(cmd), SERVICE_LINE_NOINDEX, mod, modprobe_path, mod, args, mod);
snprintf(cmd, sizeof(cmd), SERVICE_LINE_NOINDEX, mod, lvl, modprobe_path, mod, args, mod);
else
snprintf(cmd, sizeof(cmd), SERVICE_LINE, mod, index++, modprobe_path, mod, args, mod);
snprintf(cmd, sizeof(cmd), SERVICE_LINE, mod, index++, lvl, modprobe_path, mod, args, mod);
dbg("task %s", cmd);
service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL);
@@ -160,6 +175,7 @@ static int modules_load(const char *file, int index)
}
skip:
free(modprobe_path);
free(lvl);
fclose(fp);
return num;