aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2016-08-16 11:04:12 +0200
committerAndreas Schneider <asn@samba.org>2016-10-20 10:50:33 +0200
commitd3d09e631aa7f9b5ffe88a786ad21e7e51aee909 (patch)
treea11a1e8bcc8bc0a0401e9dd155454c9a469e497e /src
parentebe5f15854866c225febe73c952356873b958305 (diff)
downloadsocket_wrapper-d3d09e631aa7f9b5ffe88a786ad21e7e51aee909.tar.gz
socket_wrapper-d3d09e631aa7f9b5ffe88a786ad21e7e51aee909.tar.xz
socket_wrapper-d3d09e631aa7f9b5ffe88a786ad21e7e51aee909.zip
swrap: Improve dup2 to add the dup'd fd after the source fd
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>
Diffstat (limited to 'src')
-rw-r--r--src/socket_wrapper.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 110d999..730e346 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5203,14 +5203,15 @@ int dup(int fd)
static int swrap_dup2(int fd, int newfd)
{
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_dup2(fd, newfd);
}
+ si = src_fi->si;
+
if (fd == newfd) {
/*
* According to the manpage:
@@ -5247,7 +5248,7 @@ static int swrap_dup2(int fd, int newfd)
/* 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;
}