]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: replace udev_monitor by sd_device_monitor
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 8 Oct 2018 13:47:29 +0000 (22:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 16 Oct 2018 18:31:20 +0000 (03:31 +0900)
src/core/device.c
src/core/manager.h

index 80bd2555f1711fbf012bb211403b71c4f596e555..16c1cf19fa626a884298ae7d8f551af5a86379c6 100644 (file)
@@ -9,7 +9,6 @@
 #include "device-private.h"
 #include "device-util.h"
 #include "device.h"
-#include "libudev-private.h"
 #include "log.h"
 #include "parse-util.h"
 #include "path-util.h"
@@ -25,7 +24,7 @@ static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = {
         [DEVICE_PLUGGED] = UNIT_ACTIVE,
 };
 
-static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
+static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *userdata);
 static void device_update_found_one(Device *d, DeviceFound found, DeviceFound mask);
 
 static void device_unset_sysfs(Device *d) {
@@ -472,7 +471,7 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool
         if (dev) {
                 r = sd_device_get_syspath(dev, &sysfs);
                 if (r < 0) {
-                        log_debug_errno(r, "Couldn't get syspath from udev device, ignoring: %m");
+                        log_debug_errno(r, "Couldn't get syspath from device, ignoring: %m");
                         return 0;
                 }
         }
@@ -773,8 +772,7 @@ static int device_following_set(Unit *u, Set **_set) {
 static void device_shutdown(Manager *m) {
         assert(m);
 
-        m->udev_event_source = sd_event_source_unref(m->udev_event_source);
-        m->udev_monitor = udev_monitor_unref(m->udev_monitor);
+        m->device_monitor = sd_device_monitor_unref(m->device_monitor);
         m->devices_by_sysfs = hashmap_free(m->devices_by_sysfs);
 }
 
@@ -785,37 +783,35 @@ static void device_enumerate(Manager *m) {
 
         assert(m);
 
-        if (!m->udev_monitor) {
-                m->udev_monitor = udev_monitor_new_from_netlink(NULL, "udev");
-                if (!m->udev_monitor) {
-                        log_error_errno(errno, "Failed to allocate udev monitor: %m");
+        if (!m->device_monitor) {
+                r = sd_device_monitor_new(&m->device_monitor);
+                if (r < 0) {
+                        log_error_errno(r, "Failed to allocate device monitor: %m");
                         goto fail;
                 }
 
                 /* This will fail if we are unprivileged, but that
                  * should not matter much, as user instances won't run
                  * during boot. */
-                (void) udev_monitor_set_receive_buffer_size(m->udev_monitor, 128*1024*1024);
+                (void) sd_device_monitor_set_receive_buffer_size(m->device_monitor, 128*1024*1024);
 
-                r = udev_monitor_filter_add_match_tag(m->udev_monitor, "systemd");
+                r = sd_device_monitor_filter_add_match_tag(m->device_monitor, "systemd");
                 if (r < 0) {
                         log_error_errno(r, "Failed to add udev tag match: %m");
                         goto fail;
                 }
 
-                r = udev_monitor_enable_receiving(m->udev_monitor);
+                r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
                 if (r < 0) {
-                        log_error_errno(r, "Failed to enable udev event reception: %m");
+                        log_error_errno(r, "Failed to attach event to device monitor: %m");
                         goto fail;
                 }
 
-                r = sd_event_add_io(m->event, &m->udev_event_source, udev_monitor_get_fd(m->udev_monitor), EPOLLIN, device_dispatch_io, m);
+                r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m, "systemd-device-monitor");
                 if (r < 0) {
-                        log_error_errno(r, "Failed to watch udev file descriptor: %m");
+                        log_error_errno(r, "Failed to start device monitor: %m");
                         goto fail;
                 }
-
-                (void) sd_event_source_set_description(m->udev_event_source, "device");
         }
 
         r = sd_device_enumerator_new(&e);
@@ -868,30 +864,13 @@ static void device_propagate_reload_by_sysfs(Manager *m, const char *sysfs) {
         }
 }
 
-static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
-        _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *userdata) {
         Manager *m = userdata;
         const char *action, *sysfs;
         int r;
 
         assert(m);
-
-        if (revents != EPOLLIN) {
-                static RATELIMIT_DEFINE(limit, 10*USEC_PER_SEC, 5);
-
-                if (ratelimit_below(&limit))
-                        log_warning("Failed to get udev event");
-                if (!(revents & EPOLLIN))
-                        return 0;
-        }
-
-        /*
-         * libudev might filter-out devices which pass the bloom
-         * filter, so getting NULL here is not necessarily an error.
-         */
-        r = udev_monitor_receive_sd_device(m->udev_monitor, &dev);
-        if (r < 0)
-                return 0;
+        assert(dev);
 
         r = sd_device_get_syspath(dev, &sysfs);
         if (r < 0) {
index 6e6e251a55b2a4388df3c3f220b92acf4fd75af8..1daa9f23088959c683bdc3df2cd0c9282298e52c 100644 (file)
@@ -4,8 +4,8 @@
 #include <stdbool.h>
 #include <stdio.h>
 
-#include "libudev.h"
 #include "sd-bus.h"
+#include "sd-device.h"
 #include "sd-event.h"
 
 #include "cgroup-util.h"
@@ -220,8 +220,7 @@ struct Manager {
         dual_timestamp timestamps[_MANAGER_TIMESTAMP_MAX];
 
         /* Data specific to the device subsystem */
-        struct udev_monitor* udev_monitor;
-        sd_event_source *udev_event_source;
+        sd_device_monitor *device_monitor;
         Hashmap *devices_by_sysfs;
 
         /* Data specific to the mount subsystem */