]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: drop timeout handlers
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Feb 2022 12:30:18 +0000 (21:30 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Feb 2022 12:50:32 +0000 (21:50 +0900)
Fixes file descriptor leak reported in #22576.

src/libsystemd-network/test-dhcp-client.c
src/libsystemd-network/test-dhcp6-client.c
src/libsystemd-network/test-ndisc-ra.c
src/libsystemd-network/test-ndisc-rs.c

index 476dcce85ef2077b5935cd23297d5173b1cf5f43..d1d104196a0d407136485de9e0057824f6a3f628 100644 (file)
@@ -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);
index 3b25df7625b29c84b789f53b7b23e55c90c59a7a..b696db8b9eea5d09b690ea59757d9785d84b8b8a 100644 (file)
@@ -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);
index 7b961f47610c83bdb1532a74fdbe582a8f322925..83186a97bb61079bc619f7ed2b8429863f409e86 100644 (file)
@@ -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);
index 1366b44115ac025919594b769c85813744d009e7..10915e1d4c5c9ad151deeda26e530bde31a33ea6 100644 (file)
@@ -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);