From: Yu Watanabe Date: Tue, 22 Feb 2022 12:30:18 +0000 (+0900) Subject: test: drop timeout handlers X-Git-Tag: v251-rc1~240^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e37084fc93adb5f2234c5c8d526f699a3b427a0;p=thirdparty%2Fsystemd.git test: drop timeout handlers Fixes file descriptor leak reported in #22576. --- diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index 476dcce85ef..d1d104196a0 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -31,13 +31,6 @@ static bool verbose = true; static int test_fd[2]; static test_callback_recv_t callback_recv; static be32_t xid; -static sd_event_source *test_hangcheck; - -static int test_dhcp_hangcheck(sd_event_source *s, uint64_t usec, void *userdata) { - assert_not_reached(); - - return 0; -} static void test_request_basic(sd_event *e) { int r; @@ -514,19 +507,15 @@ static void test_addr_acq(sd_event *e) { callback_recv = test_addr_acq_recv_discover; - assert_se(sd_event_add_time_relative( - e, &test_hangcheck, - clock_boottime_or_monotonic(), - 2 * USEC_PER_SEC, 0, - test_dhcp_hangcheck, NULL) >= 0); + assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + 2 * USEC_PER_SEC, 0, + NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); res = sd_dhcp_client_start(client); assert_se(IN_SET(res, 0, -EINPROGRESS)); assert_se(sd_event_loop(e) >= 0); - test_hangcheck = sd_event_source_unref(test_hangcheck); - assert_se(sd_dhcp_client_set_callback(client, NULL, NULL) >= 0); assert_se(sd_dhcp_client_stop(client) >= 0); sd_dhcp_client_unref(client); diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index 3b25df7625b..b696db8b9ee 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -981,7 +981,7 @@ static void test_dhcp6_client(void) { assert_se(sd_event_new(&e) >= 0); assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), 2 * USEC_PER_SEC, 0, - NULL, INT_TO_PTR(ETIMEDOUT)) >= 0); + NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); assert_se(sd_dhcp6_client_new(&client) >= 0); assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0); diff --git a/src/libsystemd-network/test-ndisc-ra.c b/src/libsystemd-network/test-ndisc-ra.c index 7b961f47610..83186a97bb6 100644 --- a/src/libsystemd-network/test-ndisc-ra.c +++ b/src/libsystemd-network/test-ndisc-ra.c @@ -51,7 +51,6 @@ static uint8_t advertisement[] = { 0x72, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -static sd_event_source *test_hangcheck; static bool test_stopped; static int test_fd[2]; static sd_event_source *recv_router_advertisement; @@ -101,13 +100,6 @@ static const struct in6_addr test_rdnss = { { { 0x20, 0x01, 0x0d, 0xb8, static const char *test_dnssl[] = { "lab.intra", NULL }; -static int test_rs_hangcheck(sd_event_source *s, uint64_t usec, - void *userdata) { - assert_se(false); - - return 0; -} - static void test_radv_prefix(void) { sd_radv_prefix *p; @@ -341,16 +333,13 @@ static void test_ra(void) { assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0], EPOLLIN, radv_recv, ra) >= 0); - assert_se(sd_event_add_time_relative( - e, &test_hangcheck, clock_boottime_or_monotonic(), - 2 *USEC_PER_SEC, 0, - test_rs_hangcheck, NULL) >= 0); + assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + 2 * USEC_PER_SEC, 0, + NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); assert_se(sd_radv_start(ra) >= 0); - sd_event_loop(e); - - test_hangcheck = sd_event_source_unref(test_hangcheck); + assert_se(sd_event_loop(e) >= 0); ra = sd_radv_unref(ra); assert_se(!ra); diff --git a/src/libsystemd-network/test-ndisc-rs.c b/src/libsystemd-network/test-ndisc-rs.c index 1366b44115a..10915e1d4c5 100644 --- a/src/libsystemd-network/test-ndisc-rs.c +++ b/src/libsystemd-network/test-ndisc-rs.c @@ -22,7 +22,6 @@ static struct ether_addr mac_addr = { }; static bool verbose = false; -static sd_event_source *test_hangcheck; static int test_fd[2]; static sd_ndisc *test_timeout_nd; @@ -166,13 +165,6 @@ static void router_dump(sd_ndisc_router *rt) { } } -static int test_rs_hangcheck(sd_event_source *s, uint64_t usec, - void *userdata) { - assert_se(false); - - return 0; -} - int icmp6_bind_router_solicitation(int ifindex) { assert_se(ifindex == 42); @@ -285,10 +277,9 @@ static void test_rs(void) { assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0); assert_se(sd_ndisc_set_callback(nd, test_callback, e) >= 0); - assert_se(sd_event_add_time_relative( - e, &test_hangcheck, clock_boottime_or_monotonic(), - 30 * USEC_PER_SEC, 0, - test_rs_hangcheck, NULL) >= 0); + assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + 30 * USEC_PER_SEC, 0, + NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); assert_se(sd_ndisc_stop(nd) >= 0); assert_se(sd_ndisc_start(nd) >= 0); @@ -297,9 +288,7 @@ static void test_rs(void) { assert_se(sd_ndisc_start(nd) >= 0); - sd_event_loop(e); - - test_hangcheck = sd_event_source_unref(test_hangcheck); + assert_se(sd_event_loop(e) >= 0); nd = sd_ndisc_unref(nd); assert_se(!nd); @@ -379,16 +368,13 @@ static void test_timeout(void) { assert_se(sd_ndisc_set_ifindex(nd, 42) >= 0); assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0); - assert_se(sd_event_add_time_relative( - e, &test_hangcheck, clock_boottime_or_monotonic(), - 30 * USEC_PER_SEC, 0, - test_rs_hangcheck, NULL) >= 0); + assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + 30 * USEC_PER_SEC, 0, + NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); assert_se(sd_ndisc_start(nd) >= 0); - sd_event_loop(e); - - test_hangcheck = sd_event_source_unref(test_hangcheck); + assert_se(sd_event_loop(e) >= 0); nd = sd_ndisc_unref(nd);