]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1705] Solve problem with duplicate FDs
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 23 Feb 2012 14:47:52 +0000 (15:47 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 23 Feb 2012 14:47:52 +0000 (15:47 +0100)
src/lib/util/io/fd_share.cc

index 9c02a33022ee4803c9ad6fa9ee41a25ddd4b264e..82c629e4387d2a899bbc1f8b6548b24389c7dc8b 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/uio.h>
 #include <errno.h>
 #include <stdlib.h>             // for malloc and free
+#include <unistd.h>
 #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