]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: allow clearing cloexec bit
authorEric Blake <eblake@redhat.com>
Sat, 26 Mar 2011 11:19:28 +0000 (05:19 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 28 Mar 2011 16:26:32 +0000 (10:26 -0600)
* src/util/util.h (virSetInherit): New prototype.
* src/util/util.c (virSetCloseExec): Move guts...
(virSetInherit): ...to new function, and allow clearing.
* src/libvirt_private.syms (util.h): Export it.

src/libvirt_private.syms
src/util/util.c
src/util/util.h

index 11fd5c7d0215d010f8703cbb95a94dac1881db52..557184268fb72b987761934bb6e953a4213b2963 100644 (file)
@@ -913,6 +913,7 @@ virRun;
 virRunWithHook;
 virSetBlocking;
 virSetCloseExec;
+virSetInherit;
 virSetNonBlock;
 virSetUIDGID;
 virSkipSpaces;
index 4301b0092daded46846be6fda6dab6297dc7407b..7c7da225542080b6cb34e4847bbfc48d39fc4b4c 100644 (file)
@@ -273,13 +273,21 @@ int virSetNonBlock(int fd) {
 }
 
 
+int virSetCloseExec(int fd)
+{
+    return virSetInherit(fd, false);
+}
+
 #ifndef WIN32
 
-int virSetCloseExec(int fd) {
+int virSetInherit(int fd, bool inherit) {
     int flags;
     if ((flags = fcntl(fd, F_GETFD)) < 0)
         return -1;
-    flags |= FD_CLOEXEC;
+    if (inherit)
+        flags &= ~FD_CLOEXEC;
+    else
+        flags |= FD_CLOEXEC;
     if ((fcntl(fd, F_SETFD, flags)) < 0)
         return -1;
     return 0;
@@ -931,7 +939,7 @@ virRunWithHook(const char *const*argv,
 
 #else /* WIN32 */
 
-int virSetCloseExec(int fd ATTRIBUTE_UNUSED)
+int virSetInherit(int fd ATTRIBUTE_UNUSED, bool inherit ATTRIBUTE_UNUSED)
 {
     return -1;
 }
index c313023e3bbd54071ec72d3613f5f5649d1a9aca..0f11f8fb09d1b37deb092d89615ca8013d7c3a04 100644 (file)
@@ -51,6 +51,7 @@ enum {
 
 int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
 int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
+int virSetInherit(int fd, bool inherit) ATTRIBUTE_RETURN_CHECK;
 int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
 
 /* This will execute in the context of the first child