summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-10-08 22:47:53 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-10-17 03:31:20 +0900
commiteb968396bb77a2c2f8f8118f696e5eb47d89ffcf (patch)
treeab08afdfc4a762fcf639344d8aba14a97a5fe068 /src/login
parentd0955f009195c2512e042cc10f723d6e5ac0d31a (diff)
downloadsystemd-eb968396bb77a2c2f8f8118f696e5eb47d89ffcf.tar.gz
systemd-eb968396bb77a2c2f8f8118f696e5eb47d89ffcf.tar.bz2
systemd-eb968396bb77a2c2f8f8118f696e5eb47d89ffcf.zip
login: replace udev_monitor by sd_device_monitor
Diffstat (limited to 'src/login')
-rw-r--r--src/login/logind.c121
-rw-r--r--src/login/logind.h7
2 files changed, 49 insertions, 79 deletions
diff --git a/src/login/logind.c b/src/login/logind.c
index 44899064c5..2539b1ef03 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -18,7 +18,6 @@
#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"
@@ -127,10 +126,6 @@ static Manager* manager_unref(Manager *m) {
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
@@ -139,10 +134,10 @@ static Manager* manager_unref(Manager *m) {
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");
@@ -540,72 +535,52 @@ static int manager_enumerate_inhibitors(Manager *m) {
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;
}
@@ -844,70 +819,70 @@ static int manager_connect_udev(Manager *m) {
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;
}
@@ -915,19 +890,19 @@ 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(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;
}
diff --git a/src/login/logind.h b/src/login/logind.h
index b1a7b932eb..6290107de2 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -3,7 +3,6 @@
#include <stdbool.h>
-#include "libudev.h"
#include "sd-bus.h"
#include "sd-device.h"
#include "sd-event.h"
@@ -36,13 +35,9 @@ struct Manager {
LIST_HEAD(Session, session_gc_queue);
LIST_HEAD(User, user_gc_queue);
- struct udev_monitor *udev_seat_monitor, *udev_device_monitor, *udev_vcsa_monitor, *udev_button_monitor;
+ sd_device_monitor *device_seat_monitor, *device_monitor, *device_vcsa_monitor, *device_button_monitor;
sd_event_source *console_active_event_source;
- sd_event_source *udev_seat_event_source;
- sd_event_source *udev_device_event_source;
- sd_event_source *udev_vcsa_event_source;
- sd_event_source *udev_button_event_source;
#if ENABLE_UTMP
sd_event_source *utmp_event_source;