[libvirt] [PATCH] rpc: retry to call dup() if fcntl with CLOEXEC fails

dongsu.park at profitbricks.com dongsu.park at profitbricks.com
Wed Dec 14 11:19:12 UTC 2011


From: Dongsu Park <dongsu.park at profitbricks.com>

If fcntl with F_DUPFD_CLOEXEC fails, we need to try again to use dup()
to get the fd, instead of giving up right away.

Signed-off-by: Dongsu Park <dongsu.park at profitbricks.com>
Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis at profitbricks.com>
---
 src/rpc/virnetsocket.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index af4fc5e..25c7891 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -778,8 +778,15 @@ int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
 {
     int fd;
 
-    if (cloexec)
+    if (cloexec) {
         fd = fcntl(sock->fd, F_DUPFD_CLOEXEC);
+        /* retry to use dup if fcntl fails */
+        if (fd < 0) {
+            virReportSystemError(errno, "%s",
+                             _("fcntl failed, reverting to dup"));
+            fd = dup(sock->fd);
+        }
+    }
     else
         fd = dup(sock->fd);
     if (fd < 0) {
-- 
1.7.7.2




More information about the libvir-list mailing list