]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: never apply first boot presets in the initrd
authorLennart Poettering <lennart@poettering.net>
Wed, 15 Nov 2017 18:56:21 +0000 (19:56 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Nov 2017 10:28:17 +0000 (11:28 +0100)
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

src/core/main.c
src/core/manager.c

index 9be651e97a7f9d61c9dca2e0c23017417426f386..d0a66b9ecbbe72acef562d8bdba3965e16164f79 100644 (file)
@@ -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;
index ecb87167fa43ab5a60aedfaa3b27a065fd96beee..b9d179cc3a6d475b622f0ddde809f4c497dd5a33 100644 (file)
@@ -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);