[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 1/3] libxl: Make libxl_exec tolerate foofd<=2



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@xxxxxxxxxxxxx>
CC: Roger Pau Monne <roger.pau@xxxxxxxxxx>
CC: Vasiliy Tolstov <v.tolstov@xxxxxxxxx>
CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
---
 tools/libxl/libxl_exec.c     |    6 +++---
 tools/libxl/libxl_internal.h |    4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c
index 4b012dc..478b4c2 100644
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -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);
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 69d2ba8..6efaab8 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1418,6 +1418,10 @@ _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).
+ *
  * Logs errors, never returns.
  */
 _hidden  void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd,
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.