]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
exec: Simplify fd handling.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 13 May 2024 21:14:53 +0000 (23:14 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 16 May 2024 23:45:20 +0000 (01:45 +0200)
exec.c

diff --git a/exec.c b/exec.c
index 85dbaf9474aa286add74cd761f09d30dc74ad805..38f445ee20b4151b38d4b4fa296f25d10103e2e2 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -46,29 +46,26 @@ static int para_exec(pid_t *pid, const char *file, char *const *const args, int
        }
        *pid = ret;
        if (!(*pid)) { /* child */
-               if (fds[0] >= 0) {
-                       if (fds[0]) {
-                               close(in[1]);
-                               if (in[0] != STDIN_FILENO)
-                                       dup2(in[0], STDIN_FILENO);
-                       } else
-                               dup2(null, STDIN_FILENO);
+               if (fds[0] == 0)
+                       dup2(null, STDIN_FILENO);
+               else if (fds[0] > 0) {
+                       close(in[1]);
+                       if (in[0] != STDIN_FILENO)
+                               dup2(in[0], STDIN_FILENO);
                }
-               if (fds[1] >= 0) {
-                       if (fds[1]) {
-                               close(out[0]);
-                               if (out[1] != STDOUT_FILENO)
-                                       dup2(out[1], STDOUT_FILENO);
-                       } else
-                               dup2(null, STDOUT_FILENO);
+               if (fds[1] == 0)
+                       dup2(null, STDOUT_FILENO);
+               else if (fds[1] > 0) {
+                       close(out[0]);
+                       if (out[1] != STDOUT_FILENO)
+                               dup2(out[1], STDOUT_FILENO);
                }
-               if (fds[2] >= 0) {
-                       if (fds[2]) {
-                               close(err[0]);
-                               if (err[1] != STDERR_FILENO)
-                                       dup2(err[1], STDERR_FILENO);
-                       } else
-                               dup2(null, STDERR_FILENO);
+               if (fds[2] == 0)
+                       dup2(null, STDERR_FILENO);
+               else if (fds[2] > 0) {
+                       close(err[0]);
+                       if (err[1] != STDERR_FILENO)
+                               dup2(err[1], STDERR_FILENO);
                }
                if (null >= 0)
                        close(null);