swrap: Improve dup to add the dup'd fd after the source fd
authorMichael Adam <obnox@samba.org>
Tue, 16 Aug 2016 09:03:27 +0000 (11:03 +0200)
committerAndreas Schneider <asn@samba.org>
Thu, 20 Oct 2016 08:50:29 +0000 (10:50 +0200)
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index 2a88dff6a5d981633fb7995ab4d1afc19aa5c3d3..110d9994b164ee31e31f863f2827774bc8d035be 100644 (file)
@@ -5158,14 +5158,15 @@ int close(int fd)
 static int swrap_dup(int fd)
 {
        struct socket_info *si;
-       struct socket_info_fd *fi;
-
-       si = find_socket_info(fd);
+       struct socket_info_fd *src_fi, *fi;
 
-       if (!si) {
+       src_fi = find_socket_info_fd(fd);
+       if (src_fi == NULL) {
                return libc_dup(fd);
        }
 
+       si = src_fi->si;
+
        fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd));
        if (fi == NULL) {
                errno = ENOMEM;
@@ -5186,7 +5187,7 @@ static int swrap_dup(int fd)
        /* Make sure we don't have an entry for the fd */
        swrap_remove_stale(fi->fd);
 
-       SWRAP_DLIST_ADD(socket_fds, fi);
+       SWRAP_DLIST_ADD_AFTER(socket_fds, fi, src_fi);
        return fi->fd;
 }