]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Move hwdb creation code to src/shared/
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 21 Jun 2021 20:10:37 +0000 (22:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 24 Jun 2021 07:47:15 +0000 (09:47 +0200)
hwdb_update() is the main entry point, and it is called from
"udevadm hwdb" and "systemd-hwdb", so it belongs in shared/.

src/libsystemd/meson.build
src/libsystemd/sd-hwdb/hwdb-internal.h
src/libsystemd/sd-hwdb/sd-hwdb.c
src/shared/hwdb-util.c [moved from src/libsystemd/sd-hwdb/hwdb-util.c with 96% similarity]
src/shared/hwdb-util.h [moved from src/libsystemd/sd-hwdb/hwdb-util.h with 100% similarity]
src/shared/meson.build

index 5af8b75af26d8d87a3ae4f8460cdebaaf38ac357..489ed12a73465cc40c287f9cac5eb604223bd09b 100644 (file)
@@ -131,8 +131,6 @@ libsystemd_sources = files('''
         sd-device/device-util.h
         sd-device/sd-device.c
         sd-hwdb/hwdb-internal.h
-        sd-hwdb/hwdb-util.c
-        sd-hwdb/hwdb-util.h
         sd-hwdb/sd-hwdb.c
         sd-netlink/generic-netlink.c
         sd-netlink/generic-netlink.h
index 5c20688cd4b016c4ee7346717563a5c66d3219f6..5ddc2211e62c3a485278888e8d72385880da9092 100644 (file)
@@ -3,10 +3,27 @@
 
 #include <stdint.h>
 
+#include "def.h"
+#include "hashmap.h"
 #include "sparse-endian.h"
 
 #define HWDB_SIG { 'K', 'S', 'L', 'P', 'H', 'H', 'R', 'H' }
 
+struct sd_hwdb {
+        unsigned n_ref;
+
+        FILE *f;
+        struct stat st;
+        union {
+                struct trie_header_f *head;
+                const char *map;
+        };
+
+        OrderedHashmap *properties;
+        Iterator properties_iterator;
+        bool properties_modified;
+};
+
 /* on-disk trie objects */
 struct trie_header_f {
         uint8_t signature[8];
@@ -63,3 +80,10 @@ struct trie_value_entry2_f {
         le16_t file_priority;
         le16_t padding;
 } _packed_;
+
+#define hwdb_bin_paths                          \
+        "/etc/systemd/hwdb/hwdb.bin\0"          \
+        "/etc/udev/hwdb.bin\0"                  \
+        "/usr/lib/systemd/hwdb/hwdb.bin\0"      \
+        _CONF_PATHS_SPLIT_USR_NULSTR("systemd/hwdb/hwdb.bin") \
+        UDEVLIBEXECDIR "/hwdb.bin\0"
index cb3c77ce961ed70788a2c34359f4eae4f274c5cf..53601765fe7f4799c0059532d19f498673cdf27d 100644 (file)
 #include "fd-util.h"
 #include "hashmap.h"
 #include "hwdb-internal.h"
-#include "hwdb-util.h"
 #include "nulstr-util.h"
 #include "string-util.h"
 #include "time-util.h"
 
-struct sd_hwdb {
-        unsigned n_ref;
-
-        FILE *f;
-        struct stat st;
-        union {
-                struct trie_header_f *head;
-                const char *map;
-        };
-
-        OrderedHashmap *properties;
-        Iterator properties_iterator;
-        bool properties_modified;
-};
-
 struct linebuf {
         char bytes[LINE_MAX];
         size_t size;
@@ -296,15 +280,6 @@ static int trie_search_f(sd_hwdb *hwdb, const char *search) {
         return 0;
 }
 
-static const char hwdb_bin_paths[] =
-        "/etc/systemd/hwdb/hwdb.bin\0"
-        "/etc/udev/hwdb.bin\0"
-        "/usr/lib/systemd/hwdb/hwdb.bin\0"
-#if HAVE_SPLIT_USR
-        "/lib/systemd/hwdb/hwdb.bin\0"
-#endif
-        UDEVLIBEXECDIR "/hwdb.bin\0";
-
 _public_ int sd_hwdb_new(sd_hwdb **ret) {
         _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
         const char *hwdb_bin_path;
@@ -372,30 +347,6 @@ static sd_hwdb *hwdb_free(sd_hwdb *hwdb) {
 
 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_hwdb, sd_hwdb, hwdb_free)
 
-bool hwdb_validate(sd_hwdb *hwdb) {
-        bool found = false;
-        const char* p;
-        struct stat st;
-
-        if (!hwdb)
-                return false;
-        if (!hwdb->f)
-                return false;
-
-        /* if hwdb.bin doesn't exist anywhere, we need to update */
-        NULSTR_FOREACH(p, hwdb_bin_paths)
-                if (stat(p, &st) >= 0) {
-                        found = true;
-                        break;
-                }
-        if (!found)
-                return true;
-
-        if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim))
-                return true;
-        return false;
-}
-
 static int properties_prepare(sd_hwdb *hwdb, const char *modalias) {
         assert(hwdb);
         assert(modalias);
similarity index 96%
rename from src/libsystemd/sd-hwdb/hwdb-util.c
rename to src/shared/hwdb-util.c
index 8964a40e38cea38c0d30a2ed0bae03314803c7ac..d7626aed9561622bb5215d7fd5b8c210613cf49c 100644 (file)
@@ -13,6 +13,7 @@
 #include "hwdb-util.h"
 #include "label.h"
 #include "mkdir.h"
+#include "nulstr-util.h"
 #include "path-util.h"
 #include "sort-util.h"
 #include "strbuf.h"
@@ -586,10 +587,10 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
         uint16_t file_priority = 1;
         int r = 0, err;
 
-        /* The argument 'compat' controls the format version of database. If false, then hwdb.bin will be created with
-         * additional information such that priority, line number, and filename of database source. If true, then hwdb.bin
-         * will be created without the information. systemd-hwdb command should set the argument false, and 'udevadm hwdb'
-         * command should set it true. */
+        /* The argument 'compat' controls the format version of database. If false, then hwdb.bin will be
+         * created with additional information such that priority, line number, and filename of database
+         * source. If true, then hwdb.bin will be created without the information. systemd-hwdb command
+         * should set the argument false, and 'udevadm hwdb' command should set it true. */
 
         trie = new0(struct trie, 1);
         if (!trie)
@@ -666,3 +667,27 @@ int hwdb_query(const char *modalias) {
 
         return 0;
 }
+
+bool hwdb_validate(sd_hwdb *hwdb) {
+        bool found = false;
+        const char* p;
+        struct stat st;
+
+        if (!hwdb)
+                return false;
+        if (!hwdb->f)
+                return false;
+
+        /* if hwdb.bin doesn't exist anywhere, we need to update */
+        NULSTR_FOREACH(p, hwdb_bin_paths)
+                if (stat(p, &st) >= 0) {
+                        found = true;
+                        break;
+                }
+        if (!found)
+                return true;
+
+        if (timespec_load(&hwdb->st.st_mtim) != timespec_load(&st.st_mtim))
+                return true;
+        return false;
+}
index 579abcc60297143024c906be69cc4804df4f99c9..c478d46f31e3561837bef2ad6465645590c65ad4 100644 (file)
@@ -129,6 +129,8 @@ shared_sources = files('''
         group-record.h
         hostname-setup.c
         hostname-setup.h
+        hwdb-util.c
+        hwdb-util.h
         id128-print.c
         id128-print.h
         idn-util.c