47313b1
From 896050eeb3acbf4106d71204a5173b4984cf1675 Mon Sep 17 00:00:00 2001
b397f2a
From: Jan Synacek <jsynacek@redhat.com>
b397f2a
Date: Fri, 31 Oct 2014 10:16:45 +0100
b397f2a
Subject: [PATCH] core: improve error message when machine id is missing
b397f2a
b397f2a
(cherry picked from commit 86fb9ca7ae49790880d4b3ce523988b01b13d9ae)
b397f2a
---
b397f2a
 src/core/machine-id-setup.c | 17 ++++++++++++-----
b397f2a
 1 file changed, 12 insertions(+), 5 deletions(-)
b397f2a
b397f2a
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
b397f2a
index efb074fcbd..ce6d8e02d0 100644
b397f2a
--- a/src/core/machine-id-setup.c
b397f2a
+++ b/src/core/machine-id-setup.c
b397f2a
@@ -162,7 +162,7 @@ static int generate(char id[34], const char *root) {
b397f2a
 int machine_id_setup(const char *root) {
b397f2a
         const char *etc_machine_id, *run_machine_id;
b397f2a
         _cleanup_close_ int fd = -1;
b397f2a
-        bool writable = false;
b397f2a
+        bool writable = true;
b397f2a
         struct stat st;
b397f2a
         char id[34]; /* 32 + \n + \0 */
b397f2a
         int r;
b397f2a
@@ -186,12 +186,19 @@ int machine_id_setup(const char *root) {
b397f2a
 
b397f2a
                 mkdir_parents(etc_machine_id, 0755);
b397f2a
                 fd = open(etc_machine_id, O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
b397f2a
-                if (fd >= 0)
b397f2a
-                        writable = true;
b397f2a
-                else {
b397f2a
+                if (fd < 0) {
b397f2a
+                        int old_errno = errno;
b397f2a
+
b397f2a
                         fd = open(etc_machine_id, O_RDONLY|O_CLOEXEC|O_NOCTTY);
b397f2a
                         if (fd < 0) {
b397f2a
-                                log_error("Cannot open %s: %m", etc_machine_id);
b397f2a
+                                if (old_errno == EROFS && errno == ENOENT)
b397f2a
+                                        log_error("System cannot boot: Missing /etc/machine-id and /etc is mounted read-only.\n"
b397f2a
+                                                  "Booting up is supported only when:\n"
b397f2a
+                                                  "1) /etc/machine-id exists and is populated.\n"
b397f2a
+                                                  "2) /etc/machine-id exists and is empty.\n"
b397f2a
+                                                  "3) /etc/machine-id is missing and /etc is writable.\n");
b397f2a
+                                else
b397f2a
+                                        log_error("Cannot open %s: %m", etc_machine_id);
b397f2a
                                 return -errno;
b397f2a
                         }
b397f2a