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

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

On 12/14/2011 04:19 AM, dongsu.park@profitbricks.com wrote:
From: Dongsu Park <dongsu.park@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.
NACK. gnulib guarantees that F_DUPFD_CLOEXEC works (albeit not atomically), even on systems where it is not implemented natively. Falling back to dup() is worthless, since gnulib already provided the necessary fallbacks as part of its rpl_fcntl. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
dongsu.park@profitbricks.com
-
Eric Blake