]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hwdb: implement --root option for systemd-hwdb query 23518/head
authorNick Rosbrook <nick.rosbrook@canonical.com>
Tue, 24 May 2022 17:15:13 +0000 (13:15 -0400)
committerNick Rosbrook <nick.rosbrook@canonical.com>
Fri, 27 May 2022 13:40:54 +0000 (09:40 -0400)
Currently, the systemd-hwdb --root flag only has an effect for the
'update' verb. It would be useful to be able to use the --root option
for the 'query' verb too (e.g. for testing a hwdb.bin created with
systemd-hwdb update --root <path>).

Use sd_hwdb_new_from_path to initialize the hwdb if --root is passed to
systemd-hwdb query.

Note that this functionality was not added to 'udevadm hwdb' since that
command is deprecated.

src/hwdb/hwdb.c
src/shared/hwdb-util.c
src/shared/hwdb-util.h
src/udev/udevadm-hwdb.c

index 17ac7e4fbe080396b85cad374e9a7a7fe3497cc8..6925aecd8493bfd728ffb78db8ec9d978c79c5bb 100644 (file)
@@ -18,7 +18,7 @@ static const char *arg_root = NULL;
 static bool arg_strict = false;
 
 static int verb_query(int argc, char *argv[], void *userdata) {
-        return hwdb_query(argv[1]);
+        return hwdb_query(argv[1], arg_root);
 }
 
 static int verb_update(int argc, char *argv[], void *userdata) {
index f98d03f7669fd7c4ed0a2864d385d95ef9525c51..1ec861f76fe11b2d485f0d4264b47e739ad9e40b 100644 (file)
@@ -650,14 +650,27 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
         return r;
 }
 
-int hwdb_query(const char *modalias) {
+int hwdb_query(const char *modalias, const char *root) {
         _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
-        const char *key, *value;
+        const char *key, *value, *p;
         int r;
 
         assert(modalias);
 
-        r = sd_hwdb_new(&hwdb);
+        if (!isempty(root))
+                NULSTR_FOREACH(p, hwdb_bin_paths) {
+                        _cleanup_free_ char *hwdb_bin = NULL;
+
+                        hwdb_bin = path_join(root, p);
+                        if (!hwdb_bin)
+                                return -ENOMEM;
+
+                        r = sd_hwdb_new_from_path(hwdb_bin, &hwdb);
+                        if (r >= 0)
+                                break;
+                }
+        else
+                r = sd_hwdb_new(&hwdb);
         if (r < 0)
                 return r;
 
index 5afde7472342e947083c8fc7955f5669aabcdcd1..bfecddea421ac3e738cca7799a6d52dbd2ac4bec 100644 (file)
@@ -7,4 +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);
+int hwdb_query(const char *modalias, const char *root);
index 162b3516b81a30eb0d2c2c75e55260dfce68d66e..972cda129df420c73c4750fc82a9fe954a5434ac 100644 (file)
@@ -95,7 +95,7 @@ int hwdb_main(int argc, char *argv[], void *userdata) {
         }
 
         if (arg_test)
-                return hwdb_query(arg_test);
+                return hwdb_query(arg_test, NULL);
 
         return 0;
 }