Make passing 0, 1, or 2 as stdinfd, stdoutfd or stderrfd work
properly.
Also, document the meaning of the fd arguments.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Roger Pau Monne <roger.pau@citrix.com>
CC: Vasiliy Tolstov <v.tolstov@selfip.ru>
Acked-by: Ian Campbell <Ian.Campbell@citrix.com>
if (stderrfd != -1)
dup2(stderrfd, STDERR_FILENO);
- if (stdinfd != -1)
+ if (stdinfd > 2)
close(stdinfd);
- if (stdoutfd != -1 && stdoutfd != stdinfd)
+ if (stdoutfd > 2 && stdoutfd != stdinfd)
close(stdoutfd);
- if (stderrfd != -1 && stderrfd != stdinfd && stderrfd != stdoutfd)
+ if (stderrfd > 2 && stderrfd != stdinfd && stderrfd != stdoutfd)
close(stderrfd);
check_open_fds(arg0);
*
* The last entry of the array always has to be NULL.
*
+ * stdinfd, stdoutfd, stderrfd will be dup2'd onto the corresponding
+ * fd in the child, if they are not -1. The original copy of the
+ * descriptor will be closed in the child (unless it's 0, 1 or 2
+ * ie the source descriptor is itself stdin, stdout or stderr).
+ *
* Logs errors, never returns.
*/
_hidden void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd,