diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 5e15b2ba1d6..819d5367738 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -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 diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index 4287b1f0660..861dac0fd15 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -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); } diff --git a/src/shared/hwdb-util.c b/src/shared/hwdb-util.c index f67e917b533..648bfc50265 100644 --- a/src/shared/hwdb-util.c +++ b/src/shared/hwdb-util.c @@ -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; +} diff --git a/src/shared/hwdb-util.h b/src/shared/hwdb-util.h index cb93690ee8d..00610b18d49 100644 --- a/src/shared/hwdb-util.h +++ b/src/shared/hwdb-util.h @@ -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); diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 2f5429fd89d..f306a4ffd6d 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -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;