Run all runparts scripts using /bin/sh -c foo

This patch is an attempt to address an issue with runparts scripts found
by Magnus Malm, @magnusmalm.  Any script in:

    runparts /foo/bar.d/

were required to have the #!/bin/sh she-bang, otherwise Finit would not
start them.  He tested with the standard run-parts tool, which had no
such restrictions.

The patch not only makes sure to start scripts using `/bin/sh -c`

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2018-10-18 22:19:51 +02:00
1 parent 1a2f7d162b
commit 9a98bff23f
1 file changed
+15 -18
+15 -18
View File
@@ -449,14 +449,18 @@ int run_parts(char *dir, char *cmd)
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
int j = 0;
pid_t pid = 0;
struct stat st; struct stat st;
char *args[NUM_ARGS]; char path[512];
char *argv[4] = {
"sh",
"-c",
path,
NULL
};
char *name = e[i]->d_name; char *name = e[i]->d_name;
char path[LINE_SIZE]; pid_t pid = 0;
snprintf(path, sizeof(path), "%s/%s", dir, name); snprintf(path, sizeof(path), "%s/%s ", dir, name);
if (stat(path, &st)) { if (stat(path, &st)) {
_d("Failed stat(%s): %s", path, strerror(errno)); _d("Failed stat(%s): %s", path, strerror(errno));
continue; continue;
@@ -467,29 +471,22 @@ int run_parts(char *dir, char *cmd)
continue; continue;
} }
/* Fill in args[], starting with full path to executable */
args[j++] = path;
/* 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 */
_d("Checking if %s is a sysvinit startstop script ...", name); _d("Checking if %s is a sysvinit startstop script ...", name);
if (name[0] == 'S' && isdigit(name[1])) { if (name[0] == 'S' && isdigit(name[1]))
args[j++] = "start"; strlcat(path, "start", sizeof(path));
} else if (name[0] == 'K' && isdigit(name[1])) { else if (name[0] == 'K' && isdigit(name[1]))
args[j++] = "stop"; strlcat(path, "stop", sizeof(path));
}
} else { } else {
args[j++] = cmd; strlcat(path, cmd, sizeof(path));
} }
args[j++] = NULL;
pid = fork(); pid = fork();
if (!pid) { if (!pid) {
_d("Calling %s ...", path);
sig_unblock(); sig_unblock();
execv(path, args); return execvp(_PATH_BSHELL, argv);
exit(0);
} }
complete(path, pid); complete(path, pid);