Add $SYSTEMD_HWDB_UPDATE_BYPASS (#30463)

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=.
This commit is contained in:
Daan De Meyer 2023-12-14 10:57:05 +01:00 committed by GitHub
parent bd546b9b48
commit 3d11b46bf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 1 deletions

View file

@ -249,6 +249,14 @@ All tools:
devices sysfs path are actually backed by sysfs. Relaxing this verification devices sysfs path are actually backed by sysfs. Relaxing this verification
is useful for testing purposes. 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`: `nss-systemd`:
* `$SYSTEMD_NSS_BYPASS_SYNTHETIC=1` — if set, `nss-systemd` won't synthesize * `$SYSTEMD_NSS_BYPASS_SYNTHETIC=1` — if set, `nss-systemd` won't synthesize

View 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) { 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); return hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, false);
} }

View file

@ -6,6 +6,7 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "conf-files.h" #include "conf-files.h"
#include "env-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "fileio.h" #include "fileio.h"
#include "fs-util.h" #include "fs-util.h"
@ -710,3 +711,16 @@ bool hwdb_should_reload(sd_hwdb *hwdb) {
return true; return true;
return false; 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;
}

View file

@ -8,3 +8,4 @@
bool hwdb_should_reload(sd_hwdb *hwdb); bool hwdb_should_reload(sd_hwdb *hwdb);
int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool compat); 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_query(const char *modalias, const char *root);
int hwdb_bypass(void);

View file

@ -89,7 +89,7 @@ int hwdb_main(int argc, char *argv[], void *userdata) {
log_notice("udevadm hwdb is deprecated. Use systemd-hwdb instead."); 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); r = hwdb_update(arg_root, arg_hwdb_bin_dir, arg_strict, true);
if (r < 0) if (r < 0)
return r; return r;