summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorHarald Seiler <hws@denx.de>2020-09-06 21:23:35 +0200
committerHarald Seiler <hws@denx.de>2020-10-19 12:33:39 +0200
commit583cef3b7347c4e6ca269d38efef6d2e4314aba6 (patch)
tree6a8a090412c52fc8f53e590a2d25d0341c95adad /src/core
parentpreset: don't enable proc-sys-fs-binfmt_misc.mount (diff)
downloadsystemd-583cef3b7347c4e6ca269d38efef6d2e4314aba6.tar.xz
systemd-583cef3b7347c4e6ca269d38efef6d2e4314aba6.zip
core: treat "uninitialized" in /etc/machine-id as first boot as well
When /etc/machine-id contains the string "uninitialized" instead of a valid machine-id, treat this like the file was missing and mark this boot as the first (-> units with ConditionFirstBoot=yes will run).
Diffstat (limited to 'src/core')
-rw-r--r--src/core/main.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/core/main.c b/src/core/main.c
index 6cd596fa79..a8a48db2a0 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -2001,15 +2001,26 @@ static void log_execution_mode(bool *ret_first_boot) {
*ret_first_boot = false;
log_info("Running in initial RAM disk.");
} 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. */
-
- *ret_first_boot = access("/etc/machine-id", F_OK) < 0;
- if (*ret_first_boot)
- log_info("Running with unpopulated /etc.");
+ int r;
+ _cleanup_free_ char *id_text = NULL;
+
+ /* Let's check whether we are in first boot. We use /etc/machine-id as flag file
+ * for this: If it is missing or contains the value "uninitialized", this is the
+ * first boot. In any other case, it is not. 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. */
+
+ r = read_one_line_file("/etc/machine-id", &id_text);
+ if (r < 0 || streq(id_text, "uninitialized")) {
+ if (r < 0 && r != -ENOENT)
+ log_warning_errno(r, "Unexpected error while reading /etc/machine-id, ignoring: %m");
+
+ *ret_first_boot = true;
+ log_info("Detected first boot.");
+ } else {
+ *ret_first_boot = false;
+ log_debug("Detected initialized system, this is not the first boot.");
+ }
}
} else {
if (DEBUG_LOGGING) {