From: Lennart Poettering Date: Wed, 15 Nov 2017 18:56:21 +0000 (+0100) Subject: core: never apply first boot presets in the initrd X-Git-Tag: v236~190^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fd1306121d014847b14e16e7f467faec619d71ff;p=thirdparty%2Fsystemd.git core: never apply first boot presets in the initrd Presets are useful to initialize uninitialized /etc, but that doesn't apply to the initrd. Also, let's rename etc_empty → first_boot. After all, the variable doesn't actually reflect whether /etc is really empty, it just reflects whether /etc/machine-id existed originally or not. Moreover, we later on directly initialize manager_set_first_boot() from it, hence let's just name it the same way all through the codepath, to make this all less confusing. See: #7100 --- diff --git a/src/core/main.c b/src/core/main.c index 9be651e97a7..d0a66b9ecbb 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1406,7 +1406,7 @@ int main(int argc, char *argv[]) { bool loaded_policy = false; bool arm_reboot_watchdog = false; bool queue_default_job = false; - bool empty_etc = false; + bool first_boot = false; char *switch_root_dir = NULL, *switch_root_init = NULL; struct rlimit saved_rlimit_nofile = RLIMIT_MAKE_CONST(0), saved_rlimit_memlock = RLIMIT_MAKE_CONST((rlim_t) -1); const char *error_message = NULL; @@ -1767,18 +1767,17 @@ int main(int argc, char *argv[]) { if (in_initrd()) log_info("Running in initial RAM disk."); - - /* Let's check whether /etc is already populated. We - * don't actually really check for that, but use - * /etc/machine-id as flag file. This allows container - * managers and installers to provision a couple of - * files already. If the container manager wants to - * provision the machine ID itself it should pass - * $container_uuid to PID 1. */ - - empty_etc = access("/etc/machine-id", F_OK) < 0; - if (empty_etc) - log_info("Running with unpopulated /etc."); + else { + /* Let's check whether we are in first boot, i.e. whether /etc is still unpopulated. We use + * /etc/machine-id as flag file, for this: if it exists we assume /etc is populated, if it + * doesn't it's unpopulated. This allows container managers and installers to provision a + * couple of files already. If the container manager wants to provision the machine ID itself + * it should pass $container_uuid to PID 1. */ + + first_boot = access("/etc/machine-id", F_OK) < 0; + if (first_boot) + log_info("Running with unpopulated /etc."); + } } else { _cleanup_free_ char *t; @@ -1863,7 +1862,7 @@ int main(int argc, char *argv[]) { set_manager_defaults(m); manager_set_show_status(m, arg_show_status); - manager_set_first_boot(m, empty_etc); + manager_set_first_boot(m, first_boot); /* Remember whether we should queue the default job */ queue_default_job = !arg_serialization || arg_switched_root; diff --git a/src/core/manager.c b/src/core/manager.c index ecb87167fa4..b9d179cc3a6 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -1345,8 +1345,9 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) { if (r < 0) return r; + /* If this is the first boot, and we are in the host system, then preset everything */ if (m->first_boot > 0 && - m->unit_file_scope == UNIT_FILE_SYSTEM && + MANAGER_IS_SYSTEM(m) && !m->test_run_flags) { r = unit_file_preset_all(UNIT_FILE_SYSTEM, 0, NULL, UNIT_FILE_PRESET_ENABLE_ONLY, NULL, 0);