summaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-12-01 10:28:52 +0100
committerFelix Fietkau <nbd@openwrt.org>2013-12-01 10:28:52 +0100
commitfba9c88b995957b8109889f4747c7fe942fd5812 (patch)
tree67c89c8f33744a71354804a419b5bfc5f6bba3d8 /main.c
parent5a195e18041067536566e1a4083c91b88fde63e8 (diff)
netifd: fix process stdin/stdout/stderr when the pipe fds overlap with standard fds
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/main.c b/main.c
index 92c6f49..d8cb17f 100644
--- a/main.c
+++ b/main.c
@@ -143,6 +143,8 @@ netifd_start_process(const char **argv, char **env, struct netifd_process *proc)
goto error;
if (!pid) {
+ int i;
+
if (env) {
while (*env) {
putenv(*env);
@@ -152,12 +154,17 @@ netifd_start_process(const char **argv, char **env, struct netifd_process *proc)
if (proc->dir_fd >= 0)
fchdir(proc->dir_fd);
- dup2(pfds[1], 0);
- dup2(pfds[1], 1);
- dup2(pfds[1], 2);
-
close(pfds[0]);
- close(pfds[1]);
+
+ for (i = 0; i <= 2; i++) {
+ if (pfds[1] == i)
+ continue;
+
+ dup2(pfds[1], i);
+ }
+
+ if (pfds[1] > 2)
+ close(pfds[1]);
execvp(argv[0], (char **) argv);
exit(127);