Skip to content

Commit b9c6617

Browse files
committed
librdmacm: Add support for dup
Add preload interception for dup so that duplicating an rsocket file descriptor produces another rsocket fd that refers to the same connection. Signed-off-by: Batsheva Black <bblack@nvidia.com>
1 parent e712a3b commit b9c6617

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

librdmacm/librspreload.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
bind;
99
close;
1010
connect;
11+
dup;
1112
dup2;
1213
fcntl;
1314
fcntl64;

librdmacm/preload.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct socket_calls {
103103
(!defined(RDMA_PRELOAD_HAVE_64) || RDMA_PRELOAD_HAVE_64)
104104
int (*fcntl64)(int socket, int cmd, ... /* arg */);
105105
#endif
106+
int (*dup)(int oldfd);
106107
int (*dup2)(int oldfd, int newfd);
107108
ssize_t (*sendfile)(int out_fd, int in_fd, off_t *offset, size_t count);
108109
#if (!defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS != 64) && \
@@ -441,6 +442,7 @@ static void init_preload(void)
441442
(!defined(RDMA_PRELOAD_HAVE_64) || RDMA_PRELOAD_HAVE_64)
442443
real.fcntl64 = dlsym(RTLD_NEXT, "fcntl64");
443444
#endif
445+
real.dup = dlsym(RTLD_NEXT, "dup");
444446
real.dup2 = dlsym(RTLD_NEXT, "dup2");
445447
real.sendfile = dlsym(RTLD_NEXT, "sendfile");
446448
#if (!defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS != 64) && \
@@ -1243,6 +1245,13 @@ int fcntl64(int socket, int cmd, ... /* arg */)
12431245
}
12441246
#endif
12451247

1248+
int dup(int oldfd)
1249+
{
1250+
int new_fd = fcntl(oldfd, F_DUPFD, 0);
1251+
1252+
return dup2(oldfd, new_fd);
1253+
}
1254+
12461255
/*
12471256
* dup2 is not thread safe
12481257
*/

0 commit comments

Comments
 (0)