]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add $SYSTEMD_HWDB_UPDATE_BYPASS (#30463)
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 14 Dec 2023 09:57:05 +0000 (10:57 +0100)
committerGitHub <noreply@github.com>
Thu, 14 Dec 2023 09:57:05 +0000 (18:57 +0900)
Same as $KERNEL_INSTALL_BYPASS, but for hwdb. This will speed up
cross architecture image builds in mkosi as I can disable package
managers from running the costly hwdb update stuff in qemu user
mode and run it myself with a native systemd-hwdb with --root=.

docs/ENVIRONMENT.md
src/hwdb/hwdb.c
src/shared/hwdb-util.c
src/shared/hwdb-util.h
src/udev/udevadm-hwdb.c

index 5e15b2ba1d62e750433adac6af9ed1992bec209c..819d5367738bf974fe7d9aa944536bfdeebf5b44 100644 (file)
@@ -249,6 +249,14 @@ All tools:
   devices sysfs path are actually backed by sysfs. Relaxing this verification
   is useful for testing purposes.
 
+`udevadm` and `systemd-hwdb`:
+
+* `SYSTEMD_HWDB_UPDATE_BYPASS=` — If set to "1", execution of hwdb updates is skipped
+  when `udevadm hwdb --update` or `systemd-hwdb update` are invoked. This can
+  be useful if either of these tools are invoked unconditionally as a child
+  process by another tool, such as package managers running either of these
+  tools in a postinstall script.
+
 `nss-systemd`:
 
 * `$SYSTEMD_NSS_BYPASS_SYNTHETIC=1` — if set, `nss-systemd` won't synthesize
index 4287b1f066015c11d5a3eccc3b437afe7600094d..861dac0fd154ca5e8bb9ea46c613b98d81f2014d 100644 (file)
@@ -22,6 +22,9 @@ static int verb_query(int argc, char *argv[], void *userdata) {
 }
 
 static int verb_update(int argc, char *argv[], void *userdata) {
+        if (hwdb_bypass())
+                return 0;
+
         return hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, false);
 }
 
index f67e917b533c36316a4bb8b7aea6ca7a3774e053..648bfc502655ee8df566de33ccc52edb3dea1627 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "alloc-util.h"
 #include "conf-files.h"
+#include "env-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
@@ -710,3 +711,16 @@ bool hwdb_should_reload(sd_hwdb *hwdb) {
                 return true;
         return false;
 }
+
+int hwdb_bypass(void) {
+        int r;
+
+        r = getenv_bool("SYSTEMD_HWDB_UPDATE_BYPASS");
+        if (r < 0 && r != -ENXIO)
+                log_debug_errno(r, "Failed to parse $SYSTEMD_HWDB_UPDATE_BYPASS, assuming no.");
+        if (r <= 0)
+                return false;
+
+        log_debug("$SYSTEMD_HWDB_UPDATE_BYPASS is enabled, skipping execution.");
+        return true;
+}
index cb93690ee8ddadb5e3e410cfffbeec6ef4793082..00610b18d49364158e4ed6574b20f6fa38bba6d7 100644 (file)
@@ -8,3 +8,4 @@
 bool hwdb_should_reload(sd_hwdb *hwdb);
 int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool compat);
 int hwdb_query(const char *modalias, const char *root);
+int hwdb_bypass(void);
index 2f5429fd89d1e9f7ff0043c127a851bdb3079ea8..f306a4ffd6d82975d078be0c5eb010f0f69c923c 100644 (file)
@@ -89,7 +89,7 @@ int hwdb_main(int argc, char *argv[], void *userdata) {
 
         log_notice("udevadm hwdb is deprecated. Use systemd-hwdb instead.");
 
-        if (arg_update) {
+        if (arg_update && !hwdb_bypass()) {
                 r = hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, true);
                 if (r < 0)
                         return r;