From d6609f828084c47f296ebbd148e823dc576c709b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 18 Sep 2018 23:14:18 +0900 Subject: [PATCH] hwdb,udevadm: also unify hwdb_query() and hwdb_test() --- src/hwdb/hwdb.c | 20 +------------------- src/libsystemd/sd-hwdb/hwdb-util.c | 18 ++++++++++++++++++ src/libsystemd/sd-hwdb/hwdb-util.h | 1 + src/udev/udevadm-hwdb.c | 21 +-------------------- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index eb1e88f..be64a26 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -7,7 +7,6 @@ #include "alloc-util.h" #include "hwdb-util.h" #include "selinux-util.h" -#include "string-util.h" #include "terminal-util.h" #include "util.h" #include "verbs.h" @@ -17,24 +16,7 @@ static const char *arg_root = NULL; static bool arg_strict = false; static int verb_query(int argc, char *argv[], void *userdata) { - _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL; - const char *key, *value; - const char *modalias; - int r; - - assert(argc >= 2); - assert(argv); - - modalias = argv[1]; - - r = sd_hwdb_new(&hwdb); - if (r < 0) - return r; - - SD_HWDB_FOREACH_PROPERTY(hwdb, modalias, key, value) - printf("%s=%s\n", key, value); - - return 0; + return hwdb_query(argv[1]); } static int verb_update(int argc, char *argv[], void *userdata) { diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index 46cc8a4..fe1f93b 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include +#include #include "alloc-util.h" #include "conf-files.h" @@ -659,3 +660,20 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co return r; } + +int hwdb_query(const char *modalias) { + _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL; + const char *key, *value; + int r; + + assert(modalias); + + r = sd_hwdb_new(&hwdb); + if (r < 0) + return r; + + SD_HWDB_FOREACH_PROPERTY(hwdb, modalias, key, value) + printf("%s=%s\n", key, value); + + return 0; +} diff --git a/src/libsystemd/sd-hwdb/hwdb-util.h b/src/libsystemd/sd-hwdb/hwdb-util.h index dac367a..425b4b3 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.h +++ b/src/libsystemd/sd-hwdb/hwdb-util.h @@ -7,3 +7,4 @@ bool hwdb_validate(sd_hwdb *hwdb); int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool compat); +int hwdb_query(const char *modalias); diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 1df7c82..e1a322e 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -2,11 +2,7 @@ #include -#include "sd-hwdb.h" - -#include "alloc-util.h" #include "hwdb-util.h" -#include "string-util.h" #include "udevadm.h" #include "util.h" @@ -16,21 +12,6 @@ static const char *arg_hwdb_bin_dir = NULL; static bool arg_update = false; static bool arg_strict = false; -static int hwdb_test(void) { - _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL; - const char *key, *value; - int r; - - r = sd_hwdb_new(&hwdb); - if (r < 0) - return r; - - SD_HWDB_FOREACH_PROPERTY(hwdb, arg_test, key, value) - printf("%s=%s\n", key, value); - - return 0; -} - static int help(void) { printf("%s hwdb [OPTIONS]\n\n" " -h --help Print this message\n" @@ -117,7 +98,7 @@ int hwdb_main(int argc, char *argv[], void *userdata) { } if (arg_test) - return hwdb_test(); + return hwdb_query(arg_test); return 0; } -- 2.7.4