From: Dongsu Park <dongsu.park(a)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(a)profitbricks.com>
Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis(a)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