2010-07-27 13:02:24 -06:00
|
|
|
/*
|
|
|
|
* Copyright © 2009 Julien Cristau
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Julien Cristau <jcristau@debian.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <libudev.h>
|
2010-12-05 08:36:02 -07:00
|
|
|
#include <ctype.h>
|
2014-09-27 11:52:59 -06:00
|
|
|
#include <unistd.h>
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "hotplug.h"
|
|
|
|
#include "config-backends.h"
|
|
|
|
#include "os.h"
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "globals.h"
|
2014-09-27 11:52:59 -06:00
|
|
|
#include "systemd-logind.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
#define UDEV_XKB_PROP_KEY "xkb"
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define LOG_PROPERTY(path, prop, val) \
|
|
|
|
LogMessageVerb(X_INFO, 10, \
|
|
|
|
"config/udev: getting property %s on %s " \
|
|
|
|
"returned \"%s\"\n", \
|
|
|
|
(prop), (path), (val) ? (val) : "(null)")
|
|
|
|
#define LOG_SYSATTR(path, attr, val) \
|
|
|
|
LogMessageVerb(X_INFO, 10, \
|
|
|
|
"config/udev: getting attribute %s on %s " \
|
|
|
|
"returned \"%s\"\n", \
|
|
|
|
(attr), (path), (val) ? (val) : "(null)")
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static struct udev_monitor *udev_monitor;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
#ifdef CONFIG_UDEV_KMS
|
2014-09-27 11:52:59 -06:00
|
|
|
static void
|
2013-06-07 11:28:45 -06:00
|
|
|
config_udev_odev_setup_attribs(const char *path, const char *syspath,
|
2014-09-27 11:52:59 -06:00
|
|
|
int major, int minor,
|
2013-06-07 11:28:45 -06:00
|
|
|
config_odev_probe_proc_ptr probe_callback);
|
|
|
|
#endif
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
static char itoa_buf[16];
|
|
|
|
|
|
|
|
static const char *itoa(int i)
|
|
|
|
{
|
|
|
|
snprintf(itoa_buf, sizeof(itoa_buf), "%d", i);
|
|
|
|
return itoa_buf;
|
|
|
|
}
|
|
|
|
|
2015-02-11 13:58:46 -07:00
|
|
|
static Bool
|
|
|
|
check_seat(struct udev_device *udev_device)
|
|
|
|
{
|
|
|
|
const char *dev_seat;
|
|
|
|
|
|
|
|
dev_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
|
|
|
|
if (!dev_seat)
|
|
|
|
dev_seat = "seat0";
|
|
|
|
|
|
|
|
if (SeatId && strcmp(dev_seat, SeatId))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!SeatId && strcmp(dev_seat, "seat0"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static void
|
|
|
|
device_added(struct udev_device *udev_device)
|
|
|
|
{
|
|
|
|
const char *path, *name = NULL;
|
|
|
|
char *config_info = NULL;
|
|
|
|
const char *syspath;
|
2010-12-05 08:36:02 -07:00
|
|
|
const char *tags_prop;
|
2010-07-27 13:02:24 -06:00
|
|
|
const char *key, *value, *tmp;
|
2012-06-10 07:21:05 -06:00
|
|
|
InputOption *input_options;
|
|
|
|
InputAttributes attrs = { };
|
2010-07-27 13:02:24 -06:00
|
|
|
DeviceIntPtr dev = NULL;
|
|
|
|
struct udev_list_entry *set, *entry;
|
|
|
|
struct udev_device *parent;
|
|
|
|
int rc;
|
2014-09-27 11:52:59 -06:00
|
|
|
dev_t devnum;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
path = udev_device_get_devnode(udev_device);
|
|
|
|
|
|
|
|
syspath = udev_device_get_syspath(udev_device);
|
|
|
|
|
|
|
|
if (!path || !syspath)
|
|
|
|
return;
|
|
|
|
|
2015-02-11 13:58:46 -07:00
|
|
|
if (!check_seat(udev_device))
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
devnum = udev_device_get_devnum(udev_device);
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
#ifdef CONFIG_UDEV_KMS
|
|
|
|
if (!strcmp(udev_device_get_subsystem(udev_device), "drm")) {
|
|
|
|
const char *sysname = udev_device_get_sysname(udev_device);
|
|
|
|
|
|
|
|
if (strncmp(sysname, "card", 4) != 0)
|
|
|
|
return;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
/* Check for devices already added through xf86platformProbe() */
|
|
|
|
if (xf86_find_platform_device_by_devnum(major(devnum), minor(devnum)))
|
|
|
|
return;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
config_udev_odev_setup_attribs(path, syspath, major(devnum),
|
|
|
|
minor(devnum), NewGPUDeviceRequest);
|
2013-06-07 11:28:45 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-18 10:16:37 -07:00
|
|
|
value = udev_device_get_property_value(udev_device, "ID_INPUT");
|
2019-03-19 15:19:54 -06:00
|
|
|
if (!value || !strcmp(value, "0")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
LogMessageVerb(X_INFO, 10,
|
|
|
|
"config/udev: ignoring device %s without "
|
2012-06-10 07:21:05 -06:00
|
|
|
"property ID_INPUT set\n", path);
|
2010-07-27 13:02:24 -06:00
|
|
|
return;
|
2010-12-05 08:36:02 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options = input_option_new(NULL, "_source", "server/udev");
|
|
|
|
if (!input_options)
|
2010-07-27 13:02:24 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
parent = udev_device_get_parent(udev_device);
|
|
|
|
if (parent) {
|
2010-12-05 08:36:02 -07:00
|
|
|
const char *ppath = udev_device_get_devnode(parent);
|
|
|
|
const char *product = udev_device_get_property_value(parent, "PRODUCT");
|
2011-11-05 07:32:40 -06:00
|
|
|
const char *pnp_id = udev_device_get_sysattr_value(parent, "id");
|
2010-12-05 08:36:02 -07:00
|
|
|
unsigned int usb_vendor, usb_model;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
name = udev_device_get_sysattr_value(parent, "name");
|
2010-12-05 08:36:02 -07:00
|
|
|
LOG_SYSATTR(ppath, "name", name);
|
|
|
|
if (!name) {
|
2010-07-27 13:02:24 -06:00
|
|
|
name = udev_device_get_property_value(parent, "NAME");
|
2010-12-05 08:36:02 -07:00
|
|
|
LOG_PROPERTY(ppath, "NAME", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* construct USB ID in lowercase hex - "0000:ffff" */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (product &&
|
|
|
|
sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
|
2014-09-27 11:52:59 -06:00
|
|
|
char *usb_id;
|
|
|
|
if (asprintf(&usb_id, "%04x:%04x", usb_vendor, usb_model)
|
2011-11-05 07:32:40 -06:00
|
|
|
== -1)
|
2014-09-27 11:52:59 -06:00
|
|
|
usb_id = NULL;
|
2011-11-05 07:32:40 -06:00
|
|
|
else
|
|
|
|
LOG_PROPERTY(ppath, "PRODUCT", product);
|
2014-09-27 11:52:59 -06:00
|
|
|
attrs.usb_id = usb_id;
|
2010-12-05 08:36:02 -07:00
|
|
|
}
|
2014-05-02 13:27:46 -06:00
|
|
|
|
|
|
|
while (!pnp_id && (parent = udev_device_get_parent(parent))) {
|
|
|
|
pnp_id = udev_device_get_sysattr_value(parent, "id");
|
|
|
|
if (!pnp_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
attrs.pnp_id = strdup(pnp_id);
|
|
|
|
ppath = udev_device_get_devnode(parent);
|
|
|
|
LOG_SYSATTR(ppath, "id", pnp_id);
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
if (!name)
|
|
|
|
name = "(unnamed)";
|
|
|
|
else
|
2011-11-05 07:32:40 -06:00
|
|
|
attrs.product = strdup(name);
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options = input_option_new(input_options, "name", name);
|
|
|
|
input_options = input_option_new(input_options, "path", path);
|
|
|
|
input_options = input_option_new(input_options, "device", path);
|
2014-09-27 11:52:59 -06:00
|
|
|
input_options = input_option_new(input_options, "major", itoa(major(devnum)));
|
|
|
|
input_options = input_option_new(input_options, "minor", itoa(minor(devnum)));
|
2011-11-05 07:32:40 -06:00
|
|
|
if (path)
|
|
|
|
attrs.device = strdup(path);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
tags_prop = udev_device_get_property_value(udev_device, "ID_INPUT.tags");
|
|
|
|
LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop);
|
|
|
|
attrs.tags = xstrtokenize(tags_prop, ",");
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (asprintf(&config_info, "udev:%s", syspath) == -1) {
|
|
|
|
config_info = NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
goto unwind;
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (device_is_duplicate(config_info)) {
|
|
|
|
LogMessage(X_WARNING, "config/udev: device %s already added. "
|
2012-06-10 07:21:05 -06:00
|
|
|
"Ignoring.\n", name);
|
2010-07-27 13:02:24 -06:00
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
set = udev_device_get_properties_list_entry(udev_device);
|
|
|
|
udev_list_entry_foreach(entry, set) {
|
|
|
|
key = udev_list_entry_get_name(entry);
|
|
|
|
if (!key)
|
|
|
|
continue;
|
|
|
|
value = udev_list_entry_get_value(entry);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!strncasecmp(key, UDEV_XKB_PROP_KEY, sizeof(UDEV_XKB_PROP_KEY) - 1)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
LOG_PROPERTY(path, key, value);
|
2010-07-27 13:02:24 -06:00
|
|
|
tmp = key + sizeof(UDEV_XKB_PROP_KEY) - 1;
|
|
|
|
if (!strcasecmp(tmp, "rules"))
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_rules", value);
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (!strcasecmp(tmp, "layout"))
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_layout", value);
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (!strcasecmp(tmp, "variant"))
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_variant", value);
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (!strcasecmp(tmp, "model"))
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_model", value);
|
2010-07-27 13:02:24 -06:00
|
|
|
else if (!strcasecmp(tmp, "options"))
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options =
|
|
|
|
input_option_new(input_options, "xkb_options", value);
|
|
|
|
}
|
|
|
|
else if (!strcmp(key, "ID_VENDOR")) {
|
2010-12-05 08:36:02 -07:00
|
|
|
LOG_PROPERTY(path, key, value);
|
2011-11-05 07:32:40 -06:00
|
|
|
attrs.vendor = strdup(value);
|
2018-02-18 10:16:37 -07:00
|
|
|
} else if (!strncmp(key, "ID_INPUT_", 9)) {
|
|
|
|
const struct pfmap {
|
|
|
|
const char *property;
|
|
|
|
unsigned int flag;
|
|
|
|
} map[] = {
|
|
|
|
{ "ID_INPUT_KEY", ATTR_KEY },
|
|
|
|
{ "ID_INPUT_KEYBOARD", ATTR_KEYBOARD },
|
|
|
|
{ "ID_INPUT_MOUSE", ATTR_POINTER },
|
|
|
|
{ "ID_INPUT_JOYSTICK", ATTR_JOYSTICK },
|
|
|
|
{ "ID_INPUT_TABLET", ATTR_TABLET },
|
|
|
|
{ "ID_INPUT_TABLET_PAD", ATTR_TABLET_PAD },
|
|
|
|
{ "ID_INPUT_TOUCHPAD", ATTR_TOUCHPAD },
|
|
|
|
{ "ID_INPUT_TOUCHSCREEN", ATTR_TOUCHSCREEN },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Anything but the literal string "0" is considered a
|
|
|
|
* boolean true. The empty string isn't a thing with udev
|
|
|
|
* properties anyway */
|
|
|
|
if (value && strcmp(value, "0")) {
|
|
|
|
const struct pfmap *m = map;
|
|
|
|
|
|
|
|
while (m->property != NULL) {
|
|
|
|
if (!strcmp(m->property, key)) {
|
|
|
|
LOG_PROPERTY(path, key, value);
|
|
|
|
attrs.flags |= m->flag;
|
|
|
|
}
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
input_options = input_option_new(input_options, "config_info", config_info);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
/* Default setting needed for non-seat0 seats */
|
|
|
|
if (ServerIsNotSeat0())
|
|
|
|
input_options = input_option_new(input_options, "GrabDevice", "on");
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n",
|
|
|
|
name, path);
|
2012-06-10 07:21:05 -06:00
|
|
|
rc = NewInputDeviceRequest(input_options, &attrs, &dev);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
|
|
|
unwind:
|
2010-12-05 08:36:02 -07:00
|
|
|
free(config_info);
|
2012-06-10 07:21:05 -06:00
|
|
|
input_option_free_list(&input_options);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(attrs.usb_id);
|
2011-11-05 07:32:40 -06:00
|
|
|
free(attrs.pnp_id);
|
|
|
|
free(attrs.product);
|
|
|
|
free(attrs.device);
|
|
|
|
free(attrs.vendor);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (attrs.tags) {
|
|
|
|
char **tag = attrs.tags;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
while (*tag) {
|
2010-12-05 08:36:02 -07:00
|
|
|
free(*tag);
|
2010-07-27 13:02:24 -06:00
|
|
|
tag++;
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(attrs.tags);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_removed(struct udev_device *device)
|
|
|
|
{
|
|
|
|
char *value;
|
|
|
|
const char *syspath = udev_device_get_syspath(device);
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
#ifdef CONFIG_UDEV_KMS
|
|
|
|
if (!strcmp(udev_device_get_subsystem(device), "drm")) {
|
|
|
|
const char *sysname = udev_device_get_sysname(device);
|
|
|
|
const char *path = udev_device_get_devnode(device);
|
2014-09-27 11:52:59 -06:00
|
|
|
dev_t devnum = udev_device_get_devnum(device);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
if ((strncmp(sysname,"card", 4) != 0) || (path == NULL))
|
2013-06-07 11:28:45 -06:00
|
|
|
return;
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
LogMessage(X_INFO, "config/udev: removing GPU device %s %s\n",
|
|
|
|
syspath, path);
|
2014-09-27 11:52:59 -06:00
|
|
|
config_udev_odev_setup_attribs(path, syspath, major(devnum),
|
|
|
|
minor(devnum), DeleteGPUDeviceRequest);
|
|
|
|
/* Retry vtenter after a drm node removal */
|
|
|
|
systemd_logind_vtenter();
|
2013-06-07 11:28:45 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (asprintf(&value, "udev:%s", syspath) == -1)
|
2010-07-27 13:02:24 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
remove_devices("udev", value);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(value);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-12-08 08:01:59 -07:00
|
|
|
socket_handler(int fd, int ready, void *data)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
struct udev_device *udev_device;
|
|
|
|
const char *action;
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
input_lock();
|
|
|
|
udev_device = udev_monitor_receive_device(udev_monitor);
|
|
|
|
if (!udev_device) {
|
|
|
|
input_unlock();
|
2010-07-27 13:02:24 -06:00
|
|
|
return;
|
2017-12-08 08:01:59 -07:00
|
|
|
}
|
|
|
|
action = udev_device_get_action(udev_device);
|
|
|
|
if (action) {
|
|
|
|
if (!strcmp(action, "add")) {
|
|
|
|
device_removed(udev_device);
|
|
|
|
device_added(udev_device);
|
|
|
|
} else if (!strcmp(action, "change")) {
|
|
|
|
/* ignore change for the drm devices */
|
|
|
|
if (strcmp(udev_device_get_subsystem(udev_device), "drm")) {
|
2011-11-05 07:32:40 -06:00
|
|
|
device_removed(udev_device);
|
2010-07-27 13:02:24 -06:00
|
|
|
device_added(udev_device);
|
2011-11-05 07:32:40 -06:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2017-12-08 08:01:59 -07:00
|
|
|
else if (!strcmp(action, "remove"))
|
|
|
|
device_removed(udev_device);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2017-12-08 08:01:59 -07:00
|
|
|
udev_device_unref(udev_device);
|
|
|
|
input_unlock();
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-06-07 11:28:45 -06:00
|
|
|
config_udev_pre_init(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
struct udev *udev;
|
|
|
|
|
|
|
|
udev = udev_new();
|
|
|
|
if (!udev)
|
|
|
|
return 0;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
|
|
|
if (!udev_monitor)
|
|
|
|
return 0;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input",
|
|
|
|
NULL);
|
2013-06-07 11:28:45 -06:00
|
|
|
/* For Wacom serial devices */
|
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL);
|
|
|
|
#ifdef CONFIG_UDEV_KMS
|
|
|
|
/* For output GPU devices */
|
|
|
|
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "drm", NULL);
|
|
|
|
#endif
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef HAVE_UDEV_MONITOR_FILTER_ADD_MATCH_TAG
|
2013-06-07 11:28:45 -06:00
|
|
|
if (ServerIsNotSeat0())
|
2012-06-10 07:21:05 -06:00
|
|
|
udev_monitor_filter_add_match_tag(udev_monitor, SeatId);
|
|
|
|
#endif
|
2010-07-27 13:02:24 -06:00
|
|
|
if (udev_monitor_enable_receiving(udev_monitor)) {
|
|
|
|
ErrorF("config/udev: failed to bind the udev monitor\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
int
|
|
|
|
config_udev_init(void)
|
|
|
|
{
|
|
|
|
struct udev *udev;
|
|
|
|
struct udev_enumerate *enumerate;
|
|
|
|
struct udev_list_entry *devices, *device;
|
|
|
|
|
|
|
|
udev = udev_monitor_get_udev(udev_monitor);
|
2010-07-27 13:02:24 -06:00
|
|
|
enumerate = udev_enumerate_new(udev);
|
|
|
|
if (!enumerate)
|
|
|
|
return 0;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
udev_enumerate_add_match_subsystem(enumerate, "input");
|
|
|
|
udev_enumerate_add_match_subsystem(enumerate, "tty");
|
2013-06-07 11:28:45 -06:00
|
|
|
#ifdef CONFIG_UDEV_KMS
|
|
|
|
udev_enumerate_add_match_subsystem(enumerate, "drm");
|
|
|
|
#endif
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG
|
2013-06-07 11:28:45 -06:00
|
|
|
if (ServerIsNotSeat0())
|
2012-06-10 07:21:05 -06:00
|
|
|
udev_enumerate_add_match_tag(enumerate, SeatId);
|
|
|
|
#endif
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
udev_enumerate_scan_devices(enumerate);
|
|
|
|
devices = udev_enumerate_get_list_entry(enumerate);
|
|
|
|
udev_list_entry_foreach(device, devices) {
|
|
|
|
const char *syspath = udev_list_entry_get_name(device);
|
2012-06-10 07:21:05 -06:00
|
|
|
struct udev_device *udev_device =
|
|
|
|
udev_device_new_from_syspath(udev, syspath);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
/* Device might be gone by the time we try to open it */
|
|
|
|
if (!udev_device)
|
|
|
|
continue;
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
device_added(udev_device);
|
|
|
|
udev_device_unref(udev_device);
|
|
|
|
}
|
|
|
|
udev_enumerate_unref(enumerate);
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
SetNotifyFd(udev_monitor_get_fd(udev_monitor), socket_handler, X_NOTIFY_READ, NULL);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
config_udev_fini(void)
|
|
|
|
{
|
|
|
|
struct udev *udev;
|
|
|
|
|
|
|
|
if (!udev_monitor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
udev = udev_monitor_get_udev(udev_monitor);
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
RemoveNotifyFd(udev_monitor_get_fd(udev_monitor));
|
2010-07-27 13:02:24 -06:00
|
|
|
udev_monitor_unref(udev_monitor);
|
|
|
|
udev_monitor = NULL;
|
|
|
|
udev_unref(udev);
|
|
|
|
}
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_UDEV_KMS
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
static void
|
2013-06-07 11:28:45 -06:00
|
|
|
config_udev_odev_setup_attribs(const char *path, const char *syspath,
|
2014-09-27 11:52:59 -06:00
|
|
|
int major, int minor,
|
2013-06-07 11:28:45 -06:00
|
|
|
config_odev_probe_proc_ptr probe_callback)
|
|
|
|
{
|
2015-09-16 13:10:19 -06:00
|
|
|
struct OdevAttributes *attribs = config_odev_allocate_attributes();
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
attribs->path = XNFstrdup(path);
|
|
|
|
attribs->syspath = XNFstrdup(syspath);
|
|
|
|
attribs->major = major;
|
|
|
|
attribs->minor = minor;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
/* ownership of attribs is passed to probe layer */
|
|
|
|
probe_callback(attribs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback)
|
|
|
|
{
|
|
|
|
struct udev *udev;
|
|
|
|
struct udev_enumerate *enumerate;
|
|
|
|
struct udev_list_entry *devices, *device;
|
|
|
|
|
|
|
|
udev = udev_monitor_get_udev(udev_monitor);
|
|
|
|
enumerate = udev_enumerate_new(udev);
|
|
|
|
if (!enumerate)
|
|
|
|
return;
|
|
|
|
|
|
|
|
udev_enumerate_add_match_subsystem(enumerate, "drm");
|
|
|
|
udev_enumerate_add_match_sysname(enumerate, "card[0-9]*");
|
|
|
|
#ifdef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG
|
|
|
|
if (ServerIsNotSeat0())
|
|
|
|
udev_enumerate_add_match_tag(enumerate, SeatId);
|
|
|
|
#endif
|
|
|
|
udev_enumerate_scan_devices(enumerate);
|
|
|
|
devices = udev_enumerate_get_list_entry(enumerate);
|
|
|
|
udev_list_entry_foreach(device, devices) {
|
|
|
|
const char *syspath = udev_list_entry_get_name(device);
|
|
|
|
struct udev_device *udev_device = udev_device_new_from_syspath(udev, syspath);
|
|
|
|
const char *path = udev_device_get_devnode(udev_device);
|
|
|
|
const char *sysname = udev_device_get_sysname(udev_device);
|
2014-09-27 11:52:59 -06:00
|
|
|
dev_t devnum = udev_device_get_devnum(udev_device);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
if (!path || !syspath)
|
|
|
|
goto no_probe;
|
|
|
|
else if (strcmp(udev_device_get_subsystem(udev_device), "drm") != 0)
|
|
|
|
goto no_probe;
|
|
|
|
else if (strncmp(sysname, "card", 4) != 0)
|
|
|
|
goto no_probe;
|
2015-02-11 13:58:46 -07:00
|
|
|
else if (!check_seat(udev_device))
|
|
|
|
goto no_probe;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
config_udev_odev_setup_attribs(path, syspath, major(devnum),
|
|
|
|
minor(devnum), probe_callback);
|
2013-06-07 11:28:45 -06:00
|
|
|
no_probe:
|
|
|
|
udev_device_unref(udev_device);
|
|
|
|
}
|
|
|
|
udev_enumerate_unref(enumerate);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|