summaryrefslogtreecommitdiff
path: root/src/login/logind-session-device.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-08-22 14:53:51 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-08-23 04:57:39 +0900
commit4f209af7da0edee6b54c23b702354b35510e35e7 (patch)
tree43a65cf92f1b0c6f85560208a14df42b26eaf966 /src/login/logind-session-device.c
parent4366e598aef9898ab9d2a71e834e330cc2999e5b (diff)
downloadsystemd-4f209af7da0edee6b54c23b702354b35510e35e7.tar.gz
logind: replace udev_device by sd_device
Diffstat (limited to 'src/login/logind-session-device.c')
-rw-r--r--src/login/logind-session-device.c82
1 files changed, 34 insertions, 48 deletions
diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c
index c2dfe9f974..fbba792ed6 100644
--- a/src/login/logind-session-device.c
+++ b/src/login/logind-session-device.c
@@ -6,7 +6,7 @@
#include <sys/ioctl.h>
#include <sys/types.h>
-#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) {