From 4f209af7da0edee6b54c23b702354b35510e35e7 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 22 Aug 2018 14:53:51 +0900 Subject: [PATCH] logind: replace udev_device by sd_device --- src/login/logind-acl.c | 41 +++++--------- src/login/logind-acl.h | 8 +-- src/login/logind-core.c | 101 ++++++++++++++++++---------------- src/login/logind-dbus.c | 44 ++++++++------- src/login/logind-seat.c | 3 +- src/login/logind-session-device.c | 82 ++++++++++++---------------- src/login/logind.c | 110 ++++++++++++++++---------------------- src/login/logind.h | 6 +-- 8 files changed, 177 insertions(+), 218 deletions(-) diff --git a/src/login/logind-acl.c b/src/login/logind-acl.c index cafeb88..94b33ae 100644 --- a/src/login/logind-acl.c +++ b/src/login/logind-acl.c @@ -3,8 +3,11 @@ #include #include +#include "sd-device.h" + #include "acl-util.h" #include "alloc-util.h" +#include "device-enumerator-private.h" #include "dirent-util.h" #include "escape.h" #include "fd-util.h" @@ -12,7 +15,6 @@ #include "logind-acl.h" #include "set.h" #include "string-util.h" -#include "udev-util.h" #include "util.h" static int flush_acl(acl_t acl) { @@ -157,30 +159,27 @@ finish: return r; } -int devnode_acl_all(struct udev *udev, - const char *seat, +int devnode_acl_all(const char *seat, bool flush, bool del, uid_t old_uid, bool add, uid_t new_uid) { - _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; - struct udev_list_entry *item = NULL, *first = NULL; + _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_set_free_free_ Set *nodes = NULL; _cleanup_closedir_ DIR *dir = NULL; struct dirent *dent; + sd_device *d; Iterator i; char *n; int r; - assert(udev); - nodes = set_new(&path_hash_ops); if (!nodes) return -ENOMEM; - e = udev_enumerate_new(udev); - if (!e) - return -ENOMEM; + r = sd_device_enumerator_new(&e); + if (r < 0) + return r; if (isempty(seat)) seat = "seat0"; @@ -190,37 +189,25 @@ int devnode_acl_all(struct udev *udev, * could add the seat name as second match tag, but this would * be hardly optimizable in libudev, and hence checking the * second tag manually in our loop is a good solution. */ - r = udev_enumerate_add_match_tag(e, "uaccess"); + r = sd_device_enumerator_add_match_tag(e, "uaccess"); if (r < 0) return r; - r = udev_enumerate_add_match_is_initialized(e); + r = device_enumerator_scan_devices(e); if (r < 0) return r; - r = udev_enumerate_scan_devices(e); - if (r < 0) - return r; - - first = udev_enumerate_get_list_entry(e); - udev_list_entry_foreach(item, first) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { const char *node, *sn; - d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item)); - if (!d) - return -ENOMEM; - - sn = udev_device_get_property_value(d, "ID_SEAT"); - if (isempty(sn)) + if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn)) sn = "seat0"; if (!streq(seat, sn)) continue; - node = udev_device_get_devnode(d); /* In case people mistag devices with nodes, we need to ignore this */ - if (!node) + if (sd_device_get_devname(d, &node) < 0) continue; n = strdup(node); diff --git a/src/login/logind-acl.h b/src/login/logind-acl.h index 7970067..00e286d 100644 --- a/src/login/logind-acl.h +++ b/src/login/logind-acl.h @@ -4,8 +4,6 @@ #include #include -#include "libudev.h" - #if HAVE_ACL int devnode_acl(const char *path, @@ -13,8 +11,7 @@ int devnode_acl(const char *path, bool del, uid_t old_uid, bool add, uid_t new_uid); -int devnode_acl_all(struct udev *udev, - const char *seat, +int devnode_acl_all(const char *seat, bool flush, bool del, uid_t old_uid, bool add, uid_t new_uid); @@ -27,8 +24,7 @@ static inline int devnode_acl(const char *path, return 0; } -static inline int devnode_acl_all(struct udev *udev, - const char *seat, +static inline int devnode_acl_all(const char *seat, bool flush, bool del, uid_t old_uid, bool add, uid_t new_uid) { diff --git a/src/login/logind-core.c b/src/login/logind-core.c index ad7f9ae..5fc4f29 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -6,18 +6,20 @@ #include #include +#include "sd-device.h" + #include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-util.h" #include "conf-parser.h" +#include "device-enumerator-private.h" #include "fd-util.h" #include "logind.h" #include "parse-util.h" #include "process-util.h" #include "strv.h" #include "terminal-util.h" -#include "udev-util.h" #include "user-util.h" void manager_reset_config(Manager *m) { @@ -215,15 +217,22 @@ int manager_add_button(Manager *m, const char *name, Button **_button) { return 0; } -int manager_process_seat_device(Manager *m, struct udev_device *d) { +int manager_process_seat_device(Manager *m, sd_device *d) { + const char *action = NULL; Device *device; int r; assert(m); - if (streq_ptr(udev_device_get_action(d), "remove")) { + (void) sd_device_get_property_value(d, "ACTION", &action); + if (streq_ptr(action, "remove")) { + const char *syspath; + + r = sd_device_get_syspath(d, &syspath); + if (r < 0) + return 0; - device = hashmap_get(m->devices, udev_device_get_syspath(d)); + device = hashmap_get(m->devices, syspath); if (!device) return 0; @@ -231,12 +240,11 @@ int manager_process_seat_device(Manager *m, struct udev_device *d) { device_free(device); } else { - const char *sn; - Seat *seat = NULL; + const char *sn, *syspath; bool master; + Seat *seat; - sn = udev_device_get_property_value(d, "ID_SEAT"); - if (isempty(sn)) + if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn)) sn = "seat0"; if (!seat_name_is_valid(sn)) { @@ -245,13 +253,17 @@ int manager_process_seat_device(Manager *m, struct udev_device *d) { } seat = hashmap_get(m->seats, sn); - master = udev_device_has_tag(d, "master-of-seat"); + master = sd_device_has_tag(d, "master-of-seat") > 0; /* Ignore non-master devices for unknown seats */ if (!master && !seat) return 0; - r = manager_add_device(m, udev_device_get_syspath(d), master, &device); + r = sd_device_get_syspath(d, &syspath); + if (r < 0) + return r; + + r = manager_add_device(m, syspath, master, &device); if (r < 0) return r; @@ -272,30 +284,34 @@ int manager_process_seat_device(Manager *m, struct udev_device *d) { return 0; } -int manager_process_button_device(Manager *m, struct udev_device *d) { +int manager_process_button_device(Manager *m, sd_device *d) { + const char *action = NULL, *sysname; Button *b; - int r; assert(m); - if (streq_ptr(udev_device_get_action(d), "remove")) { + r = sd_device_get_sysname(d, &sysname); + if (r < 0) + return r; + + (void) sd_device_get_property_value(d, "ACTION", &action); + if (streq_ptr(action, "remove")) { - b = hashmap_get(m->buttons, udev_device_get_sysname(d)); + b = hashmap_get(m->buttons, sysname); if (!b) return 0; button_free(b); } else { - const char *sn; + const char *sn = NULL; - r = manager_add_button(m, udev_device_get_sysname(d), &b); + r = manager_add_button(m, sysname, &b); if (r < 0) return r; - sn = udev_device_get_property_value(d, "ID_SEAT"); - if (isempty(sn)) + if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn)) sn = "seat0"; button_set_seat(b, sn); @@ -539,46 +555,41 @@ static bool manager_is_docked(Manager *m) { } static int manager_count_external_displays(Manager *m) { - _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; - struct udev_list_entry *item = NULL, *first = NULL; - int r; - int n = 0; + _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; + sd_device *d; + int r, n = 0; - e = udev_enumerate_new(m->udev); - if (!e) - return -ENOMEM; + r = sd_device_enumerator_new(&e); + if (r < 0) + return r; - r = udev_enumerate_add_match_subsystem(e, "drm"); + r = sd_device_enumerator_allow_uninitialized(e); if (r < 0) return r; - r = udev_enumerate_scan_devices(e); + r = sd_device_enumerator_add_match_subsystem(e, "drm", true); if (r < 0) return r; - first = udev_enumerate_get_list_entry(e); - udev_list_entry_foreach(item, first) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; - struct udev_device *p; - const char *status, *enabled, *dash, *nn, *i; - bool external = false; + r = device_enumerator_scan_devices(e); + if (r < 0) + return r; - d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item)); - if (!d) - return -ENOMEM; + FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { + sd_device *p; + const char *status, *enabled, *dash, *nn, *i, *subsys; + bool external = false; - p = udev_device_get_parent(d); - if (!p) + if (sd_device_get_parent(d, &p) < 0) continue; /* If the parent shares the same subsystem as the * device we are looking at then it is a connector, * which is what we are interested in. */ - if (!streq_ptr(udev_device_get_subsystem(p), "drm")) + if (sd_device_get_subsystem(p, &subsys) < 0 || !streq(subsys, "drm")) continue; - nn = udev_device_get_sysname(d); - if (!nn) + if (sd_device_get_sysname(d, &nn) < 0) continue; /* Ignore internal displays: the type is encoded in @@ -605,16 +616,12 @@ static int manager_count_external_displays(Manager *m) { continue; /* Ignore ports that are not enabled */ - enabled = udev_device_get_sysattr_value(d, "enabled"); - if (!enabled) - continue; - if (!streq_ptr(enabled, "enabled")) + if (sd_device_get_sysattr_value(d, "enabled", &enabled) < 0 || !streq(enabled, "enabled")) continue; /* We count any connector which is not explicitly * "disconnected" as connected. */ - status = udev_device_get_sysattr_value(d, "status"); - if (!streq_ptr(status, "disconnected")) + if (sd_device_get_sysattr_value(d, "status", &status) < 0 || !streq(status, "disconnected")) n++; } diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 38e36f2..47cf62c 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -5,6 +5,7 @@ #include #include +#include "sd-device.h" #include "sd-messages.h" #include "alloc-util.h" @@ -13,6 +14,7 @@ #include "bus-error.h" #include "bus-unit-util.h" #include "bus-util.h" +#include "device-enumerator-private.h" #include "dirent-util.h" #include "efivars.h" #include "escape.h" @@ -30,7 +32,6 @@ #include "special.h" #include "strv.h" #include "terminal-util.h" -#include "udev-util.h" #include "unit-name.h" #include "user-util.h" #include "utmp-wtmp.h" @@ -1189,33 +1190,37 @@ static int method_set_user_linger(sd_bus_message *message, void *userdata, sd_bu return sd_bus_reply_method_return(message, NULL); } -static int trigger_device(Manager *m, struct udev_device *d) { - _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; - struct udev_list_entry *first, *item; +static int trigger_device(Manager *m, sd_device *d) { + _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; int r; assert(m); - e = udev_enumerate_new(m->udev); - if (!e) - return -ENOMEM; + r = sd_device_enumerator_new(&e); + if (r < 0) + return r; + + r = sd_device_enumerator_allow_uninitialized(e); + if (r < 0) + return r; if (d) { - r = udev_enumerate_add_match_parent(e, d); + r = sd_device_enumerator_add_match_parent(e, d); if (r < 0) return r; } - r = udev_enumerate_scan_devices(e); + r = device_enumerator_scan_devices(e); if (r < 0) return r; - first = udev_enumerate_get_list_entry(e); - udev_list_entry_foreach(item, first) { + FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { _cleanup_free_ char *t = NULL; const char *p; - p = udev_list_entry_get_name(item); + r = sd_device_get_syspath(d, &p); + if (r < 0) + return r; t = strappend(p, "/uevent"); if (!t) @@ -1228,7 +1233,7 @@ static int trigger_device(Manager *m, struct udev_device *d) { } static int attach_device(Manager *m, const char *seat, const char *sysfs) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + _cleanup_(sd_device_unrefp) sd_device *d = NULL; _cleanup_free_ char *rule = NULL, *file = NULL; const char *id_for_seat; int r; @@ -1237,15 +1242,14 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { assert(seat); assert(sysfs); - d = udev_device_new_from_syspath(m->udev, sysfs); - if (!d) - return -ENODEV; + r = sd_device_new_from_syspath(&d, sysfs); + if (r < 0) + return r; - if (!udev_device_has_tag(d, "seat")) + if (sd_device_has_tag(d, "seat") <= 0) return -ENODEV; - id_for_seat = udev_device_get_property_value(d, "ID_FOR_SEAT"); - if (!id_for_seat) + if (sd_device_get_property_value(d, "ID_FOR_SEAT", &id_for_seat) < 0) return -ENODEV; if (asprintf(&file, "/etc/udev/rules.d/72-seat-%s.rules", id_for_seat) < 0) @@ -1254,7 +1258,7 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) { if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) return -ENOMEM; - mkdir_p_label("/etc/udev/rules.d", 0755); + (void) mkdir_p_label("/etc/udev/rules.d", 0755); r = write_string_file_atomic_label(file, rule); if (r < 0) return r; diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 63253db..cca4f90 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -203,8 +203,7 @@ int seat_apply_acls(Seat *s, Session *old_active) { assert(s); - r = devnode_acl_all(s->manager->udev, - s->id, + r = devnode_acl_all(s->id, false, !!old_active, old_active ? old_active->user->uid : 0, !!s->active, s->active ? s->active->user->uid : 0); diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index c2dfe9f..fbba792 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -6,7 +6,7 @@ #include #include -#include "libudev.h" +#include "sd-device.h" #include "alloc-util.h" #include "bus-util.h" @@ -247,13 +247,13 @@ static void session_device_stop(SessionDevice *sd) { sd->active = false; } -static DeviceType detect_device_type(struct udev_device *dev) { +static DeviceType detect_device_type(sd_device *dev) { const char *sysname, *subsystem; - DeviceType type; + DeviceType type = DEVICE_TYPE_UNKNOWN; - sysname = udev_device_get_sysname(dev); - subsystem = udev_device_get_subsystem(dev); - type = DEVICE_TYPE_UNKNOWN; + if (sd_device_get_sysname(dev, &sysname) < 0 || + sd_device_get_subsystem(dev, &subsystem) < 0) + return type; if (streq_ptr(subsystem, "drm")) { if (startswith(sysname, "card")) @@ -267,42 +267,37 @@ static DeviceType detect_device_type(struct udev_device *dev) { } static int session_device_verify(SessionDevice *sd) { - struct udev_device *dev, *p = NULL; - const char *sp, *node; + _cleanup_(sd_device_unrefp) sd_device *p = NULL; + sd_device *dev; + const char *sp = NULL, *node; int r; - dev = udev_device_new_from_devnum(sd->session->manager->udev, 'c', sd->dev); - if (!dev) + if (sd_device_new_from_devnum(&p, 'c', sd->dev) < 0) return -ENODEV; - sp = udev_device_get_syspath(dev); - node = udev_device_get_devnode(dev); - if (!node) { - r = -EINVAL; - goto err_dev; - } + dev = p; + + (void) sd_device_get_syspath(dev, &sp); + if (sd_device_get_devname(dev, &node) < 0) + return -EINVAL; /* detect device type so we can find the correct sysfs parent */ sd->type = detect_device_type(dev); - if (sd->type == DEVICE_TYPE_UNKNOWN) { - r = -ENODEV; - goto err_dev; - } else if (sd->type == DEVICE_TYPE_EVDEV) { + if (sd->type == DEVICE_TYPE_UNKNOWN) + return -ENODEV; + + else if (sd->type == DEVICE_TYPE_EVDEV) { /* for evdev devices we need the parent node as device */ - p = dev; - dev = udev_device_get_parent_with_subsystem_devtype(p, "input", NULL); - if (!dev) { - r = -ENODEV; - goto err_dev; - } - sp = udev_device_get_syspath(dev); - } else if (sd->type != DEVICE_TYPE_DRM) { + if (sd_device_get_parent_with_subsystem_devtype(p, "input", NULL, &dev) < 0) + return -ENODEV; + if (sd_device_get_syspath(dev, &sp) < 0) + return -ENODEV; + + } else if (sd->type != DEVICE_TYPE_DRM) /* Prevent opening unsupported devices. Especially devices of * subsystem "input" must be opened via the evdev node as * we require EVIOCREVOKE. */ - r = -ENODEV; - goto err_dev; - } + return -ENODEV; /* search for an existing seat device and return it if available */ sd->device = hashmap_get(sd->session->manager->devices, sp); @@ -312,31 +307,22 @@ static int session_device_verify(SessionDevice *sd) { * logind-manager handle the new device. */ r = manager_process_seat_device(sd->session->manager, dev); if (r < 0) - goto err_dev; + return r; /* if it's still not available, then the device is invalid */ sd->device = hashmap_get(sd->session->manager->devices, sp); - if (!sd->device) { - r = -ENODEV; - goto err_dev; - } + if (!sd->device) + return -ENODEV; } - if (sd->device->seat != sd->session->seat) { - r = -EPERM; - goto err_dev; - } + if (sd->device->seat != sd->session->seat) + return -EPERM; sd->node = strdup(node); - if (!sd->node) { - r = -ENOMEM; - goto err_dev; - } + if (!sd->node) + return -ENOMEM; - r = 0; -err_dev: - udev_device_unref(p ? : dev); - return r; + return 0; } int session_device_new(Session *s, dev_t dev, bool open_device, SessionDevice **out) { diff --git a/src/login/logind.c b/src/login/logind.c index 52fcee9..c487fbc 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -5,25 +5,26 @@ #include #include -#include "libudev.h" #include "sd-daemon.h" +#include "sd-device.h" #include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-util.h" #include "def.h" +#include "device-enumerator-private.h" #include "dirent-util.h" #include "fd-util.h" #include "format-util.h" #include "fs-util.h" +#include "libudev-private.h" #include "logind.h" #include "parse-util.h" #include "process-util.h" #include "selinux-util.h" #include "signal-util.h" #include "strv.h" -#include "udev-util.h" static Manager* manager_unref(Manager *m); DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref); @@ -56,10 +57,6 @@ static int manager_new(Manager **ret) { if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units) return -ENOMEM; - m->udev = udev_new(); - if (!m->udev) - return -errno; - r = sd_event_default(&m->event); if (r < 0) return r; @@ -139,8 +136,6 @@ static Manager* manager_unref(Manager *m) { udev_monitor_unref(m->udev_vcsa_monitor); udev_monitor_unref(m->udev_button_monitor); - udev_unref(m->udev); - if (m->unlink_nologin) (void) unlink_or_warn("/run/nologin"); @@ -163,8 +158,8 @@ static Manager* manager_unref(Manager *m) { } static int manager_enumerate_devices(Manager *m) { - struct udev_list_entry *item = NULL, *first = NULL; - _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; + _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; + sd_device *d; int r; assert(m); @@ -172,31 +167,21 @@ static int manager_enumerate_devices(Manager *m) { /* Loads devices from udev and creates seats for them as * necessary */ - e = udev_enumerate_new(m->udev); - if (!e) - return -ENOMEM; - - r = udev_enumerate_add_match_tag(e, "master-of-seat"); + r = sd_device_enumerator_new(&e); if (r < 0) return r; - r = udev_enumerate_add_match_is_initialized(e); + r = sd_device_enumerator_add_match_tag(e, "master-of-seat"); if (r < 0) return r; - r = udev_enumerate_scan_devices(e); + r = device_enumerator_scan_devices(e); if (r < 0) return r; - first = udev_enumerate_get_list_entry(e); - udev_list_entry_foreach(item, first) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { int k; - d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item)); - if (!d) - return -ENOMEM; - k = manager_process_seat_device(m, d); if (k < 0) r = k; @@ -206,8 +191,8 @@ static int manager_enumerate_devices(Manager *m) { } static int manager_enumerate_buttons(Manager *m) { - _cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; - struct udev_list_entry *item = NULL, *first = NULL; + _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; + sd_device *d; int r; assert(m); @@ -217,35 +202,25 @@ static int manager_enumerate_buttons(Manager *m) { if (manager_all_buttons_ignored(m)) return 0; - e = udev_enumerate_new(m->udev); - if (!e) - return -ENOMEM; - - r = udev_enumerate_add_match_subsystem(e, "input"); + r = sd_device_enumerator_new(&e); if (r < 0) return r; - r = udev_enumerate_add_match_tag(e, "power-switch"); + r = sd_device_enumerator_add_match_subsystem(e, "input", true); if (r < 0) return r; - r = udev_enumerate_add_match_is_initialized(e); + r = sd_device_enumerator_add_match_tag(e, "power-switch"); if (r < 0) return r; - r = udev_enumerate_scan_devices(e); + r = device_enumerator_scan_devices(e); if (r < 0) return r; - first = udev_enumerate_get_list_entry(e); - udev_list_entry_foreach(item, first) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { int k; - d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item)); - if (!d) - return -ENOMEM; - k = manager_process_button_device(m, d); if (k < 0) r = k; @@ -566,64 +541,69 @@ static int manager_enumerate_inhibitors(Manager *m) { } static int manager_dispatch_seat_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + _cleanup_(sd_device_unrefp) sd_device *d = NULL; Manager *m = userdata; + int r; assert(m); - d = udev_monitor_receive_device(m->udev_seat_monitor); - if (!d) - return -ENOMEM; + r = udev_monitor_receive_sd_device(m->udev_seat_monitor, &d); + if (r < 0) + return r; manager_process_seat_device(m, d); return 0; } static int manager_dispatch_device_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + _cleanup_(sd_device_unrefp) sd_device *d = NULL; Manager *m = userdata; + int r; assert(m); - d = udev_monitor_receive_device(m->udev_device_monitor); - if (!d) - return -ENOMEM; + r = udev_monitor_receive_sd_device(m->udev_device_monitor, &d); + if (r < 0) + return r; manager_process_seat_device(m, d); return 0; } static int manager_dispatch_vcsa_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + _cleanup_(sd_device_unrefp) sd_device *d = NULL; Manager *m = userdata; - const char *name; + const char *name, *action; + int r; assert(m); - d = udev_monitor_receive_device(m->udev_vcsa_monitor); - if (!d) - return -ENOMEM; - - name = udev_device_get_sysname(d); + r = udev_monitor_receive_sd_device(m->udev_vcsa_monitor, &d); + if (r < 0) + return r; /* Whenever a VCSA device is removed try to reallocate our * VTs, to make sure our auto VTs never go away. */ - if (name && startswith(name, "vcsa") && streq_ptr(udev_device_get_action(d), "remove")) + if (sd_device_get_sysname(d, &name) >= 0 && + startswith(name, "vcsa") && + sd_device_get_property_value(d, "ACTION", &action) >= 0 && + streq_ptr(action, "remove")) seat_preallocate_vts(m->seat0); return 0; } static int manager_dispatch_button_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) { - _cleanup_(udev_device_unrefp) struct udev_device *d = NULL; + _cleanup_(sd_device_unrefp) sd_device *d = NULL; Manager *m = userdata; + int r; assert(m); - d = udev_monitor_receive_device(m->udev_button_monitor); - if (!d) - return -ENOMEM; + r = udev_monitor_receive_sd_device(m->udev_button_monitor, &d); + if (r < 0) + return r; manager_process_button_device(m, d); return 0; @@ -869,7 +849,7 @@ static int manager_connect_udev(Manager *m) { assert(!m->udev_vcsa_monitor); assert(!m->udev_button_monitor); - m->udev_seat_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); + m->udev_seat_monitor = udev_monitor_new_from_netlink(NULL, "udev"); if (!m->udev_seat_monitor) return -ENOMEM; @@ -885,7 +865,7 @@ static int manager_connect_udev(Manager *m) { if (r < 0) return r; - m->udev_device_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); + m->udev_device_monitor = udev_monitor_new_from_netlink(NULL, "udev"); if (!m->udev_device_monitor) return -ENOMEM; @@ -911,7 +891,7 @@ static int manager_connect_udev(Manager *m) { /* Don't watch keys if nobody cares */ if (!manager_all_buttons_ignored(m)) { - m->udev_button_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); + m->udev_button_monitor = udev_monitor_new_from_netlink(NULL, "udev"); if (!m->udev_button_monitor) return -ENOMEM; @@ -935,7 +915,7 @@ static int manager_connect_udev(Manager *m) { /* Don't bother watching VCSA devices, if nobody cares */ if (m->n_autovts > 0 && m->console_active_fd >= 0) { - m->udev_vcsa_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); + m->udev_vcsa_monitor = udev_monitor_new_from_netlink(NULL, "udev"); if (!m->udev_vcsa_monitor) return -ENOMEM; diff --git a/src/login/logind.h b/src/login/logind.h index a6ebc9e..e25bc1e 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -5,6 +5,7 @@ #include "libudev.h" #include "sd-bus.h" +#include "sd-device.h" #include "sd-event.h" #include "conf-parser.h" @@ -34,7 +35,6 @@ struct Manager { LIST_HEAD(Session, session_gc_queue); LIST_HEAD(User, user_gc_queue); - struct udev *udev; struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor; sd_event_source *console_active_event_source; @@ -133,8 +133,8 @@ int manager_add_user_by_name(Manager *m, const char *name, User **_user); int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user); int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor); -int manager_process_seat_device(Manager *m, struct udev_device *d); -int manager_process_button_device(Manager *m, struct udev_device *d); +int manager_process_seat_device(Manager *m, sd_device *d); +int manager_process_button_device(Manager *m, sd_device *d); int manager_spawn_autovt(Manager *m, unsigned int vtnr); -- 2.7.4