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
+8 -4
View File
@@ -64,10 +64,14 @@ For your convenience a set of *optional* plugins are available:
name of the module to load. Any line starting with the standard UNIX name of the module to load. Any line starting with the standard UNIX
comment character, `#`, or `;`, is skipped. comment character, `#`, or `;`, is skipped.
Modules are loaded when entering runlevel `[2345]` using the `task` Modules are by default loaded in runlevel `S` using the `task` stanza.
stanza. Each module gets a unique `name:modprobe.foo`, and Each module gets a unique `name:modprobe.foo`, and optional`:ID`. The
optional`:ID`. The `:ID` is a globally incremented index, which can runlevel can be changed per file using:
be disabled per file (anywhere) using the following config line:
set runlevel 2345
The `:ID` is a globally incremented index, which can be disabled per
file (anywhere) using the following config line:
set noindex set noindex
+20 -4
View File
@@ -64,9 +64,9 @@
#endif #endif
#define MODPROBE_PATH "/sbin/modprobe" #define MODPROBE_PATH "/sbin/modprobe"
#define SERVICE_LINE \ #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 \ #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) 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; char *modprobe_path;
int num = 0; int num = 0;
char *line; char *line;
char *lvl;
FILE *fp; FILE *fp;
strlcpy(module_path, MODULES_LOAD_PATH "/", sizeof(module_path)); 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); modprobe_path = strdup(MODPROBE_PATH);
if (!modprobe_path) { if (!modprobe_path) {
fail:
warnx("failed allocating memory in modules-load plugin."); warnx("failed allocating memory in modules-load plugin.");
fclose(fp); fclose(fp);
return -1; return -1;
} }
lvl = strdup("S");
if (!lvl) {
free(modprobe_path);
goto fail;
}
while ((line = fparseln(fp, NULL, NULL, NULL, 0))) { while ((line = fparseln(fp, NULL, NULL, NULL, 0))) {
char cmd[CMD_SIZE * 2], *mod, *args, *set; char cmd[CMD_SIZE * 2], *mod, *args, *set;
@@ -124,6 +132,13 @@ static int modules_load(const char *file, int index)
goto next; goto next;
} }
if ((val = fgetval(set, "runlevel", "= \t"))) {
free(lvl);
lvl = val;
free(set);
goto next;
}
if ((val = fgetval(set, "modprobe", "= \t"))) { if ((val = fgetval(set, "modprobe", "= \t"))) {
if (access(val, X_OK)) { if (access(val, X_OK)) {
warn("%s: cannot use %s", module_path, val); warn("%s: cannot use %s", module_path, val);
@@ -148,9 +163,9 @@ static int modules_load(const char *file, int index)
goto next; goto next;
if (!index) 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 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); dbg("task %s", cmd);
service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL); service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL);
@@ -160,6 +175,7 @@ static int modules_load(const char *file, int index)
} }
skip: skip:
free(modprobe_path); free(modprobe_path);
free(lvl);
fclose(fp); fclose(fp);
return num; return num;