mirror of
https://github.com/troglobit/finit.git
synced 2026-11-29 21:08:21 +00:00
plugins: refactor modules-load to read files in lexicographic order
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
7af3461e3c
commit
eca3098c0e
1 file changed
+71
-56
+71
-56
@@ -67,75 +67,90 @@
|
|||||||
#define SERVICE_LINE_NOINDEX \
|
#define SERVICE_LINE_NOINDEX \
|
||||||
"cgroup.init name:modprobe.%s [2345] /sbin/modprobe %s %s -- Kernel module: %s"
|
"cgroup.init name:modprobe.%s [2345] /sbin/modprobe %s %s -- Kernel module: %s"
|
||||||
|
|
||||||
static void load(void *arg)
|
static int load_file(const char *file, int index)
|
||||||
{
|
{
|
||||||
struct dirent *d;
|
char module_path[PATH_MAX];
|
||||||
int counter = 1;
|
char line[256];
|
||||||
|
int num = 0;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
DIR *dir;
|
|
||||||
|
|
||||||
_d("Scanning " MODULES_LOAD_PATH " for config files ...");
|
strlcpy(module_path, MODULES_LOAD_PATH "/", sizeof(module_path));
|
||||||
|
strlcat(module_path, file, sizeof(module_path));
|
||||||
|
|
||||||
dir = opendir(MODULES_LOAD_PATH);
|
fp = fopen(module_path, "r");
|
||||||
if (!dir)
|
if (!fp)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
while ((d = readdir(dir))) {
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
char module_path[PATH_MAX];
|
char cmd[CMD_SIZE], *mod, *args;
|
||||||
int index = counter;
|
|
||||||
char line[256];
|
|
||||||
|
|
||||||
if (d->d_name[strlen(d->d_name) - 1] == '~')
|
chomp(line);
|
||||||
continue; /* skip backup files */
|
|
||||||
|
|
||||||
strlcpy(module_path, MODULES_LOAD_PATH "/", sizeof(module_path));
|
mod = strip_line(line);
|
||||||
strlcat(module_path, d->d_name, sizeof(module_path));
|
if (!mod[0])
|
||||||
|
|
||||||
fp = fopen(module_path, "r");
|
|
||||||
if (!fp)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
while (fgets(line, sizeof(line), fp)) {
|
if (mod[0] == '#' || mod[0] == ';')
|
||||||
char cmd[CMD_SIZE], *mod, *args;
|
continue;
|
||||||
|
|
||||||
chomp(line);
|
if (!strcmp(mod, "set noindex")) {
|
||||||
|
index = 0;
|
||||||
mod = strip_line(line);
|
continue;
|
||||||
if (!mod[0])
|
}
|
||||||
continue;
|
if (!strncmp(mod, "set index", 9)) {
|
||||||
|
mod += 9;
|
||||||
if (mod[0] == '#' || mod[0] == ';')
|
args = strchr(mod, '=');
|
||||||
continue;
|
if (args) /* optional */
|
||||||
|
mod = args + 1;
|
||||||
if (!strcmp(mod, "set noindex")) {
|
index = atoi(mod);
|
||||||
index = 0;
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!strncmp(mod, "set index", 9)) {
|
|
||||||
mod += 9;
|
|
||||||
args = strchr(mod, '=');
|
|
||||||
if (args) /* optional */
|
|
||||||
mod = args + 1;
|
|
||||||
index = atoi(mod);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
mod = strtok_r(mod, " ", &args);
|
|
||||||
if (!mod)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!index)
|
|
||||||
snprintf(cmd, sizeof(cmd), SERVICE_LINE_NOINDEX, mod, mod, args, mod);
|
|
||||||
else
|
|
||||||
snprintf(cmd, sizeof(cmd), SERVICE_LINE, mod, index++, mod, args, mod);
|
|
||||||
service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL);
|
|
||||||
counter++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
mod = strtok_r(mod, " ", &args);
|
||||||
}
|
if (!mod)
|
||||||
|
continue;
|
||||||
|
|
||||||
closedir(dir);
|
if (!index)
|
||||||
|
snprintf(cmd, sizeof(cmd), SERVICE_LINE_NOINDEX, mod, mod, args, mod);
|
||||||
|
else
|
||||||
|
snprintf(cmd, sizeof(cmd), SERVICE_LINE, mod, index++, mod, args, mod);
|
||||||
|
|
||||||
|
service_register(SVC_TYPE_TASK, cmd, global_rlimit, NULL);
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX: check here for .conf only? */
|
||||||
|
static int module_filter(const struct dirent *d)
|
||||||
|
{
|
||||||
|
if (d->d_type == DT_DIR)
|
||||||
|
return 0;
|
||||||
|
if (d->d_name[0] == '.')
|
||||||
|
return 0; /* skip dot files */
|
||||||
|
if (d->d_name[strlen(d->d_name) - 1] == '~')
|
||||||
|
return 0; /* skip backup files */
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void load(void *arg)
|
||||||
|
{
|
||||||
|
struct dirent **dentry;
|
||||||
|
int index = 1;
|
||||||
|
int i, num;
|
||||||
|
|
||||||
|
_d("Scanning " MODULES_LOAD_PATH " for config files ...");
|
||||||
|
num = scandir(MODULES_LOAD_PATH, &dentry, module_filter, alphasort);
|
||||||
|
if (num > 0) {
|
||||||
|
for (i = 0; i < num; i++) {
|
||||||
|
index += load_file(dentry[i]->d_name, index);
|
||||||
|
free(dentry[i]);
|
||||||
|
}
|
||||||
|
free(dentry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static plugin_t plugin = {
|
static plugin_t plugin = {
|
||||||
|
|||||||
Reference in new issue
Block a user