rc: sort rc files
This commit is contained in:
parent
d64e99b496
commit
1282a563de
@ -42,21 +42,40 @@ static int rc_load_dir(const char *path, const char *action) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
char script[256];
|
char *filenames = malloc(512 * 16);
|
||||||
|
char *filename;
|
||||||
|
size_t fcap = 16;
|
||||||
|
size_t fcnt = 0;
|
||||||
|
|
||||||
|
|
||||||
// TODO: readdir doesn't guarantee ordering
|
|
||||||
while ((ent = readdir(dir))) {
|
while ((ent = readdir(dir))) {
|
||||||
if (ent->d_name[0] == '.') {
|
if (ent->d_name[0] == '.') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(script, sizeof(script), "%s/%s", path, ent->d_name);
|
if (fcnt == fcap) {
|
||||||
|
fcap += 16;
|
||||||
rc_script_exec(script, "start");
|
filenames = realloc(filenames, 512 * fcap);
|
||||||
|
if (!filenames) {
|
||||||
|
warn("realloc()");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filename = &filenames[512 * fcnt];
|
||||||
|
snprintf(filename, 512, "%s/%s", path, ent->d_name);
|
||||||
|
++fcnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
qsort(filenames, fcnt, 512, (int (*) (const void *, const void *)) strcmp);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < fcnt; ++i) {
|
||||||
|
filename = &filenames[i * 512];
|
||||||
|
if (rc_script_exec(filename, "start") != 0) {
|
||||||
|
warn("rc_script_exec(%s)", filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user