]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
spawn: another cleanups in spawn_and_give_stdout()
authorJaroslav Kysela <perex@perex.cz>
Mon, 17 Nov 2014 22:17:19 +0000 (23:17 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 17 Nov 2014 22:17:19 +0000 (23:17 +0100)
src/spawn.c

index 7236a3366362236fd21625380d75fce30d6bd11c..69fcc7f52c70f103ff8c3bf2fddfe91c32415012 100644 (file)
@@ -340,11 +340,6 @@ spawn_and_give_stdout(const char *prog, char *argv[], int *rd, int redir_stderr)
     close(fd[0]);
     dup2(fd[1], 1);
     close(fd[1]);
-    if (redir_stderr)
-      dup2(spawn_pipe_error.wr, 2);
-
-    for (f = 3; f < maxfd; f++)
-      close(f);
 
     f = open("/dev/null", O_RDWR);
     if(f == -1) {
@@ -354,12 +349,14 @@ spawn_and_give_stdout(const char *prog, char *argv[], int *rd, int redir_stderr)
     }
 
     dup2(f, 0);
-    if (!redir_stderr)
-      dup2(f, 2);
+    dup2(redir_stderr ? spawn_pipe_error.wr : f, 2);
     close(f);
 
     spawn_info("Executing \"%s\"\n", prog);
 
+    for (f = 3; f < maxfd; f++)
+      close(f);
+
     execve(prog, argv, environ);
     spawn_error("pid %d cannot execute %s -- %s\n",
                 getpid(), prog, strerror(errno));