{
struct socket_info_fd *s = socket_fds;
- SWRAP_LOCK_ALL;
-
while (s != NULL) {
swrap_close(s->fd);
s = socket_fds;
if (swrap.libc.socket_handle) {
dlclose(swrap.libc.socket_handle);
}
-
- SWRAP_UNLOCK_ALL;
}
test_echo_udp_send_recv
test_echo_udp_sendmsg_recvmsg
test_swrap_unit
- test_max_sockets)
+ test_max_sockets
+ test_close_failure)
if (HAVE_STRUCT_MSGHDR_MSG_CONTROL)
set(SWRAP_TESTS ${SWRAP_TESTS} test_sendmsg_recvmsg_fd)
--- /dev/null
+#include "torture.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <cmocka.h>
+#include <unistd.h>
+#include <stdlib.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_close_failure(void **state)
+{
+ int s;
+ int rc;
+
+ (void) state; /* unused */
+ (void) s; /*set but not used */
+
+ s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ assert_int_not_equal(rc, -1);
+
+ /* Do not close the socket here so that destructor
+ * handles it and no hang should be observed.*/
+}
+
+int main(void) {
+ int rc;
+
+ const struct CMUnitTest close_failure_tests[] = {
+ cmocka_unit_test_setup_teardown(test_close_failure,
+ setup, teardown),
+ };
+
+ rc = cmocka_run_group_tests(close_failure_tests, NULL, NULL);
+
+ return rc;
+}