summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-09-18 23:14:18 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-09-19 17:38:07 +0900
commitd6609f828084c47f296ebbd148e823dc576c709b (patch)
tree3fe89b308a253d6b56057360f4afaf8de7919eca
parente3b9fd0a27a831d362a116ee198063c479b46fe8 (diff)
downloadsystemd-d6609f828084c47f296ebbd148e823dc576c709b.tar.gz
hwdb,udevadm: also unify hwdb_query() and hwdb_test()
-rw-r--r--src/hwdb/hwdb.c20
-rw-r--r--src/libsystemd/sd-hwdb/hwdb-util.c18
-rw-r--r--src/libsystemd/sd-hwdb/hwdb-util.h1
-rw-r--r--src/udev/udevadm-hwdb.c21
4 files changed, 21 insertions, 39 deletions
diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index eb1e88fe1c..be64a26d64 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 46cc8a4e89..fe1f93baeb 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 <ctype.h>
+#include <stdio.h>
#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 dac367a76b..425b4b3e13 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 1df7c82dfa..e1a322e545 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -2,11 +2,7 @@
#include <getopt.h>
-#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;
}