X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=exec.c;h=85dbaf9474aa286add74cd761f09d30dc74ad805;hb=refs%2Fheads%2Fpu;hp=b603809d062ee07724f7a4f25b9629ff227f047d;hpb=29a8e4384c08cb4e295e5b82994e62bf247a0ef7;p=paraslash.git diff --git a/exec.c b/exec.c index b603809d..38f445ee 100644 --- a/exec.c +++ b/exec.c @@ -1,16 +1,10 @@ -/* - * Copyright (C) 2003-2009 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2003 Andre Noll , see file COPYING. */ /** \file exec.c Helper functions for spawning new processes. */ #include -#include #include "para.h" -#include "close_on_fork.h" #include "error.h" #include "fd.h" #include "string.h" @@ -52,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); @@ -119,7 +110,7 @@ err_out: * Exec the given command. * * \param pid Will hold the pid of the created process upon return. - * \param cmdline Holds the command and its arguments, seperated by spaces. + * \param cmdline Holds the command and its arguments, separated by spaces. * \param fds A pointer to a value-result array. * * This function uses fork/exec to create a new process. \a fds must be a @@ -132,7 +123,7 @@ err_out: * - fd[i] > 0: create a pipe and dup i to one end of that pipe. * Upon return, fd[i] contains the file descriptor of the pipe. * - * In any case, all unneeded filedescriptors are closed. + * In any case, all unneeded file descriptors are closed. * * \return Standard. */