[PATCH] Add virSetBlocking() to allow O_NONBLOCK to be toggle on or off

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

 



The virSetNonBlock() API only allows enabling non-blocking
operations. It doesn't allow turning blocking back on. Add
a new API to allow arbitrary toggling.

* src/libvirt_private.syms, src/util/util.h
  src/util/util.c: Add virSetBlocking
---
 src/libvirt_private.syms |    1 +
 src/util/util.c          |   13 ++++++++++---
 src/util/util.h          |    1 +
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 09eb03a..c88d934 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -910,6 +910,7 @@ virRandom;
 virRandomInitialize;
 virRun;
 virRunWithHook;
+virSetBlocking;
 virSetCloseExec;
 virSetNonBlock;
 virSetUIDGID;
diff --git a/src/util/util.c b/src/util/util.c
index f41e117..e573f4a 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -244,16 +244,19 @@ virArgvToString(const char *const *argv)
     return ret;
 }
 
-int virSetNonBlock(int fd) {
+int virSetBlocking(int fd, bool blocking) {
 #ifndef WIN32
     int flags;
     if ((flags = fcntl(fd, F_GETFL)) < 0)
         return -1;
-    flags |= O_NONBLOCK;
+    if (blocking)
+        flags &= ~O_NONBLOCK;
+    else
+        flags |= O_NONBLOCK;
     if ((fcntl(fd, F_SETFL, flags)) < 0)
         return -1;
 #else
-    unsigned long flag = 1;
+    unsigned long flag = blocking ? 0 : 1;
 
     /* This is actually Gnulib's replacement rpl_ioctl function.
      * We can't call ioctlsocket directly in any case.
@@ -264,6 +267,10 @@ int virSetNonBlock(int fd) {
     return 0;
 }
 
+int virSetNonBlock(int fd) {
+    return virSetBlocking(fd, false);
+}
+
 
 #ifndef WIN32
 
diff --git a/src/util/util.h b/src/util/util.h
index 5f6473c..31c3a33 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -49,6 +49,7 @@ enum {
     VIR_EXEC_CLEAR_CAPS = (1 << 2),
 };
 
+int virSetBlocking(int fd, bool blocking) ATTRIBUTE_RETURN_CHECK;
 int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
 int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
 
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]