]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add a few more bypass environment variables
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 28 Feb 2025 16:14:49 +0000 (17:14 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 1 Mar 2025 15:22:53 +0000 (16:22 +0100)
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.

docs/ENVIRONMENT.md
src/kernel-install/kernel-install.c
src/shared/hwdb-util.c
src/shared/verbs.c
src/shared/verbs.h
src/systemctl/systemctl-enable.c
src/systemctl/systemctl-preset-all.c
src/sysusers/sysusers.c
src/tmpfiles/tmpfiles.c

index 6d7287ca48144cc4ca0310210b58c83e6a8ef37a..0976623be9c2eeeb096de105f95280b79a4337bc 100644 (file)
@@ -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
index 899499da4c504440d22eed1cf2c1bf8e4725c012..d4e65f5208777162a4f14f31678b4e71cf8ec032 100644 (file)
@@ -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(
index bc4da846f1bcb604c956b91b3e19284016f895fb..1d80a9f4a514cb002162cfa3ebc452c8b4f659e1 100644 (file)
@@ -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");
 }
index 8442963b37128f0764abd64208c227f32de8ab8b..5b4b0705ac5337c46060dc297216eb3adfe94708 100644 (file)
@@ -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);
 
index 03819e38cd7c046c3533c2327aad1a62fbda0568..3c0ae79d5a7adb3e4f0f7afdb68beffa13aabbbb 100644 (file)
@@ -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);
index ad907650298ef67fa8600e76dd5ccf22cc66ba72..537b6cbb45aff8533fe336156b938ac9f1176ed0 100644 (file)
@@ -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)
index b55f8e35ca74474dcf0d38a6693857ef11be670e..769a73f4d97422b7416d027178a52125462582ef 100644 (file)
@@ -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;
index 8152e5c205b63b90a13925af20a1bb8d0ea66e95..3a2cd5129a542e8f2cf39a7664b624bf40423f44 100644 (file)
@@ -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();
index 231247adbf77bd8d6ad70df55b0fedcd2d6b2887..971e46a032fd488ba7500ff87f434849c052e0f1 100644 (file)
@@ -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();