From 5ab12505342a896cc0c2bc4ef16c99a62d559c7e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 27 Aug 2024 06:23:43 +0900 Subject: [PATCH] sd-device-monitor: introduce sd_device_monitor_get_events() and _get_timeout() Follow-up for bab889c51e888c1b288fed253c349e979a6cf31a (#33032). Currently, they unconditionally returns EPOLLIN and USEC_INFINITY, respectively. Just for consistency with sd-bus, sd-journal, sd-varlink, and so on. All they have _get_fd(), _get_events(), and _get_timeout(). Closes #34094. --- src/libsystemd/libsystemd.sym | 2 ++ src/libsystemd/sd-device/device-monitor.c | 16 ++++++++++++++++ .../sd-device/test-sd-device-monitor.c | 11 ++++++++++- src/systemd/sd-device.h | 2 ++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 50ef8096db0..a808f00fbf3 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -1048,5 +1048,7 @@ global: sd_varlink_wait; sd_device_monitor_is_running; sd_device_monitor_get_fd; + sd_device_monitor_get_events; + sd_device_monitor_get_timeout; sd_device_monitor_receive; } LIBSYSTEMD_256; diff --git a/src/libsystemd/sd-device/device-monitor.c b/src/libsystemd/sd-device/device-monitor.c index 9d598f5ac17..287fb8d9f27 100644 --- a/src/libsystemd/sd-device/device-monitor.c +++ b/src/libsystemd/sd-device/device-monitor.c @@ -131,6 +131,22 @@ _public_ int sd_device_monitor_get_fd(sd_device_monitor *m) { return m->sock; } +_public_ int sd_device_monitor_get_events(sd_device_monitor *m) { + assert_return(m, -EINVAL); + assert_return(m->sock >= 0, -ESTALE); + + return EPOLLIN; +} + +_public_ int sd_device_monitor_get_timeout(sd_device_monitor *m, uint64_t *ret) { + assert_return(m, -EINVAL); + assert_return(m->sock >= 0, -ESTALE); + + if (ret) + *ret = USEC_INFINITY; + return 0; +} + int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group, int fd) { _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL; _cleanup_close_ int sock = -EBADF; diff --git a/src/libsystemd/sd-device/test-sd-device-monitor.c b/src/libsystemd/sd-device/test-sd-device-monitor.c index e1d65b5bc98..1cdeabbf21e 100644 --- a/src/libsystemd/sd-device/test-sd-device-monitor.c +++ b/src/libsystemd/sd-device/test-sd-device-monitor.c @@ -377,8 +377,17 @@ TEST(sd_device_monitor_receive) { ASSERT_OK(device_monitor_send(monitor_server, &sa, device)); ASSERT_OK(fd = sd_device_monitor_get_fd(monitor_client)); + for (;;) { - r = fd_wait_for_event(fd, POLLIN, 10 * USEC_PER_SEC); + usec_t timeout; + int events; + + ASSERT_OK(events = sd_device_monitor_get_events(monitor_client)); + ASSERT_EQ(events, (int) EPOLLIN); + ASSERT_OK(sd_device_monitor_get_timeout(monitor_client, &timeout)); + ASSERT_EQ(timeout, USEC_INFINITY); + + r = fd_wait_for_event(fd, events, MAX(10 * USEC_PER_SEC, timeout)); if (r == -EINTR) continue; ASSERT_OK_POSITIVE(r); diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h index c84cc552029..50dc925c5ce 100644 --- a/src/systemd/sd-device.h +++ b/src/systemd/sd-device.h @@ -143,6 +143,8 @@ sd_device_monitor *sd_device_monitor_ref(sd_device_monitor *m); sd_device_monitor *sd_device_monitor_unref(sd_device_monitor *m); int sd_device_monitor_get_fd(sd_device_monitor *m); +int sd_device_monitor_get_events(sd_device_monitor *m); +int sd_device_monitor_get_timeout(sd_device_monitor *m, uint64_t *ret); int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size); int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event); int sd_device_monitor_detach_event(sd_device_monitor *m); -- 2.47.3