summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Gothe2023-08-28 14:12:01 +0000
committerFelix Fietkau2023-11-27 15:55:12 +0000
commitd852f877920b35f4188dde752e94edb43be596cb (patch)
treea25c5aee4e2619a8b038c9be6b7e11dbbcd75d3f
parent2db836553e8fc318143b38dbc6e12b8625cf5c33 (diff)
service: Fix retriggering of init.d-scripts.
Fix retriggering of init.d-scripts which calls commands dependent on functional STDIN/STDOUT/STDERR. If we just close these file descriptors those commands will not work as expected leading to unwanted consequences. If we instead redirect the file descriptors to /dev/null, we will end up the same end-result and these commands will work as expected. Signed-off-by: Markus Gothe <markus.gothe@genexis.eu> Signed-off-by: Felix Fietkau <nbd@nbd.name> [refactor]
-rw-r--r--service/trigger.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/service/trigger.c b/service/trigger.c
index 4af1474..86cbc0f 100644
--- a/service/trigger.c
+++ b/service/trigger.c
@@ -105,6 +105,7 @@ static void trigger_command_run(struct runqueue *q, struct runqueue_task *t)
pid_t pid;
int n = 0;
int rem;
+ int fd;
pid = fork();
if (pid < 0) {
@@ -117,10 +118,12 @@ static void trigger_command_run(struct runqueue *q, struct runqueue_task *t)
return;
}
- if (debug < 3) {
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
+ if (debug < 3 && (fd = open("/dev/null", O_RDWR)) >= 0) {
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ if (fd > STDERR_FILENO)
+ close(fd);
}
blobmsg_for_each_attr(cur, cmd->data, rem)