]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device-monitor: introduce sd_device_monitor_get_events() and _get_timeout() 34139/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 26 Aug 2024 21:23:43 +0000 (06:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Aug 2024 20:35:07 +0000 (05:35 +0900)
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
src/libsystemd/sd-device/device-monitor.c
src/libsystemd/sd-device/test-sd-device-monitor.c
src/systemd/sd-device.h

index 50ef8096db0640ccc86202629086a5ca38d0ac93..a808f00fbf3069c7a74200810d67557067c0813b 100644 (file)
@@ -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;
index 9d598f5ac1712993dc09bdb3fa3e99141e780436..287fb8d9f27658cb6b722c5238d0e2a4b8bc8fb9 100644 (file)
@@ -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;
index e1d65b5bc9860f8889aaed34311d5bbd053d5658..1cdeabbf21e5016999cb4590a73d8815c93b1a8a 100644 (file)
@@ -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);
index c84cc552029abd944e5622341f8745dca0f94867..50dc925c5cea45bd5d04c8a7d3e281b515982819 100644 (file)
@@ -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);