From: Michal 'vorner' Vaner Date: Thu, 23 Feb 2012 14:47:52 +0000 (+0100) Subject: [1705] Solve problem with duplicate FDs X-Git-Tag: trac2351_base~226^2~116^2~179^2^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ca1f0da6b1e7dc488e5ff57b9ef041f4322ab67;p=thirdparty%2Fkea.git [1705] Solve problem with duplicate FDs --- diff --git a/src/lib/util/io/fd_share.cc b/src/lib/util/io/fd_share.cc index 9c02a33022..82c629e438 100644 --- a/src/lib/util/io/fd_share.cc +++ b/src/lib/util/io/fd_share.cc @@ -20,6 +20,7 @@ #include #include #include // for malloc and free +#include #include "fd_share.h" namespace isc { @@ -106,7 +107,12 @@ recv_fd(const int sock) { std::memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); } free(msghdr.msg_control); - return (fd); + // It is strange, but the call can return the same file descriptor as + // one returned previously, even if that one is not closed yet. So, + // we just re-number every one we get, so they are unique. + int new_fd(dup(fd)); + close(fd); + return (new_fd); } int