[SCM] Socket Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Tue Aug 23 14:28:42 UTC 2016
The branch, master has been updated
via f43d383 swrap: remove ununsed members from struct swrap.
via 17cfdc6 swrap: Add test case to validate oldfd = newfd case in dup2()
via 04dacf2 swrap: Treat the case of fd == newfd correctly in dup2()
from 3eee8df swrap: Delay addition of child socket_info_fd into socket_info list
https://git.samba.org/?p=socket_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit f43d3835451a5271c4e5ec22f321a8120b40d1df
Author: Michael Adam <obnox at samba.org>
Date: Fri Aug 19 13:34:50 2016 +0200
swrap: remove ununsed members from struct swrap.
These were used in removed swrap_init().
Pair-Programmed-With: Anoop C S <anoopcs at redhat.com>
Signed-off-by: Michael Adam <obnox at samba.org>
Signed-off-by: Anoop C S <anoopcs at redhat.com>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 17cfdc6a6568f0dbc34d863ad2d80acaed15a6ad
Author: Anoop C S <anoopcs at redhat.com>
Date: Mon Aug 22 19:37:47 2016 +0530
swrap: Add test case to validate oldfd = newfd case in dup2()
Signed-off-by: Anoop C S <anoopcs at redhat.com>
Reviewed-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 04dacf2d2e764eb9fd0791642893b4e1bc199ef0
Author: Michael Adam <obnox at samba.org>
Date: Tue Aug 16 10:59:40 2016 +0200
swrap: Treat the case of fd == newfd correctly in dup2()
Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
Signed-off-by: Michael Adam <obnox at samba.org>
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
-----------------------------------------------------------------------
Summary of changes:
src/socket_wrapper.c | 15 ++++++++++-----
tests/CMakeLists.txt | 1 +
tests/test_tcp_dup2.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 5 deletions(-)
create mode 100644 tests/test_tcp_dup2.c
Changeset truncated at 500 lines:
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 00518c1..6c4ae3b 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -413,11 +413,6 @@ struct swrap {
void *libc_handle;
void *libsocket_handle;
- bool initialised;
- bool enabled;
-
- char *socket_dir;
-
struct swrap_libc_fns fns;
};
@@ -5186,6 +5181,16 @@ static int swrap_dup2(int fd, int newfd)
return libc_dup2(fd, newfd);
}
+ if (fd == newfd) {
+ /*
+ * According to the manpage:
+ *
+ * "If oldfd is a valid file descriptor, and newfd has the same
+ * value as oldfd, then dup2() does nothing, and returns newfd."
+ */
+ return newfd;
+ }
+
if (find_socket_info(newfd)) {
/* dup2() does an implicit close of newfd, which we
* need to emulate */
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index aecf6b8..9b5c4bf 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,6 +21,7 @@ target_link_libraries(${TORTURE_LIBRARY}
set(SWRAP_TESTS
test_ioctl
test_tcp_listen
+ test_tcp_dup2
test_echo_tcp_socket
test_echo_tcp_connect
test_echo_tcp_bind
diff --git a/tests/test_tcp_dup2.c b/tests/test_tcp_dup2.c
new file mode 100644
index 0000000..fd6adc2
--- /dev/null
+++ b/tests/test_tcp_dup2.c
@@ -0,0 +1,50 @@
+#include "torture.h"
+
+#include <cmocka.h>
+#include <unistd.h>
+
+static int setup(void **state)
+{
+ torture_setup_socket_dir(state);
+
+ return 0;
+}
+
+static int teardown(void **state)
+{
+ torture_teardown_socket_dir(state);
+
+ return 0;
+}
+
+static void test_dup2_existing_open_fd(void **state)
+{
+ int s, dup_s;
+
+ (void) state; /* unused */
+
+ s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ assert_int_not_equal(s, -1);
+
+ /*
+ * Here we try to duplicate the existing socket fd to itself
+ * and as per man page for dup2() it must return the already
+ * open fd without any failure.
+ */
+ dup_s = dup2(s, s);
+ assert_int_equal(dup_s, s);
+
+ close(s);
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest tcp_dup2_tests[] = {
+ cmocka_unit_test(test_dup2_existing_open_fd),
+ };
+
+ rc = cmocka_run_group_tests(tcp_dup2_tests, setup, teardown);
+
+ return rc;
+}
--
Socket Wrapper Repository
More information about the samba-cvs
mailing list