libxl: Make libxl_exec tolerate foofd<=2
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 18 Mar 2014 17:04:36 +0000 (17:04 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Wed, 19 Mar 2014 13:40:24 +0000 (13:40 +0000)
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>
tools/libxl/libxl_exec.c
tools/libxl/libxl_internal.h

index 4b012dc7ad37db1d26f8f3569d2cf1f9ccf1f2db..478b4c22d1cfb4253963cef49a9f3677533f3559 100644 (file)
@@ -77,11 +77,11 @@ void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd, int stderrfd,
     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);
index 69d2ba8b734c5bd481a676c710ee2975c21ba777..17890ef4312c48791def040000fe9a78c1b3e0f7 100644 (file)
@@ -1418,6 +1418,11 @@ _hidden int libxl__xenstore_child_wait_deprecated(libxl__gc *gc,
  *
  * 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,