mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00:00
runparts: fix arg handling and skip backup files
For some specialized forms of runparts, e.g., start-stop scripts in SysV init replacements, there is a need to append an argument. Typically this is 'start' or 'stop'. This functionality has been broken for quite some time, meaning we should consider it being unused by current users of Finit. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
e9f403bceb
commit
f2507d9fd7
2 files changed
+14
-8
No files matched your search
@@ -5,6 +5,7 @@ initctl
|
|||||||
keventd
|
keventd
|
||||||
logit
|
logit
|
||||||
reboot
|
reboot
|
||||||
|
runparts
|
||||||
sulogin
|
sulogin
|
||||||
watchdogd
|
watchdogd
|
||||||
Makefile
|
Makefile
|
||||||
|
|||||||
+13
-8
@@ -85,30 +85,35 @@ static void run_env(const char *env[])
|
|||||||
|
|
||||||
int run_parts(char *dir, char *cmd, const char *env[], int progress)
|
int run_parts(char *dir, char *cmd, const char *env[], int progress)
|
||||||
{
|
{
|
||||||
struct dirent **e;
|
size_t cmdlen = cmd ? strlen(cmd) : strlen("start");
|
||||||
|
struct dirent **d;
|
||||||
int i, num;
|
int i, num;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
num = scandir(dir, &e, NULL, alphasort);
|
num = scandir(dir, &d, NULL, alphasort);
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
dbg("No files found in %s, skipping ...", dir);
|
dbg("No files found in %s, skipping ...", dir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
const char *name = e[i]->d_name;
|
char path[strlen(dir) + strlen(d[i]->d_name) + 3 + cmdlen];
|
||||||
char path[strlen(dir) + strlen(name) + 2];
|
const char *name = d[i]->d_name;
|
||||||
struct stat st;
|
|
||||||
char *argv[4] = {
|
char *argv[4] = {
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
path,
|
path,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
struct stat st;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
/* skip backup files */
|
||||||
|
if (name[strlen(name) - 1] == '~')
|
||||||
|
continue;
|
||||||
|
|
||||||
/* cannot rely on d_type, not supported on all filesystems */
|
/* cannot rely on d_type, not supported on all filesystems */
|
||||||
paste(path, sizeof(path), dir, name);
|
paste(path, sizeof(path), dir, name);
|
||||||
if (stat(path, &st)) {
|
if (stat(path, &st)) {
|
||||||
@@ -125,12 +130,12 @@ int run_parts(char *dir, char *cmd, const char *env[], int progress)
|
|||||||
/* If the callee didn't supply a run_parts() argument */
|
/* If the callee didn't supply a run_parts() argument */
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
/* Check if S<NUM>service or K<NUM>service notation is used */
|
/* Check if S<NUM>service or K<NUM>service notation is used */
|
||||||
// dbg("Checking if %s is a sysvinit startstop script ...", name);
|
|
||||||
if (name[0] == 'S' && isdigit(name[1]))
|
if (name[0] == 'S' && isdigit(name[1]))
|
||||||
strlcat(path, " start", sizeof(path));
|
strlcat(path, " start", sizeof(path));
|
||||||
else if (name[0] == 'K' && isdigit(name[1]))
|
else if (name[0] == 'K' && isdigit(name[1]))
|
||||||
strlcat(path, " stop", sizeof(path));
|
strlcat(path, " stop", sizeof(path));
|
||||||
} else {
|
} else {
|
||||||
|
strlcat(path, " ", sizeof(path));
|
||||||
strlcat(path, cmd, sizeof(path));
|
strlcat(path, cmd, sizeof(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,8 +170,8 @@ int run_parts(char *dir, char *cmd, const char *env[], int progress)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (num--)
|
while (num--)
|
||||||
free(e[num]);
|
free(d[num]);
|
||||||
free(e);
|
free(d);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user