]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hwdb,udevadm: also unify hwdb_query() and hwdb_test() 10113/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 18 Sep 2018 14:14:18 +0000 (23:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Sep 2018 08:38:07 +0000 (17:38 +0900)
src/hwdb/hwdb.c
src/libsystemd/sd-hwdb/hwdb-util.c
src/libsystemd/sd-hwdb/hwdb-util.h
src/udev/udevadm-hwdb.c

index eb1e88fe1cb2ba7ec2ecdbf9c0eeb44c0c28ff6e..be64a26d64ff70258bf783eac2ffe0829ee903ba 100644 (file)
@@ -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) {
index 46cc8a4e898f6c8a51c5c820b448b1de3a4d5420..fe1f93baeb429bccf0e51310da2821f6ac9945df 100644 (file)
@@ -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;
+}
index dac367a76b6b2d240116da7078578e5a66a8d7ca..425b4b3e1332775fca915dde69e8b0215fd80d3b 100644 (file)
@@ -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);
index 1df7c82dfa7e0b22177b0570047eda784d71c36e..e1a322e54527457a4f639627a48b9f4603037fb0 100644 (file)
@@ -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;
 }