diff options
author | Kay Sievers <kay@vrfy.org> | 2013-07-08 11:44:17 +0200 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2013-07-09 03:42:06 -0400 |
commit | 0d950bc04076c1f37b37facd465c40e53a7be556 (patch) | |
tree | 89acc7024309e3eb0ead17b926e0bd0920fc940c /src/udev/udev-builtin-hwdb.c | |
parent | 5084c56432dc6977aca976812fbe28b21bd0d9d1 (diff) |
hwdb: add --lookup-prefix= option
Diffstat (limited to 'src/udev/udev-builtin-hwdb.c')
-rw-r--r-- | src/udev/udev-builtin-hwdb.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/udev/udev-builtin-hwdb.c b/src/udev/udev-builtin-hwdb.c index 36958916c4..314587f2bb 100644 --- a/src/udev/udev-builtin-hwdb.c +++ b/src/udev/udev-builtin-hwdb.c @@ -31,14 +31,26 @@ static struct udev_hwdb *hwdb; int udev_builtin_hwdb_lookup(struct udev_device *dev, - const char *modalias, const char *filter, bool test) { + const char *prefix, const char *modalias, + const char *filter, bool test) { + struct udev_list_entry *list; struct udev_list_entry *entry; int n = 0; if (!hwdb) return -ENOENT; - udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0)) { + if (prefix) { + _cleanup_free_ const char *lookup; + + lookup = strjoin(prefix, modalias, NULL); + if (!lookup) + return -ENOMEM; + list = udev_hwdb_get_properties_list_entry(hwdb, lookup, 0); + } else + list = udev_hwdb_get_properties_list_entry(hwdb, modalias, 0); + + udev_list_entry_foreach(entry, list) { if (filter && fnmatch(filter, udev_list_entry_get_name(entry), FNM_NOESCAPE) != 0) continue; @@ -72,7 +84,8 @@ static const char *modalias_usb(struct udev_device *dev, char *s, size_t size) { } static int udev_builtin_hwdb_search(struct udev_device *dev, struct udev_device *srcdev, - const char *subsystem, const char *filter, bool test) { + const char *subsystem, const char *prefix, + const char *filter, bool test) { struct udev_device *d; char s[16]; int n = 0; @@ -99,7 +112,7 @@ static int udev_builtin_hwdb_search(struct udev_device *dev, struct udev_device if (!modalias) continue; - n = udev_builtin_hwdb_lookup(dev, modalias, filter, test); + n = udev_builtin_hwdb_lookup(dev, prefix, modalias, filter, test); if (n > 0) break; } @@ -112,11 +125,13 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te { "filter", required_argument, NULL, 'f' }, { "device", required_argument, NULL, 'd' }, { "subsystem", required_argument, NULL, 's' }, + { "lookup-prefix", required_argument, NULL, 'p' }, {} }; const char *filter = NULL; const char *device = NULL; const char *subsystem = NULL; + const char *prefix = NULL; struct udev_device *srcdev; if (!hwdb) @@ -125,7 +140,7 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te for (;;) { int option; - option = getopt_long(argc, argv, "s", options, NULL); + option = getopt_long(argc, argv, "f:d:s:p:", options, NULL); if (option == -1) break; @@ -141,12 +156,16 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te case 's': subsystem = optarg; break; + + case 'p': + prefix = optarg; + break; } } /* query a specific key given as argument */ if (argv[optind]) { - if (udev_builtin_hwdb_lookup(dev, argv[optind], filter, test) > 0) + if (udev_builtin_hwdb_lookup(dev, prefix, argv[optind], filter, test) > 0) return EXIT_SUCCESS; return EXIT_FAILURE; } @@ -159,7 +178,7 @@ static int builtin_hwdb(struct udev_device *dev, int argc, char *argv[], bool te } else srcdev = dev; - if (udev_builtin_hwdb_search(dev, srcdev, subsystem, filter, test) < 0) + if (udev_builtin_hwdb_search(dev, srcdev, subsystem, prefix, filter, test) < 0) return EXIT_FAILURE; return EXIT_SUCCESS; } |