0006-config-udev-drop-ID_INPUT-code.patch 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. From fefc980d1c009752df03dd018216eb1588d2f9e0 Mon Sep 17 00:00:00 2001
  2. From: Alex Suykov <alex.suykov@gmail.com>
  3. Date: Sun, 21 Jan 2018 04:05:14 +0200
  4. Subject: [PATCH xserver 6/8] config/udev: drop ID_INPUT code
  5. Query event bits directly instead.
  6. XKB/udevd configuration code goes out as well, it is prone to the same
  7. kind of race conditions and the whole idea of using udev to configure
  8. X-specific properties is just dumb.
  9. Signed-off-by: Alex Suykov <alex.suykov@gmail.com>
  10. ---
  11. config/udev.c | 151 ++++++++++++++++++----------------------------------------
  12. 1 file changed, 47 insertions(+), 104 deletions(-)
  13. diff --git a/config/udev.c b/config/udev.c
  14. index 1a6021262..1d4b4687a 100644
  15. --- a/config/udev.c
  16. +++ b/config/udev.c
  17. @@ -39,19 +39,6 @@
  18. #include "globals.h"
  19. #include "systemd-logind.h"
  20. -#define UDEV_XKB_PROP_KEY "xkb"
  21. -
  22. -#define LOG_PROPERTY(path, prop, val) \
  23. - LogMessageVerb(X_INFO, 10, \
  24. - "config/udev: getting property %s on %s " \
  25. - "returned \"%s\"\n", \
  26. - (prop), (path), (val) ? (val) : "(null)")
  27. -#define LOG_SYSATTR(path, attr, val) \
  28. - LogMessageVerb(X_INFO, 10, \
  29. - "config/udev: getting attribute %s on %s " \
  30. - "returned \"%s\"\n", \
  31. - (attr), (path), (val) ? (val) : "(null)")
  32. -
  33. static struct udev_monitor *udev_monitor;
  34. #ifdef CONFIG_UDEV_KMS
  35. @@ -108,7 +95,8 @@ device_added_drm(struct udev_device *udev_device,
  36. }
  37. static const char*
  38. -query_input_name_ids(struct udev_device* parent, InputAttributes* attrs)
  39. +query_input_name_ids(struct udev_device* parent, InputAttributes* attrs,
  40. + const char* path)
  41. {
  42. const char *ppath = udev_device_get_devnode(parent);
  43. const char *product = udev_device_get_property_value(parent, "PRODUCT");
  44. @@ -116,10 +104,10 @@ query_input_name_ids(struct udev_device* parent, InputAttributes* attrs)
  45. unsigned int vendor, model;
  46. const char* name = NULL;
  47. - if ((name = udev_device_get_sysattr_value(parent, "name")))
  48. - LOG_SYSATTR(ppath, "name", name);
  49. - else if((name = udev_device_get_property_value(parent, "NAME")))
  50. - LOG_PROPERTY(ppath, "NAME", name);
  51. + name = udev_device_get_sysattr_value(parent, "name");
  52. +
  53. + if (!name)
  54. + name = udev_device_get_property_value(parent, "NAME");
  55. if (name)
  56. attrs->product = strdup(name);
  57. @@ -129,7 +117,8 @@ query_input_name_ids(struct udev_device* parent, InputAttributes* attrs)
  58. if (asprintf(&usb_id, "%04x:%04x", vendor, model) == -1)
  59. usb_id = NULL;
  60. else
  61. - LOG_PROPERTY(ppath, "PRODUCT", product);
  62. + LogMessage(X_INFO, "config/udev: %s usb-id \"%s\"\n",
  63. + path, usb_id);
  64. attrs->usb_id = usb_id;
  65. }
  66. @@ -137,7 +126,8 @@ query_input_name_ids(struct udev_device* parent, InputAttributes* attrs)
  67. if ((pnp_id = udev_device_get_sysattr_value(parent, "id"))) {
  68. attrs->pnp_id = strdup(pnp_id);
  69. ppath = udev_device_get_devnode(parent);
  70. - LOG_SYSATTR(ppath, "id", pnp_id);
  71. + LogMessage(X_INFO, "config/udev: %s pnp-id \"%s\" via %s\n",
  72. + path, pnp_id, ppath);
  73. break;
  74. }
  75. }
  76. @@ -145,26 +135,50 @@ query_input_name_ids(struct udev_device* parent, InputAttributes* attrs)
  77. return name;
  78. }
  79. +static void
  80. +query_input_event_bits(struct udev_device* parent, InputAttributes* attrs,
  81. + const char* path)
  82. +{
  83. + const char* key = udev_device_get_property_value(parent, "KEY");
  84. + const char* rel = udev_device_get_property_value(parent, "REL");
  85. + const char* abs = udev_device_get_property_value(parent, "ABS");
  86. + int flags = 0;
  87. +
  88. + if (abs) {
  89. + LogMessage(X_INFO, "config/udev: %s is a touchpad\n", path);
  90. + flags |= ATTR_TOUCHPAD;
  91. + } else if (rel) {
  92. + LogMessage(X_INFO, "config/udev: %s is a pointer\n", path);
  93. + flags |= ATTR_POINTER;
  94. + } else if (key) {
  95. + LogMessage(X_INFO, "config/udev: %s is a keyboard\n", path);
  96. + flags |= ATTR_KEY | ATTR_KEYBOARD;
  97. + }
  98. +
  99. + attrs->flags |= flags;
  100. +}
  101. +
  102. static void
  103. device_added_input(struct udev_device *udev_device,
  104. const char* path, const char* syspath)
  105. {
  106. const char *name = NULL;
  107. char *config_info = NULL;
  108. - const char *tags_prop;
  109. - const char *key, *value, *tmp;
  110. InputOption *input_options;
  111. InputAttributes attrs = { };
  112. DeviceIntPtr dev = NULL;
  113. - struct udev_list_entry *set, *entry;
  114. int rc;
  115. + const char *sysname = udev_device_get_sysname(udev_device);
  116. struct udev_device *parent = udev_device_get_parent(udev_device);
  117. dev_t devnum = udev_device_get_devnum(udev_device);
  118. - value = udev_device_get_property_value(udev_device, "ID_INPUT");
  119. - if (value && !strcmp(value, "0")) {
  120. - LogMessageVerb(X_INFO, 10, "config/udev: ignoring device %s", path);
  121. + if (asprintf(&config_info, "udev:%s", syspath) == -1)
  122. + return;
  123. +
  124. + if (device_is_duplicate(config_info)) {
  125. + free(config_info);
  126. + LogMessage(X_WARNING, "config/udev: %s already added\n", path);
  127. return;
  128. }
  129. @@ -173,7 +187,9 @@ device_added_input(struct udev_device *udev_device,
  130. return;
  131. if (parent)
  132. - name = query_input_name_ids(parent, &attrs);
  133. + name = query_input_name_ids(parent, &attrs, path);
  134. + if (name)
  135. + LogMessage(X_INFO, "config/udev: %s name \"%s\"\n", path, name);
  136. if (!name)
  137. name = "(unnamed)";
  138. @@ -185,80 +201,8 @@ device_added_input(struct udev_device *udev_device,
  139. if (path)
  140. attrs.device = strdup(path);
  141. - tags_prop = udev_device_get_property_value(udev_device, "ID_INPUT.tags");
  142. - LOG_PROPERTY(path, "ID_INPUT.tags", tags_prop);
  143. - attrs.tags = xstrtokenize(tags_prop, ",");
  144. -
  145. - if (asprintf(&config_info, "udev:%s", syspath) == -1) {
  146. - config_info = NULL;
  147. - goto unwind;
  148. - }
  149. -
  150. - if (device_is_duplicate(config_info)) {
  151. - LogMessage(X_WARNING, "config/udev: device %s already added. ", name);
  152. - goto unwind;
  153. - }
  154. -
  155. - set = udev_device_get_properties_list_entry(udev_device);
  156. - udev_list_entry_foreach(entry, set) {
  157. - key = udev_list_entry_get_name(entry);
  158. - if (!key)
  159. - continue;
  160. - value = udev_list_entry_get_value(entry);
  161. - if (!strncasecmp(key, UDEV_XKB_PROP_KEY, sizeof(UDEV_XKB_PROP_KEY) - 1)) {
  162. - LOG_PROPERTY(path, key, value);
  163. - tmp = key + sizeof(UDEV_XKB_PROP_KEY) - 1;
  164. - if (!strcasecmp(tmp, "rules"))
  165. - input_options =
  166. - input_option_new(input_options, "xkb_rules", value);
  167. - else if (!strcasecmp(tmp, "layout"))
  168. - input_options =
  169. - input_option_new(input_options, "xkb_layout", value);
  170. - else if (!strcasecmp(tmp, "variant"))
  171. - input_options =
  172. - input_option_new(input_options, "xkb_variant", value);
  173. - else if (!strcasecmp(tmp, "model"))
  174. - input_options =
  175. - input_option_new(input_options, "xkb_model", value);
  176. - else if (!strcasecmp(tmp, "options"))
  177. - input_options =
  178. - input_option_new(input_options, "xkb_options", value);
  179. - }
  180. - else if (!strcmp(key, "ID_VENDOR")) {
  181. - LOG_PROPERTY(path, key, value);
  182. - attrs.vendor = strdup(value);
  183. - } else if (!strncmp(key, "ID_INPUT_", 9)) {
  184. - const struct pfmap {
  185. - const char *property;
  186. - unsigned int flag;
  187. - } map[] = {
  188. - { "ID_INPUT_KEY", ATTR_KEY },
  189. - { "ID_INPUT_KEYBOARD", ATTR_KEYBOARD },
  190. - { "ID_INPUT_MOUSE", ATTR_POINTER },
  191. - { "ID_INPUT_JOYSTICK", ATTR_JOYSTICK },
  192. - { "ID_INPUT_TABLET", ATTR_TABLET },
  193. - { "ID_INPUT_TABLET_PAD", ATTR_TABLET_PAD },
  194. - { "ID_INPUT_TOUCHPAD", ATTR_TOUCHPAD },
  195. - { "ID_INPUT_TOUCHSCREEN", ATTR_TOUCHSCREEN },
  196. - { NULL, 0 },
  197. - };
  198. -
  199. - /* Anything but the literal string "0" is considered a
  200. - * boolean true. The empty string isn't a thing with udev
  201. - * properties anyway */
  202. - if (value && strcmp(value, "0")) {
  203. - const struct pfmap *m = map;
  204. -
  205. - while (m->property != NULL) {
  206. - if (!strcmp(m->property, key)) {
  207. - LOG_PROPERTY(path, key, value);
  208. - attrs.flags |= m->flag;
  209. - }
  210. - m++;
  211. - }
  212. - }
  213. - }
  214. - }
  215. + if (sysname && !strncmp(sysname, "event", 5) && parent)
  216. + query_input_event_bits(parent, &attrs, path);
  217. input_options = input_option_new(input_options, "config_info", config_info);
  218. @@ -269,11 +213,10 @@ device_added_input(struct udev_device *udev_device,
  219. rc = NewInputDeviceRequest(input_options, &attrs, &dev);
  220. if (rc != Success)
  221. - LogMessage(X_INFO, "config/udev: cannot add %s (%s)\n", name, path);
  222. + LogMessage(X_INFO, "config/udev: %s cannot be added (%i)\n", path, rc);
  223. else
  224. - LogMessage(X_INFO, "config/udev: adding %s (%s)\n", name, path);
  225. + LogMessage(X_INFO, "config/udev: %s added successfully\n", path);
  226. - unwind:
  227. free(config_info);
  228. input_option_free_list(&input_options);
  229. --
  230. 2.16.1