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

[libvirt] [PATCHv5 01/13] util: allow clearing cloexec bit



* 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.
---

v5: new patch

 src/libvirt_private.syms |    1 +
 src/util/util.c          |   14 +++++++++++---
 src/util/util.h          |    1 +
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5f58970..93504e5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -933,6 +933,7 @@ virRun;
 virRunWithHook;
 virSetBlocking;
 virSetCloseExec;
+virSetInherit;
 virSetNonBlock;
 virSetUIDGID;
 virSkipSpaces;
diff --git a/src/util/util.c b/src/util/util.c
index 4301b00..7c7da22 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -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;
 }
diff --git a/src/util/util.h b/src/util/util.h
index c313023..0f11f8f 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -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
-- 
1.7.4


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