diff options
author | Kay Sievers <kay.sievers@vrfy.org> | 2011-12-27 17:02:52 +0100 |
---|---|---|
committer | Kay Sievers <kay.sievers@vrfy.org> | 2011-12-27 17:02:52 +0100 |
commit | 3cf5266b029c1ec4522edc6b42d874d80407a246 (patch) | |
tree | 32d1502bddbc5ba62fc5f458d14379c4518996df | |
parent | 86a0d004c397d985505c5204fe1fbecb340f6076 (diff) |
builtin: move usb-db, pci-db to builtins
-rw-r--r-- | Makefile.am | 26 | ||||
-rw-r--r-- | configure.ac | 78 | ||||
-rw-r--r-- | extras/usb-db/.gitignore | 2 | ||||
-rw-r--r-- | rules/rules.d/75-net-description.rules | 4 | ||||
-rw-r--r-- | rules/rules.d/75-tty-description.rules | 4 | ||||
-rw-r--r-- | rules/rules.d/78-sound-card.rules | 4 | ||||
-rw-r--r-- | udev/udev-builtin-hwdb.c (renamed from extras/usb-db/usb-db.c) | 134 | ||||
-rw-r--r-- | udev/udev-builtin.c | 2 | ||||
-rw-r--r-- | udev/udev.h | 4 |
9 files changed, 114 insertions, 144 deletions
diff --git a/Makefile.am b/Makefile.am index a7f29676a2..d95a3619a9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -151,6 +151,9 @@ dist_udevrules_DATA = \ rules/rules.d/60-persistent-input.rules \ rules/rules.d/60-persistent-alsa.rules \ rules/rules.d/60-persistent-storage.rules \ + rules/rules.d/75-net-description.rules \ + rules/rules.d/75-tty-description.rules \ + rules/rules.d/78-sound-card.rules \ rules/rules.d/80-drivers.rules \ rules/rules.d/95-udev-late.rules @@ -209,6 +212,7 @@ udev_common_sources = \ udev/udev-builtin.c \ udev/udev-builtin-blkid.c \ udev/udev-builtin-firmware.c \ + udev/udev-builtin-hwdb.c \ udev/udev-builtin-input_id.c \ udev/udev-builtin-kmod.c \ udev/udev-builtin-path_id.c \ @@ -225,7 +229,8 @@ udev_common_LDADD = \ udev_common_CPPFLAGS = \ $(AM_CPPFLAGS) \ - -DFIRMWARE_PATH="$(FIRMWARE_PATH)" + -DFIRMWARE_PATH="$(FIRMWARE_PATH)" \ + -DUSB_DATABASE=\"$(USB_DATABASE)\" -DPCI_DATABASE=\"$(PCI_DATABASE)\" udev_udevd_SOURCES = \ $(udev_common_sources) \ @@ -505,25 +510,6 @@ INSTALL_EXEC_HOOKS += libgudev-install-move-hook UNINSTALL_EXEC_HOOKS += libgudev-uninstall-move-hook endif -if ENABLE_HWDB -# ------------------------------------------------------------------------------ -# usb/pci-db - read vendor/device string database -# ------------------------------------------------------------------------------ -extras_usb_db_usb_db_SOURCES = extras/usb-db/usb-db.c -extras_usb_db_usb_db_CPPFLAGS = $(AM_CPPFLAGS) -DUSB_DATABASE=\"$(USB_DATABASE)\" -DBUILD_FOR_USB -extras_usb_db_usb_db_LDADD = libudev/libudev-private.la -libexec_PROGRAMS += extras/usb-db/usb-db -dist_udevrules_DATA += \ - rules/rules.d/75-net-description.rules \ - rules/rules.d/75-tty-description.rules \ - rules/rules.d/78-sound-card.rules - -extras_usb_db_pci_db_SOURCES = extras/usb-db/usb-db.c -extras_usb_db_pci_db_CPPFLAGS = $(AM_CPPFLAGS) -DPCI_DATABASE=\"$(PCI_DATABASE)\" -DBUILD_FOR_PCI -extras_usb_db_pci_db_LDADD = libudev/libudev-private.la -libexec_PROGRAMS += extras/usb-db/pci-db -endif - if ENABLE_KEYMAP # ------------------------------------------------------------------------------ # keymap - map custom hardware's multimedia keys diff --git a/configure.ac b/configure.ac index a9ba74c1f6..497a74fc0a 100644 --- a/configure.ac +++ b/configure.ac @@ -20,9 +20,42 @@ AC_PREFIX_DEFAULT([/usr]) AC_PATH_PROG([XSLTPROC], [xsltproc]) AC_SEARCH_LIBS([clock_gettime], [rt], [], [AC_MSG_ERROR([POSIX RT library not found])]) + PKG_CHECK_MODULES(BLKID, blkid >= 2.20) + PKG_CHECK_MODULES(KMOD, libkmod >= 2) +if test "x$cross_compiling" = "xno" ; then + AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids]) + AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids]) + AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids]) +fi + +AC_ARG_WITH(usb-ids-path, + [AS_HELP_STRING([--with-usb-ids-path=DIR], [Path to usb.ids file])], + [USB_DATABASE=${withval}], + [if test -n "$usbids" ; then + USB_DATABASE="$usbids" + else + PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82) + AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)]) + fi]) +AC_MSG_CHECKING([for USB database location]) +AC_MSG_RESULT([$USB_DATABASE]) +AC_SUBST(USB_DATABASE) + +AC_ARG_WITH(pci-ids-path, + [AS_HELP_STRING([--with-pci-ids-path=DIR], [Path to pci.ids file])], + [PCI_DATABASE=${withval}], + [if test -n "$pciids" ; then + PCI_DATABASE="$pciids" + else + AC_MSG_ERROR([pci.ids not found, try --with-pci-ids-path=]) + fi]) +AC_MSG_CHECKING([for PCI database location]) +AC_MSG_RESULT([$PCI_DATABASE]) +AC_SUBST(PCI_DATABASE) + AC_ARG_WITH([rootprefix], AS_HELP_STRING([--with-rootprefix=DIR], [rootfs directory prefix for config files and kernel modules]), [], [with_rootprefix=$prefix]) @@ -104,46 +137,6 @@ AM_CONDITIONAL([ENABLE_INTROSPECTION], [test "x$enable_introspection" = "xyes"]) AM_CONDITIONAL([ENABLE_GUDEV], [test "x$enable_gudev" = "xyes"]) # ------------------------------------------------------------------------------ -# usb/pci-db - read vendor/device string database -# ------------------------------------------------------------------------------ -AC_ARG_ENABLE([hwdb], - AS_HELP_STRING([--disable-hwdb], [disable hardware database support @<:@default=enabled@:>@]), - [], [enable_hwdb=yes]) -AS_IF([test "x$enable_hwdb" = "xyes"], [ - if test "x$cross_compiling" = "xno" ; then - AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids]) - AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids]) - AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids]) - fi - - AC_ARG_WITH(usb-ids-path, - [AS_HELP_STRING([--with-usb-ids-path=DIR], [Path to usb.ids file])], - [USB_DATABASE=${withval}], - [if test -n "$usbids" ; then - USB_DATABASE="$usbids" - else - PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82) - AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)]) - fi]) - AC_MSG_CHECKING([for USB database location]) - AC_MSG_RESULT([$USB_DATABASE]) - AC_SUBST(USB_DATABASE) - - AC_ARG_WITH(pci-ids-path, - [AS_HELP_STRING([--with-pci-ids-path=DIR], [Path to pci.ids file])], - [PCI_DATABASE=${withval}], - [if test -n "$pciids" ; then - PCI_DATABASE="$pciids" - else - AC_MSG_ERROR([pci.ids not found, try --with-pci-ids-path=]) - fi]) - AC_MSG_CHECKING([for PCI database location]) - AC_MSG_RESULT([$PCI_DATABASE]) - AC_SUBST(PCI_DATABASE) -]) -AM_CONDITIONAL([ENABLE_HWDB], [test "x$enable_hwdb" = "xyes"]) - -# ------------------------------------------------------------------------------ # keymap - map custom hardware's multimedia keys # ------------------------------------------------------------------------------ AC_ARG_ENABLE([keymap], @@ -241,6 +234,8 @@ AC_MSG_RESULT([ include_prefix: ${INCLUDE_PREFIX} systemdsystemunitdir: ${systemdsystemunitdir} firmware path: ${FIRMWARE_PATH} + usb.ids: ${USB_DATABASE} + pci.ids: ${PCI_DATABASE} compiler: ${CC} cflags: ${CFLAGS} @@ -255,9 +250,6 @@ AC_MSG_RESULT([ gudev: ${enable_gudev} gintrospection: ${enable_introspection} keymap: ${enable_keymap} - hwdb: ${enable_hwdb} - usb.ids: ${USB_DATABASE} - pci.ids: ${PCI_DATABASE} mtd_probe: ${enable_mtd_probe} rule_generator: ${enable_rule_generator} udev_acl: ${enable_udev_acl} diff --git a/extras/usb-db/.gitignore b/extras/usb-db/.gitignore deleted file mode 100644 index 861a8382a6..0000000000 --- a/extras/usb-db/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -usb-db -pci-db diff --git a/rules/rules.d/75-net-description.rules b/rules/rules.d/75-net-description.rules index 0ffce2c348..ce57d48e86 100644 --- a/rules/rules.d/75-net-description.rules +++ b/rules/rules.d/75-net-description.rules @@ -4,11 +4,11 @@ ACTION=="remove", GOTO="net_end" SUBSYSTEM!="net", GOTO="net_end" SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{builtin}="usb_id" -SUBSYSTEMS=="usb", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="usb-db %p" +SUBSYSTEMS=="usb", IMPORT{builtin}="usb-db" SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}" SUBSYSTEMS=="usb", GOTO="net_end" -SUBSYSTEMS=="pci", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="pci-db %p" +SUBSYSTEMS=="pci", IMPORT{builtin}="pci-db" SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}" LABEL="net_end" diff --git a/rules/rules.d/75-tty-description.rules b/rules/rules.d/75-tty-description.rules index b67c857dfd..2e63e140cb 100644 --- a/rules/rules.d/75-tty-description.rules +++ b/rules/rules.d/75-tty-description.rules @@ -4,11 +4,11 @@ ACTION=="remove", GOTO="tty_end" SUBSYSTEM!="tty", GOTO="tty_end" SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{builtin}="usb_id" -SUBSYSTEMS=="usb", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="usb-db %p" +SUBSYSTEMS=="usb", IMPORT{builtin}="usb-db" SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}" SUBSYSTEMS=="usb", GOTO="tty_end" -SUBSYSTEMS=="pci", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="pci-db %p" +SUBSYSTEMS=="pci", IMPORT{builtin}="pci-db" SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}" LABEL="tty_end" diff --git a/rules/rules.d/78-sound-card.rules b/rules/rules.d/78-sound-card.rules index e3a13b598d..cca88f1ec3 100644 --- a/rules/rules.d/78-sound-card.rules +++ b/rules/rules.d/78-sound-card.rules @@ -38,10 +38,10 @@ KERNEL!="card*", GOTO="sound_end" ENV{SOUND_INITIALIZED}="1" SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id" -SUBSYSTEMS=="usb", ENV{ID_VENDOR_FROM_DATABASE}=="", IMPORT{program}="usb-db %p" +SUBSYSTEMS=="usb", IMPORT{builtin}="usb-db" SUBSYSTEMS=="usb", GOTO="skip_pci" -SUBSYSTEMS=="pci", ENV{ID_VENDOR_FROM_DATABASE}=="", IMPORT{program}="pci-db %p" +SUBSYSTEMS=="pci", IMPORT{builtin}="pci-db" SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}" LABEL="skip_pci" diff --git a/extras/usb-db/usb-db.c b/udev/udev-builtin-hwdb.c index fe563c2e75..e38c6b9d26 100644 --- a/extras/usb-db/usb-db.c +++ b/udev/udev-builtin-hwdb.c @@ -1,15 +1,21 @@ /* + * usb-db, pci-db - lookup vendor/product database + * * Copyright (C) 2009 Lennart Poettering <lennart@poettering.net> + * Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details: + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <stdio.h> @@ -19,23 +25,7 @@ #include <ctype.h> #include <stdlib.h> -#include <libudev.h> - -#if defined(BUILD_FOR_USB) -# define DATABASE USB_DATABASE -# define SUBSYSTEM "usb" -# define DEVTYPE "usb_device" -# define VENDOR_ATTR "idVendor" -# define PRODUCT_ATTR "idProduct" -#elif defined(BUILD_FOR_PCI) -# define DATABASE PCI_DATABASE -# define SUBSYSTEM "pci" -# define DEVTYPE NULL -# define VENDOR_ATTR "vendor" -# define PRODUCT_ATTR "device" -#else -# error "Are you havin' a laugh?" -#endif +#include "udev.h" static int get_id_attr( struct udev_device *parent, @@ -64,17 +54,19 @@ static int get_id_attr( static int get_vid_pid( struct udev_device *parent, + const char *vendor_attr, + const char *product_attr, uint16_t *vid, uint16_t *pid) { - if (get_id_attr(parent, VENDOR_ATTR, vid) < 0) + if (get_id_attr(parent, vendor_attr, vid) < 0) return -1; else if (*vid <= 0) { fprintf(stderr, "Invalid vendor id.\n"); return -1; } - if (get_id_attr(parent, PRODUCT_ATTR, pid) < 0) + if (get_id_attr(parent, product_attr, pid) < 0) return -1; return 0; @@ -89,12 +81,10 @@ static void rstrip(char *n) { #define HEXCHARS "0123456789abcdefABCDEF" #define WHITESPACE " \t\n\r" - -static int lookup_vid_pid( - uint16_t vid, - uint16_t pid, - char **vendor, - char **product) { +static int lookup_vid_pid(const char *database, + uint16_t vid, uint16_t pid, + char **vendor, char **product) +{ FILE *f; int ret = -1; @@ -103,8 +93,8 @@ static int lookup_vid_pid( *vendor = *product = NULL; - if (!(f = fopen(DATABASE, "r"))) { - fprintf(stderr, "Failed to open database file "DATABASE": %s\n", strerror(errno)); + if (!(f = fopen(database, "rme"))) { + fprintf(stderr, "Failed to open database file '%s': %s\n", database, strerror(errno)); return -1; } @@ -201,64 +191,62 @@ static struct udev_device *find_device(struct udev_device *dev, const char *subs } return dev; try_parent: - return udev_device_get_parent_with_subsystem_devtype(dev, SUBSYSTEM, DEVTYPE); + return udev_device_get_parent_with_subsystem_devtype(dev, subsys, devtype); } -int main(int argc, char*argv[]) { - struct udev *udev = NULL; - int ret = 1; - char *sp; - struct udev_device *dev = NULL, *parent = NULL; +static int builtin_db(struct udev_device *dev, bool test, + const char *database, + const char *vendor_attr, const char *product_attr, + const char *subsys, const char *devtype) +{ + struct udev_device *parent; uint16_t vid = 0, pid = 0; char *vendor = NULL, *product = NULL; - if (argc < 2) { - fprintf(stderr, "Need to pass sysfs path.\n"); - goto finish; - } - - if (!(udev = udev_new())) - goto finish; - - if (asprintf(&sp, "%s%s", udev_get_sys_path(udev), argv[1]) < 0) { - fprintf(stderr, "Failed to allocate sysfs path.\n"); - goto finish; - } - - dev = udev_device_new_from_syspath(udev, sp); - free(sp); - - if (!dev) { - fprintf(stderr, "Failed to access %s.\n", argv[1]); - goto finish; - } - - parent = find_device(dev, SUBSYSTEM, DEVTYPE); + parent = find_device(dev, subsys, devtype); if (!parent) { fprintf(stderr, "Failed to find device.\n"); goto finish; } - if (get_vid_pid(parent, &vid, &pid) < 0) + if (get_vid_pid(parent, vendor_attr, product_attr, &vid, &pid) < 0) goto finish; - if (lookup_vid_pid(vid, pid, &vendor, &product) < 0) + if (lookup_vid_pid(database, vid, pid, &vendor, &product) < 0) goto finish; if (vendor) - printf("ID_VENDOR_FROM_DATABASE=%s\n", vendor); - + udev_builtin_add_property(dev, test, "ID_VENDOR_FROM_DATABASE", vendor); if (product) - printf("ID_MODEL_FROM_DATABASE=%s\n", product); - - ret = 0; + udev_builtin_add_property(dev, test, "ID_MODEL_FROM_DATABASE", product); finish: - udev_device_unref(dev); - udev_unref(udev); free(vendor); free(product); + return 0; +} - return ret; +static int builtin_usb_db(struct udev_device *dev, int argc, char *argv[], bool test) +{ + return builtin_db(dev, test, USB_DATABASE, "idVendor", "idProduct", "usb", "usb_device"); } + +static int builtin_pci_db(struct udev_device *dev, int argc, char *argv[], bool test) +{ + return builtin_db(dev, test, PCI_DATABASE, "vendor", "device", "pci", NULL); +} + +const struct udev_builtin udev_builtin_usb_db = { + .name = "usb-db", + .cmd = builtin_usb_db, + .help = "USB vendor/product database", + .run_once = true, +}; + +const struct udev_builtin udev_builtin_pci_db = { + .name = "pci-db", + .cmd = builtin_pci_db, + .help = "PCI vendor/product database", + .run_once = true, +}; diff --git a/udev/udev-builtin.c b/udev/udev-builtin.c index 9804c50fae..8beac8a678 100644 --- a/udev/udev-builtin.c +++ b/udev/udev-builtin.c @@ -31,6 +31,8 @@ static const struct udev_builtin *builtins[] = { [UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id, [UDEV_BUILTIN_KMOD] = &udev_builtin_kmod, [UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id, + [UDEV_BUILTIN_PCI_DB] = &udev_builtin_pci_db, + [UDEV_BUILTIN_USB_DB] = &udev_builtin_usb_db, [UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id, }; diff --git a/udev/udev.h b/udev/udev.h index a289f35c4d..4f2886c69c 100644 --- a/udev/udev.h +++ b/udev/udev.h @@ -138,6 +138,8 @@ enum udev_builtin_cmd { UDEV_BUILTIN_INPUT_ID, UDEV_BUILTIN_KMOD, UDEV_BUILTIN_PATH_ID, + UDEV_BUILTIN_PCI_DB, + UDEV_BUILTIN_USB_DB, UDEV_BUILTIN_USB_ID, UDEV_BUILTIN_MAX }; @@ -155,6 +157,8 @@ extern const struct udev_builtin udev_builtin_firmware; extern const struct udev_builtin udev_builtin_input_id; extern const struct udev_builtin udev_builtin_kmod; extern const struct udev_builtin udev_builtin_path_id; +extern const struct udev_builtin udev_builtin_pci_db; +extern const struct udev_builtin udev_builtin_usb_db; extern const struct udev_builtin udev_builtin_usb_id; int udev_builtin_init(struct udev *udev); void udev_builtin_exit(struct udev *udev); |