#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"
sd_event_source_unref(m->wall_message_timeout_source);
sd_event_source_unref(m->console_active_event_source);
- sd_event_source_unref(m->udev_seat_event_source);
- sd_event_source_unref(m->udev_device_event_source);
- sd_event_source_unref(m->udev_vcsa_event_source);
- sd_event_source_unref(m->udev_button_event_source);
sd_event_source_unref(m->lid_switch_ignore_event_source);
#if ENABLE_UTMP
safe_close(m->console_active_fd);
- udev_monitor_unref(m->udev_seat_monitor);
- udev_monitor_unref(m->udev_device_monitor);
- udev_monitor_unref(m->udev_vcsa_monitor);
- udev_monitor_unref(m->udev_button_monitor);
+ sd_device_monitor_unref(m->device_seat_monitor);
+ sd_device_monitor_unref(m->device_monitor);
+ sd_device_monitor_unref(m->device_vcsa_monitor);
+ sd_device_monitor_unref(m->device_button_monitor);
if (m->unlink_nologin)
(void) unlink_or_warn("/run/nologin");
return r;
}
-static int manager_dispatch_seat_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
- _cleanup_(sd_device_unrefp) sd_device *d = NULL;
+static int manager_dispatch_seat_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
Manager *m = userdata;
- int r;
assert(m);
+ assert(device);
- r = udev_monitor_receive_sd_device(m->udev_seat_monitor, &d);
- if (r < 0)
- return r;
-
- manager_process_seat_device(m, d);
+ manager_process_seat_device(m, device);
return 0;
}
-static int manager_dispatch_device_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
- _cleanup_(sd_device_unrefp) sd_device *d = NULL;
+static int manager_dispatch_device_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
Manager *m = userdata;
- int r;
assert(m);
+ assert(device);
- r = udev_monitor_receive_sd_device(m->udev_device_monitor, &d);
- if (r < 0)
- return r;
-
- manager_process_seat_device(m, d);
+ manager_process_seat_device(m, device);
return 0;
}
-static int manager_dispatch_vcsa_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
- _cleanup_(sd_device_unrefp) sd_device *d = NULL;
+static int manager_dispatch_vcsa_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
Manager *m = userdata;
const char *name, *action;
- int r;
assert(m);
-
- r = udev_monitor_receive_sd_device(m->udev_vcsa_monitor, &d);
- if (r < 0)
- return r;
+ assert(device);
/* Whenever a VCSA device is removed try to reallocate our
* VTs, to make sure our auto VTs never go away. */
- if (sd_device_get_sysname(d, &name) >= 0 &&
+ if (sd_device_get_sysname(device, &name) >= 0 &&
startswith(name, "vcsa") &&
- sd_device_get_property_value(d, "ACTION", &action) >= 0 &&
+ sd_device_get_property_value(device, "ACTION", &action) >= 0 &&
streq(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_(sd_device_unrefp) sd_device *d = NULL;
+static int manager_dispatch_button_udev(sd_device_monitor *monitor, sd_device *device, void *userdata) {
Manager *m = userdata;
- int r;
assert(m);
+ assert(device);
- r = udev_monitor_receive_sd_device(m->udev_button_monitor, &d);
- if (r < 0)
- return r;
-
- manager_process_button_device(m, d);
+ manager_process_button_device(m, device);
return 0;
}
int r;
assert(m);
- assert(!m->udev_seat_monitor);
- assert(!m->udev_device_monitor);
- assert(!m->udev_vcsa_monitor);
- assert(!m->udev_button_monitor);
+ assert(!m->device_seat_monitor);
+ assert(!m->device_monitor);
+ assert(!m->device_vcsa_monitor);
+ assert(!m->device_button_monitor);
- m->udev_seat_monitor = udev_monitor_new_from_netlink(NULL, "udev");
- if (!m->udev_seat_monitor)
- return -ENOMEM;
+ r = sd_device_monitor_new(&m->device_seat_monitor);
+ if (r < 0)
+ return r;
- r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, "master-of-seat");
+ r = sd_device_monitor_filter_add_match_tag(m->device_seat_monitor, "master-of-seat");
if (r < 0)
return r;
- r = udev_monitor_enable_receiving(m->udev_seat_monitor);
+ r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event, 0);
if (r < 0)
return r;
- r = sd_event_add_io(m->event, &m->udev_seat_event_source, udev_monitor_get_fd(m->udev_seat_monitor), EPOLLIN, manager_dispatch_seat_udev, m);
+ r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m, "logind-seat-monitor");
if (r < 0)
return r;
- m->udev_device_monitor = udev_monitor_new_from_netlink(NULL, "udev");
- if (!m->udev_device_monitor)
- return -ENOMEM;
+ r = sd_device_monitor_new(&m->device_monitor);
+ if (r < 0)
+ return r;
- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_device_monitor, "input", NULL);
+ r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_monitor, "input", NULL);
if (r < 0)
return r;
- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_device_monitor, "graphics", NULL);
+ r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_monitor, "graphics", NULL);
if (r < 0)
return r;
- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_device_monitor, "drm", NULL);
+ r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_monitor, "drm", NULL);
if (r < 0)
return r;
- r = udev_monitor_enable_receiving(m->udev_device_monitor);
+ r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
if (r < 0)
return r;
- r = sd_event_add_io(m->event, &m->udev_device_event_source, udev_monitor_get_fd(m->udev_device_monitor), EPOLLIN, manager_dispatch_device_udev, m);
+ r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m, "logind-device-monitor");
if (r < 0)
return r;
/* Don't watch keys if nobody cares */
if (!manager_all_buttons_ignored(m)) {
- m->udev_button_monitor = udev_monitor_new_from_netlink(NULL, "udev");
- if (!m->udev_button_monitor)
- return -ENOMEM;
+ r = sd_device_monitor_new(&m->device_button_monitor);
+ if (r < 0)
+ return r;
- r = udev_monitor_filter_add_match_tag(m->udev_button_monitor, "power-switch");
+ r = sd_device_monitor_filter_add_match_tag(m->device_button_monitor, "power-switch");
if (r < 0)
return r;
- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_button_monitor, "input", NULL);
+ r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_button_monitor, "input", NULL);
if (r < 0)
return r;
- r = udev_monitor_enable_receiving(m->udev_button_monitor);
+ r = sd_device_monitor_attach_event(m->device_button_monitor, m->event, 0);
if (r < 0)
return r;
- r = sd_event_add_io(m->event, &m->udev_button_event_source, udev_monitor_get_fd(m->udev_button_monitor), EPOLLIN, manager_dispatch_button_udev, m);
+ r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m, "logind-button-monitor");
if (r < 0)
return r;
}
/* 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(NULL, "udev");
- if (!m->udev_vcsa_monitor)
- return -ENOMEM;
+ r = sd_device_monitor_new(&m->device_vcsa_monitor);
+ if (r < 0)
+ return r;
- r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_vcsa_monitor, "vc", NULL);
+ r = sd_device_monitor_filter_add_match_subsystem_devtype(m->device_vcsa_monitor, "vc", NULL);
if (r < 0)
return r;
- r = udev_monitor_enable_receiving(m->udev_vcsa_monitor);
+ r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event, 0);
if (r < 0)
return r;
- r = sd_event_add_io(m->event, &m->udev_vcsa_event_source, udev_monitor_get_fd(m->udev_vcsa_monitor), EPOLLIN, manager_dispatch_vcsa_udev, m);
+ r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m, "logind-vcsa-monitor");
if (r < 0)
return r;
}