diff --git a/man/hwdb-usb-device.c b/man/hwdb-usb-device.c new file mode 100644 index 00000000000..8a4b86e7bd1 --- /dev/null +++ b/man/hwdb-usb-device.c @@ -0,0 +1,28 @@ +#include +#include +#include + +int print_usb_properties(uint16_t vid, uint16_t pid) { + char match[15]; + sd_hwdb *hwdb; + const char *key, *value; + int r; + + /* Match this USB vendor and product ID combination */ + snprintf(match, sizeof match, "usb:v%04Xp%04X", vid, pid); + + r = sd_hwdb_new(&hwdb); + if (r < 0) + return r; + + SD_HWDB_FOREACH_PROPERTY(hwdb, match, key, value) + printf("%s: \"%s\" → \"%s\"\n", match, key, value); + + sd_hwdb_unref(hwdb); + return 0; +} + +int main(int argc, char **argv) { + print_usb_properties(0x046D, 0xC534); + return 0; +} diff --git a/man/rules/meson.build b/man/rules/meson.build index d3457e7ccc9..8c20c865447 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -560,7 +560,10 @@ manpages = [ '3', ['sd_get_machine_names', 'sd_get_sessions', 'sd_get_uids'], 'HAVE_PAM'], - ['sd_hwdb_get', '3', ['sd_hwdb_enumerate', 'sd_hwdb_seek'], ''], + ['sd_hwdb_get', + '3', + ['SD_HWDB_FOREACH_PROPERTY', 'sd_hwdb_enumerate', 'sd_hwdb_seek'], + ''], ['sd_hwdb_new', '3', ['sd_hwdb_ref', 'sd_hwdb_unref'], ''], ['sd_id128_get_machine', '3', diff --git a/man/sd_hwdb_get.xml b/man/sd_hwdb_get.xml index b5c5b1cc6f0..58e6e57e0fd 100644 --- a/man/sd_hwdb_get.xml +++ b/man/sd_hwdb_get.xml @@ -18,6 +18,7 @@ sd_hwdb_get sd_hwdb_seek sd_hwdb_enumerate + SD_HWDB_FOREACH_PROPERTY Seek to a location in hwdb or access entries @@ -47,6 +48,13 @@ const char **value + + SD_HWDB_FOREACH_PROPERTY + hwdb + modalias + key + value + @@ -75,6 +83,10 @@ modalias, the combination of all matching key-value pairs is used. See hwdb7 for details. + + The SD_HWDB_FOREACH_PROPERTY macro combines + sd_hwdb_seek() and sd_hwdb_enumerate(). No error handling is + performed and interation simply stops on error. See the example below. @@ -118,6 +130,19 @@ + + Examples + + + Look up hwdb entries for a USB device + + + + The effect is similar to calling systemd-hwdb query usb:v046DpC534. + + + + See Also