diff options
author | Keith Packard <keithp@keithp.com> | 2011-09-26 20:24:15 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2011-09-26 20:24:15 -0700 |
commit | afb1fe695d197187a301c19863a128a65389b15c (patch) | |
tree | d1ec3b11b8ca521cb77ff1d6821786d3dfc6a5e1 /config | |
parent | 7fb4bef0394a5d09680985d34bce8252b61493cb (diff) | |
parent | c7163fdd302f706a3d67f0fdf93eeb3396bb3332 (diff) |
Merge remote-tracking branch 'whot/next'
Diffstat (limited to 'config')
-rw-r--r-- | config/config-backends.h | 2 | ||||
-rw-r--r-- | config/config.c | 15 | ||||
-rw-r--r-- | config/dbus.c | 60 | ||||
-rw-r--r-- | config/hal.c | 44 | ||||
-rw-r--r-- | config/udev.c | 59 |
5 files changed, 64 insertions, 116 deletions
diff --git a/config/config-backends.h b/config/config-backends.h index 0a2a22af0..35ab8a044 100644 --- a/config/config-backends.h +++ b/config/config-backends.h @@ -27,10 +27,10 @@ #include <dix-config.h> #endif #include "input.h" +#include "list.h" void remove_devices(const char *backend, const char *config_info); BOOL device_is_duplicate(const char *config_info); -void add_option(InputOption **options, const char *key, const char *value); #ifdef CONFIG_UDEV int config_udev_init(void); diff --git a/config/config.c b/config/config.c index d86f7c649..9c28785c6 100644 --- a/config/config.c +++ b/config/config.c @@ -122,18 +122,3 @@ device_is_duplicate(const char *config_info) return FALSE; } -void -add_option(InputOption **options, const char *key, const char *value) -{ - if (!value || *value == '\0') - return; - - for (; *options; options = &(*options)->next) - ; - *options = calloc(sizeof(**options), 1); - if (!*options) /* Yeesh. */ - return; - (*options)->key = strdup(key); - (*options)->value = strdup(value); - (*options)->next = NULL; -} diff --git a/config/dbus.c b/config/dbus.c index 34e3caade..f0fc5686e 100644 --- a/config/dbus.c +++ b/config/dbus.c @@ -68,8 +68,7 @@ static int add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) { DBusMessageIter iter, reply_iter, subiter; - InputOption *tmpo = NULL, *options = NULL; - char *tmp = NULL; + InputOption *input_options = NULL; int ret, err; DeviceIntPtr dev = NULL; @@ -80,15 +79,8 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) MALFORMED_MESSAGE(); } - options = calloc(sizeof(*options), 1); - if (!options) { - ErrorF("[config/dbus] couldn't allocate option\n"); - return BadAlloc; - } - - options->key = strdup("_source"); - options->value = strdup("client/dbus"); - if (!options->key || !options->value) { + input_options = input_option_new(input_options, "_source", "client/dbus"); + if (!input_options) { ErrorF("[config/dbus] couldn't allocate first key/value pair\n"); ret = BadAlloc; goto unwind; @@ -96,36 +88,22 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) /* signature should be [ss][ss]... */ while (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) { - tmpo = calloc(sizeof(*tmpo), 1); - if (!tmpo) { - ErrorF("[config/dbus] couldn't allocate option\n"); - ret = BadAlloc; - goto unwind; - } - tmpo->next = options; - options = tmpo; - + char *key, *value; dbus_message_iter_recurse(&iter, &subiter); if (dbus_message_iter_get_arg_type(&subiter) != DBUS_TYPE_STRING) MALFORMED_MESSAGE(); - dbus_message_iter_get_basic(&subiter, &tmp); - if (!tmp) + dbus_message_iter_get_basic(&subiter, &key); + if (!key) MALFORMED_MESSAGE(); /* The _ prefix refers to internal settings, and may not be given by * the client. */ - if (tmp[0] == '_') { + if (key[0] == '_') { ErrorF("[config/dbus] attempted subterfuge: option name %s given\n", - tmp); + key); MALFORMED_MESSAGE(); } - options->key = strdup(tmp); - if (!options->key) { - ErrorF("[config/dbus] couldn't duplicate key!\n"); - ret = BadAlloc; - goto unwind; - } if (!dbus_message_iter_has_next(&subiter)) MALFORMED_MESSAGE(); @@ -133,20 +111,16 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error) if (dbus_message_iter_get_arg_type(&subiter) != DBUS_TYPE_STRING) MALFORMED_MESSAGE(); - dbus_message_iter_get_basic(&subiter, &tmp); - if (!tmp) + dbus_message_iter_get_basic(&subiter, &value); + if (!value) MALFORMED_MESSAGE(); - options->value = strdup(tmp); - if (!options->value) { - ErrorF("[config/dbus] couldn't duplicate option!\n"); - ret = BadAlloc; - goto unwind; - } + + input_options = input_option_new(input_options, key, value); dbus_message_iter_next(&iter); } - ret = NewInputDeviceRequest(options, NULL, &dev); + ret = NewInputDeviceRequest(input_options, NULL, &dev); if (ret != Success) { DebugF("[config/dbus] NewInputDeviceRequest failed\n"); goto unwind; @@ -180,13 +154,7 @@ unwind: dbus_message_iter_append_basic(&reply_iter, DBUS_TYPE_INT32, &err); } - while (options) { - tmpo = options; - options = options->next; - free(tmpo->key); - free(tmpo->value); - free(tmpo); - } + input_option_free_list(&input_options); return ret; } diff --git a/config/hal.c b/config/hal.c index 297520aa6..aa234ebb4 100644 --- a/config/hal.c +++ b/config/hal.c @@ -128,7 +128,7 @@ device_added(LibHalContext *hal_ctx, const char *udi) { char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL; char *hal_tags, *parent; - InputOption *options = NULL, *tmpo = NULL; + InputOption *input_options = NULL; InputAttributes attrs = {0}; DeviceIntPtr dev = NULL; DBusError error; @@ -205,26 +205,19 @@ device_added(LibHalContext *hal_ctx, const char *udi) free(parent); } - options = calloc(sizeof(*options), 1); - if (!options){ - LogMessage(X_ERROR, "config/hal: couldn't allocate space for input options!\n"); - goto unwind; - } - - options->key = strdup("_source"); - options->value = strdup("server/hal"); - if (!options->key || !options->value) { + input_options = input_option_new(NULL, "_source", "server/hal"); + if (!input_options) { LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n"); goto unwind; } /* most drivers use device.. not path. evdev uses both however, but the * path version isn't documented apparently. support both for now. */ - add_option(&options, "path", path); - add_option(&options, "device", path); + input_options = input_option_new(input_options, "path", path); + input_options = input_option_new(input_options, "device", path); - add_option(&options, "driver", driver); - add_option(&options, "name", name); + input_options = input_option_new(input_options, "driver", driver); + input_options = input_option_new(input_options, "name", name); if (asprintf (&config_info, "hal:%s", udi) == -1) { config_info = NULL; @@ -298,7 +291,7 @@ device_added(LibHalContext *hal_ctx, const char *udi) } else { /* all others */ - add_option(&options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val); + input_options = input_option_new(input_options, psi_key + sizeof(LIBHAL_PROP_KEY)-1, tmp_val); free(tmp_val); } } else @@ -366,20 +359,20 @@ device_added(LibHalContext *hal_ctx, const char *udi) /* Now add xkb options */ if (xkb_opts.layout) - add_option(&options, "xkb_layout", xkb_opts.layout); + input_options = input_option_new(input_options, "xkb_layout", xkb_opts.layout); if (xkb_opts.rules) - add_option(&options, "xkb_rules", xkb_opts.rules); + input_options = input_option_new(input_options, "xkb_rules", xkb_opts.rules); if (xkb_opts.variant) - add_option(&options, "xkb_variant", xkb_opts.variant); + input_options = input_option_new(input_options, "xkb_variant", xkb_opts.variant); if (xkb_opts.model) - add_option(&options, "xkb_model", xkb_opts.model); + input_options = input_option_new(input_options, "xkb_model", xkb_opts.model); if (xkb_opts.options) - add_option(&options, "xkb_options", xkb_opts.options); - add_option(&options, "config_info", config_info); + input_options = input_option_new(input_options, "xkb_options", xkb_opts.options); + input_options = input_option_new(input_options, "config_info", config_info); /* this isn't an error, but how else do you output something that the user can see? */ LogMessage(X_INFO, "config/hal: Adding input device %s\n", name); - if ((rc = NewInputDeviceRequest(options, &attrs, &dev)) != Success) { + if ((rc = NewInputDeviceRequest(input_options, &attrs, &dev)) != Success) { LogMessage(X_ERROR, "config/hal: NewInputDeviceRequest failed (%d)\n", rc); dev = NULL; goto unwind; @@ -392,12 +385,7 @@ unwind: free(driver); free(name); free(config_info); - while ((tmpo = options)) { - options = tmpo->next; - free(tmpo->key); /* NULL if dev != NULL */ - free(tmpo->value); /* NULL if dev != NULL */ - free(tmpo); - } + input_option_free_list(&input_options); free(attrs.product); free(attrs.vendor); diff --git a/config/udev.c b/config/udev.c index e7383dc36..1ba0d500d 100644 --- a/config/udev.c +++ b/config/udev.c @@ -35,6 +35,7 @@ #include "hotplug.h" #include "config-backends.h" #include "os.h" +#include "globals.h" #define UDEV_XKB_PROP_KEY "xkb" @@ -59,12 +60,13 @@ device_added(struct udev_device *udev_device) const char *syspath; const char *tags_prop; const char *key, *value, *tmp; - InputOption *options = NULL, *tmpo; + InputOption *input_options; InputAttributes attrs = {}; DeviceIntPtr dev = NULL; struct udev_list_entry *set, *entry; struct udev_device *parent; int rc; + const char *dev_seat; path = udev_device_get_devnode(udev_device); @@ -73,6 +75,16 @@ device_added(struct udev_device *udev_device) if (!path || !syspath) return; + dev_seat = udev_device_get_property_value(udev_device, "ID_SEAT"); + if (!dev_seat) + dev_seat = "seat0"; + + if (SeatId && strcmp(dev_seat, SeatId)) + return; + + if (!SeatId && strcmp(dev_seat, "seat0")) + return; + if (!udev_device_get_property_value(udev_device, "ID_INPUT")) { LogMessageVerb(X_INFO, 10, "config/udev: ignoring device %s without " @@ -81,15 +93,10 @@ device_added(struct udev_device *udev_device) return; } - options = calloc(sizeof(*options), 1); - if (!options) + input_options = input_option_new(NULL, "_source", "server/udev"); + if (!input_options) return; - options->key = strdup("_source"); - options->value = strdup("server/udev"); - if (!options->key || !options->value) - goto unwind; - parent = udev_device_get_parent(udev_device); if (parent) { const char *ppath = udev_device_get_devnode(parent); @@ -114,17 +121,16 @@ device_added(struct udev_device *udev_device) == -1) attrs.usb_id = NULL; else - LOG_PROPERTY(path, "PRODUCT", product); + LOG_PROPERTY(ppath, "PRODUCT", product); } } if (!name) name = "(unnamed)"; else attrs.product = strdup(name); - add_option(&options, "name", name); - - add_option(&options, "path", path); - add_option(&options, "device", path); + 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); if (path) attrs.device = strdup(path); @@ -154,15 +160,15 @@ device_added(struct udev_device *udev_device) LOG_PROPERTY(path, key, value); tmp = key + sizeof(UDEV_XKB_PROP_KEY) - 1; if (!strcasecmp(tmp, "rules")) - add_option(&options, "xkb_rules", value); + input_options = input_option_new(input_options, "xkb_rules", value); else if (!strcasecmp(tmp, "layout")) - add_option(&options, "xkb_layout", value); + input_options = input_option_new(input_options, "xkb_layout", value); else if (!strcasecmp(tmp, "variant")) - add_option(&options, "xkb_variant", value); + input_options = input_option_new(input_options, "xkb_variant", value); else if (!strcasecmp(tmp, "model")) - add_option(&options, "xkb_model", value); + input_options = input_option_new(input_options, "xkb_model", value); else if (!strcasecmp(tmp, "options")) - add_option(&options, "xkb_options", value); + input_options = input_option_new(input_options, "xkb_options", value); } else if (!strcmp(key, "ID_VENDOR")) { LOG_PROPERTY(path, key, value); attrs.vendor = strdup(value); @@ -187,22 +193,17 @@ device_added(struct udev_device *udev_device) } } - add_option(&options, "config_info", config_info); + input_options = input_option_new(input_options, "config_info", config_info); LogMessage(X_INFO, "config/udev: Adding input device %s (%s)\n", name, path); - rc = NewInputDeviceRequest(options, &attrs, &dev); + rc = NewInputDeviceRequest(input_options, &attrs, &dev); if (rc != Success) goto unwind; unwind: free(config_info); - while ((tmpo = options)) { - options = tmpo->next; - free(tmpo->key); /* NULL if dev != NULL */ - free(tmpo->value); /* NULL if dev != NULL */ - free(tmpo); - } + input_option_free_list(&input_options); free(attrs.usb_id); free(attrs.pnp_id); @@ -284,6 +285,9 @@ config_udev_init(void) udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input", NULL); udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL); /* For Wacom serial devices */ + if (SeatId && strcmp(SeatId, "seat0")) + udev_monitor_filter_add_match_tag(udev_monitor, SeatId); + if (udev_monitor_enable_receiving(udev_monitor)) { ErrorF("config/udev: failed to bind the udev monitor\n"); return 0; @@ -296,6 +300,9 @@ config_udev_init(void) udev_enumerate_add_match_subsystem(enumerate, "input"); udev_enumerate_add_match_subsystem(enumerate, "tty"); + if (SeatId && strcmp(SeatId, "seat0")) + udev_enumerate_add_match_tag(enumerate, SeatId); + udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); udev_list_entry_foreach(device, devices) { |