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.
This commit is contained in:
Daan De Meyer
2025-02-28 17:14:49 +01:00
parent 38701809a8
commit daa2547e31
9 changed files with 54 additions and 20 deletions

View 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

View 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(

View 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");
}

View 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);

View 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);

View 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)

View 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;

View 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();

View 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();