]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: drop priority and description from sd_device_monitor_attach_event() and... 10722/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 Nov 2018 13:50:11 +0000 (22:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 Nov 2018 13:53:00 +0000 (22:53 +0900)
Now we have sd_device_monitor_get_event_soruce(). So, it is not
necessary to include these parameters in the functions for sd_device_monitor.

src/core/device.c
src/libsystemd/sd-device/device-monitor.c
src/libsystemd/sd-device/test-sd-device-monitor.c
src/login/logind.c
src/network/networkd-manager.c
src/rfkill/rfkill.c
src/systemd/sd-device.h
src/udev/udevadm-monitor.c
src/udev/udevadm-trigger.c

index 6c50fd7832b58ec862e41538642100b0a0a91688..8b6126c4cfe8e95e9b0e4fb06421d6fc8e177e17 100644 (file)
@@ -802,13 +802,13 @@ static void device_enumerate(Manager *m) {
                         goto fail;
                 }
 
-                r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
+                r = sd_device_monitor_attach_event(m->device_monitor, m->event);
                 if (r < 0) {
                         log_error_errno(r, "Failed to attach event to device monitor: %m");
                         goto fail;
                 }
 
-                r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m, "systemd-device-monitor");
+                r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m);
                 if (r < 0) {
                         log_error_errno(r, "Failed to start device monitor: %m");
                         goto fail;
index 1ef2974003479d9d7390633c7620f8fda14a182b..da99971b0296fb61ad68409bf6ffe2cee2233a9c 100644 (file)
@@ -37,7 +37,6 @@ struct sd_device_monitor {
 
         sd_event *event;
         sd_event_source *event_source;
-        int64_t event_priority;
         sd_device_monitor_handler_t callback;
         void *userdata;
 };
@@ -200,14 +199,13 @@ static int device_monitor_event_handler(sd_event_source *s, int fd, uint32_t rev
         return 0;
 }
 
-_public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata, const char *description) {
-        _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
+_public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata) {
         int r;
 
         assert_return(m, -EINVAL);
 
         if (!m->event) {
-                r = sd_device_monitor_attach_event(m, NULL, 0);
+                r = sd_device_monitor_attach_event(m, NULL);
                 if (r < 0)
                         return r;
         }
@@ -219,21 +217,11 @@ _public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_han
         m->callback = callback;
         m->userdata = userdata;
 
-        r = sd_event_add_io(m->event, &s, m->sock, EPOLLIN, device_monitor_event_handler, m);
+        r = sd_event_add_io(m->event, &m->event_source, m->sock, EPOLLIN, device_monitor_event_handler, m);
         if (r < 0)
                 return r;
 
-        r = sd_event_source_set_priority(s, m->event_priority);
-        if (r < 0)
-                return r;
-
-        if (description) {
-                r = sd_event_source_set_description(s, description);
-                if (r < 0)
-                        return r;
-        }
-
-        m->event_source = TAKE_PTR(s);
+        (void) sd_event_source_set_description(m->event_source, "sd-device-monitor");
 
         return 0;
 }
@@ -247,7 +235,7 @@ _public_ int sd_device_monitor_detach_event(sd_device_monitor *m) {
         return 0;
 }
 
-_public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event, int64_t priority) {
+_public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event) {
         int r;
 
         assert_return(m, -EINVAL);
@@ -261,8 +249,6 @@ _public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *even
                         return 0;
         }
 
-        m->event_priority = priority;
-
         return 0;
 }
 
index 56cf1af434c18b707ccbd30f2b136524f3779db8..b703bdee2d2856d07a938a6f7cd2b612d39ddc0b 100644 (file)
@@ -39,11 +39,13 @@ static int test_loopback(bool subsystem_filter, bool tag_filter, bool use_bpf) {
         assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
 
         assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
-        assert_se(sd_device_monitor_start(monitor_server, NULL, NULL, NULL) >= 0);
+        assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
+        assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
 
         assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
         assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
-        assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath, "loopback-monitor") >= 0);
+        assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
+        assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
 
         if (subsystem_filter) {
                 assert_se(sd_device_get_subsystem(loopback, &subsystem) >= 0);
@@ -82,12 +84,14 @@ static void test_subsystem_filter(void) {
         assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
 
         assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
-        assert_se(sd_device_monitor_start(monitor_server, NULL, NULL, NULL) >= 0);
+        assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
+        assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
 
         assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
         assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
         assert_se(sd_device_monitor_filter_add_match_subsystem_devtype(monitor_client, subsystem, NULL) >= 0);
-        assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath, "subsystem-filter") >= 0);
+        assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
+        assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
 
         assert_se(sd_device_enumerator_new(&e) >= 0);
         assert_se(sd_device_enumerator_add_match_subsystem(e, subsystem, false) >= 0);
index e7de3c12e4bed8d077e55558978234740c2e2a2a..a1ab9626b53843dd82daf1ddfb04619a0e846768 100644 (file)
@@ -832,14 +832,16 @@ static int manager_connect_udev(Manager *m) {
         if (r < 0)
                 return r;
 
-        r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event, 0);
+        r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event);
         if (r < 0)
                 return r;
 
-        r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m, "logind-seat-monitor");
+        r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m);
         if (r < 0)
                 return r;
 
+        (void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_seat_monitor), "logind-seat-monitor");
+
         r = sd_device_monitor_new(&m->device_monitor);
         if (r < 0)
                 return r;
@@ -856,14 +858,16 @@ static int manager_connect_udev(Manager *m) {
         if (r < 0)
                 return r;
 
-        r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
+        r = sd_device_monitor_attach_event(m->device_monitor, m->event);
         if (r < 0)
                 return r;
 
-        r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m, "logind-device-monitor");
+        r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m);
         if (r < 0)
                 return r;
 
+        (void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_monitor), "logind-device-monitor");
+
         /* Don't watch keys if nobody cares */
         if (!manager_all_buttons_ignored(m)) {
                 r = sd_device_monitor_new(&m->device_button_monitor);
@@ -878,13 +882,15 @@ static int manager_connect_udev(Manager *m) {
                 if (r < 0)
                         return r;
 
-                r = sd_device_monitor_attach_event(m->device_button_monitor, m->event, 0);
+                r = sd_device_monitor_attach_event(m->device_button_monitor, m->event);
                 if (r < 0)
                         return r;
 
-                r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m, "logind-button-monitor");
+                r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m);
                 if (r < 0)
                         return r;
+
+                (void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_button_monitor), "logind-button-monitor");
         }
 
         /* Don't bother watching VCSA devices, if nobody cares */
@@ -898,13 +904,15 @@ static int manager_connect_udev(Manager *m) {
                 if (r < 0)
                         return r;
 
-                r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event, 0);
+                r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event);
                 if (r < 0)
                         return r;
 
-                r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m, "logind-vcsa-monitor");
+                r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m);
                 if (r < 0)
                         return r;
+
+                (void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_vcsa_monitor), "logind-vcsa-monitor");
         }
 
         return 0;
index 69861a680ebddf68c13291a5f803d8dd36619edb..2b5fc3a50bdc64a8b576a55253f6937d4cd0573f 100644 (file)
@@ -240,11 +240,11 @@ static int manager_connect_udev(Manager *m) {
         if (r < 0)
                 return log_error_errno(r, "Could not add device monitor filter: %m");
 
-        r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
+        r = sd_device_monitor_attach_event(m->device_monitor, m->event);
         if (r < 0)
                 return log_error_errno(r, "Failed to attach event to device monitor: %m");
 
-        r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m, "networkd-device-monitor");
+        r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m);
         if (r < 0)
                 return log_error_errno(r, "Failed to start device monitor: %m");
 
index 9e7d201addf21490f73ec0d6233523810b210c6b..47181bfc168bb4690a27f2f1ae7d615a25f36f8b 100644 (file)
@@ -138,11 +138,11 @@ static int wait_for_initialized(
         if (r < 0)
                 return log_error_errno(r, "Failed to add rfkill device match to monitor: %m");
 
-        r = sd_device_monitor_attach_event(monitor, event, 0);
+        r = sd_device_monitor_attach_event(monitor, event);
         if (r < 0)
                 return log_error_errno(r, "Failed to attach event to device monitor: %m");
 
-        r = sd_device_monitor_start(monitor, device_monitor_handler, &data, "rfkill-device-monitor");
+        r = sd_device_monitor_start(monitor, device_monitor_handler, &data);
         if (r < 0)
                 return log_error_errno(r, "Failed to start device monitor: %m");
 
index 4793e29237c91a93cef9ba55895735a5d4f8c4bf..3c5c88c56bdfddd40c061a00b3a8f92ec751f6f6 100644 (file)
@@ -103,11 +103,11 @@ 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_set_receive_buffer_size(sd_device_monitor *m, size_t size);
-int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event, int64_t priority);
+int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event);
 int sd_device_monitor_detach_event(sd_device_monitor *m);
 sd_event *sd_device_monitor_get_event(sd_device_monitor *m);
 sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m);
-int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata, const char *description);
+int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata);
 int sd_device_monitor_stop(sd_device_monitor *m);
 
 int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor *m, const char *subsystem, const char *devtype);
index ae8e06111e50af15773dae10ebeac8ae8ea389d5..f7737d079089db6f347c4f2bf51d6856b7db25a7 100644 (file)
@@ -67,7 +67,7 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_
 
         (void) sd_device_monitor_set_receive_buffer_size(monitor, 128*1024*1024);
 
-        r = sd_device_monitor_attach_event(monitor, event, 0);
+        r = sd_device_monitor_attach_event(monitor, event);
         if (r < 0)
                 return log_error_errno(r, "Failed to attach event: %m");
 
@@ -84,10 +84,13 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_
                         return log_error_errno(r, "Failed to apply tag filter '%s': %m", tag);
         }
 
-        r = sd_device_monitor_start(monitor, device_monitor_handler, INT_TO_PTR(sender), sender == MONITOR_GROUP_UDEV ? "device-monitor-udev" : "device-monitor-kernel");
+        r = sd_device_monitor_start(monitor, device_monitor_handler, INT_TO_PTR(sender));
         if (r < 0)
                 return log_error_errno(r, "Failed to start device monitor: %m");
 
+        (void) sd_event_source_set_description(sd_device_monitor_get_event_source(monitor),
+                                               sender == MONITOR_GROUP_UDEV ? "device-monitor-udev" : "device-monitor-kernel");
+
         *ret = TAKE_PTR(monitor);
         return 0;
 }
index 185fe29be02a65ac3c825525d6928c9f199ff416..38035b5c92f20635ebf9d44a6856aac637bc4ba5 100644 (file)
@@ -305,11 +305,11 @@ int trigger_main(int argc, char *argv[], void *userdata) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to create device monitor object: %m");
 
-                r = sd_device_monitor_attach_event(m, event, 0);
+                r = sd_device_monitor_attach_event(m, event);
                 if (r < 0)
                         return log_error_errno(r, "Failed to attach event to device monitor: %m");
 
-                r = sd_device_monitor_start(m, device_monitor_handler, settle_set, "udevadm-trigger-device-monitor");
+                r = sd_device_monitor_start(m, device_monitor_handler, settle_set);
                 if (r < 0)
                         return log_error_errno(r, "Failed to start device monitor: %m");
         }