From: Daan De Meyer Date: Fri, 28 Feb 2025 16:14:49 +0000 (+0100) Subject: Add a few more bypass environment variables X-Git-Tag: v258-rc1~1211 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=daa2547e3103eca3128fa179b349d3d45d9b6c0f;p=thirdparty%2Fsystemd.git Add a few more bypass environment variables When we're building ParticleOS images, we don't want the package manager (or mkosi) to run systemd-sysusers, systemd-tmpfiles or systemctl preset so let's add a few more bypass environment variables that we can set to have execution of these skipped like we already have $SYSTEMD_HWDB_UPDATE_BYPASS and $KERNEL_INSTALL_BYPASS. --- diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index 6d7287ca481..0976623be9c 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -143,6 +143,11 @@ All tools: instead of reboot when a new root file system has been loaded in `/run/nextroot/`. +* `SYSTEMD_PRESET_BYPASS=1` — If set, execution of `systemctl preset` and + `systemctl preset-all` is skipped. This can be useful if either of these is + invoked unconditionally as a child process by another tool, such as package + managers running it in a postinstall script. + `systemd-nspawn`: * `$SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=1` — if set, force `systemd-nspawn` into @@ -408,6 +413,11 @@ All tools: subvolumes if the backing filesystem supports them. If set to `0`, these lines will always create directories. +* `SYSTEMD_TMPFILES_BYPASS=1` — If set, execution of `systemd-tmpfiles` is + skipped. This can be useful if `systemd-tmpfiles` is invoked unconditionally + as a child process by another tool, such as package managers running it in a + postinstall script. + `systemd-sysusers`: * `$SOURCE_DATE_EPOCH` — if unset, the field of the date of last password change @@ -418,6 +428,11 @@ All tools: reproducible value for the field of the date of last password change in `/etc/shadow`. See: https://reproducible-builds.org/specs/source-date-epoch/ +* `SYSTEMD_SYSUSERS_BYPASS=1` — If set, execution of `systemd-sysusers` is + skipped. This can be useful if `systemd-sysusers` is invoked unconditionally + as a child process by another tool, such as package managers running it in a + postinstall script. + `systemd-sysv-generator`: * `$SYSTEMD_SYSVINIT_PATH` — Controls where `systemd-sysv-generator` looks for diff --git a/src/kernel-install/kernel-install.c b/src/kernel-install/kernel-install.c index 899499da4c5..d4e65f52087 100644 --- a/src/kernel-install/kernel-install.c +++ b/src/kernel-install/kernel-install.c @@ -1057,16 +1057,7 @@ static int context_execute(Context *c) { } static bool bypass(void) { - int r; - - r = getenv_bool("KERNEL_INSTALL_BYPASS"); - if (r < 0 && r != -ENXIO) - log_debug_errno(r, "Failed to parse $KERNEL_INSTALL_BYPASS, assuming no."); - if (r <= 0) - return false; - - log_debug("$KERNEL_INSTALL_BYPASS is enabled, skipping execution."); - return true; + return should_bypass("KERNEL_INSTALL"); } static int do_add( diff --git a/src/shared/hwdb-util.c b/src/shared/hwdb-util.c index bc4da846f1b..1d80a9f4a51 100644 --- a/src/shared/hwdb-util.c +++ b/src/shared/hwdb-util.c @@ -21,6 +21,7 @@ #include "string-util.h" #include "strv.h" #include "tmpfile-util.h" +#include "verbs.h" static const char* const conf_file_dirs[] = { "/etc/udev/hwdb.d", @@ -707,14 +708,5 @@ bool hwdb_should_reload(sd_hwdb *hwdb) { } 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; + return should_bypass("SYSTEMD_HWDB_UPDATE"); } diff --git a/src/shared/verbs.c b/src/shared/verbs.c index 8442963b371..5b4b0705ac5 100644 --- a/src/shared/verbs.c +++ b/src/shared/verbs.c @@ -44,6 +44,24 @@ bool running_in_chroot_or_offline(void) { return r > 0; } +bool should_bypass(const char *env_prefix) { + char *env; + int r; + + assert(env_prefix); + + env = strjoina(env_prefix, "_BYPASS"); + + r = getenv_bool(env); + if (r < 0 && r != -ENXIO) + log_debug_errno(r, "Failed to parse $%s, assuming no: %m", env); + if (r <= 0) + return false; + + log_debug("$%s is enabled, skipping execution.", env); + return true; +} + const Verb* verbs_find_verb(const char *name, const Verb verbs[]) { assert(verbs); diff --git a/src/shared/verbs.h b/src/shared/verbs.h index 03819e38cd7..3c0ae79d5a7 100644 --- a/src/shared/verbs.h +++ b/src/shared/verbs.h @@ -19,5 +19,7 @@ typedef struct { bool running_in_chroot_or_offline(void); +bool should_bypass(const char *env_prefix); + const Verb* verbs_find_verb(const char *name, const Verb verbs[]); int dispatch_verb(int argc, char *argv[], const Verb verbs[], void *userdata); diff --git a/src/systemctl/systemctl-enable.c b/src/systemctl/systemctl-enable.c index ad907650298..537b6cbb45a 100644 --- a/src/systemctl/systemctl-enable.c +++ b/src/systemctl/systemctl-enable.c @@ -9,6 +9,7 @@ #include "systemctl-sysv-compat.h" #include "systemctl-util.h" #include "systemctl.h" +#include "verbs.h" static int normalize_link_paths(char **paths) { int r; @@ -75,6 +76,9 @@ int verb_enable(int argc, char *argv[], void *userdata) { sd_bus *bus = NULL; int r; + if (streq(verb, "preset") && should_bypass("SYSTEMD_PRESET")) + return 0; + const char *operation = strjoina("to ", verb); r = mangle_names(operation, ASSERT_PTR(strv_skip(argv, 1)), &names); if (r < 0) diff --git a/src/systemctl/systemctl-preset-all.c b/src/systemctl/systemctl-preset-all.c index b55f8e35ca7..769a73f4d97 100644 --- a/src/systemctl/systemctl-preset-all.c +++ b/src/systemctl/systemctl-preset-all.c @@ -6,10 +6,14 @@ #include "systemctl-preset-all.h" #include "systemctl-util.h" #include "systemctl.h" +#include "verbs.h" int verb_preset_all(int argc, char *argv[], void *userdata) { int r; + if (should_bypass("SYSTEMD_PRESET")) + return 0; + if (install_client_side()) { InstallChange *changes = NULL; size_t n_changes = 0; diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 8152e5c205b..3a2cd5129a5 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -38,6 +38,7 @@ #include "uid-range.h" #include "user-util.h" #include "utf8.h" +#include "verbs.h" typedef enum ItemType { ADD_USER = 'u', @@ -2282,6 +2283,9 @@ static int run(int argc, char *argv[]) { if (arg_cat_flags != CAT_CONFIG_OFF) return cat_config(); + if (should_bypass("SYSTEMD_SYSUSERS")) + return 0; + umask(0022); r = mac_init(); diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 231247adbf7..971e46a032f 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -71,6 +71,7 @@ #include "terminal-util.h" #include "umask-util.h" #include "user-util.h" +#include "verbs.h" #include "virt.h" #include "xattr-util.h" @@ -4618,6 +4619,9 @@ static int run(int argc, char *argv[]) { if (arg_cat_flags != CAT_CONFIG_OFF) return cat_config(config_dirs, argv + optind); + if (should_bypass("SYSTEMD_TMPFILES")) + return 0; + umask(0022); r = mac_init();