From: Zbigniew Jędrzejewski-Szmek Date: Mon, 21 Jun 2021 20:10:37 +0000 (+0200) Subject: Move hwdb creation code to src/shared/ X-Git-Tag: v249-rc2~23^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37350b81b5ce7c94636ea637a84af479132b6726;p=thirdparty%2Fsystemd.git Move hwdb creation code to src/shared/ hwdb_update() is the main entry point, and it is called from "udevadm hwdb" and "systemd-hwdb", so it belongs in shared/. --- diff --git a/src/libsystemd/meson.build b/src/libsystemd/meson.build index 5af8b75af26..489ed12a734 100644 --- a/src/libsystemd/meson.build +++ b/src/libsystemd/meson.build @@ -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 diff --git a/src/libsystemd/sd-hwdb/hwdb-internal.h b/src/libsystemd/sd-hwdb/hwdb-internal.h index 5c20688cd4b..5ddc2211e62 100644 --- a/src/libsystemd/sd-hwdb/hwdb-internal.h +++ b/src/libsystemd/sd-hwdb/hwdb-internal.h @@ -3,10 +3,27 @@ #include +#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" diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c index cb3c77ce961..53601765fe7 100644 --- a/src/libsystemd/sd-hwdb/sd-hwdb.c +++ b/src/libsystemd/sd-hwdb/sd-hwdb.c @@ -17,26 +17,10 @@ #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); diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/shared/hwdb-util.c similarity index 96% rename from src/libsystemd/sd-hwdb/hwdb-util.c rename to src/shared/hwdb-util.c index 8964a40e38c..d7626aed956 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/shared/hwdb-util.c @@ -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; +} diff --git a/src/libsystemd/sd-hwdb/hwdb-util.h b/src/shared/hwdb-util.h similarity index 100% rename from src/libsystemd/sd-hwdb/hwdb-util.h rename to src/shared/hwdb-util.h diff --git a/src/shared/meson.build b/src/shared/meson.build index 579abcc6029..c478d46f31e 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -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