[systemd-devel] [PATCH v3] core: improve error message when machine id is missing

Jan Synacek jsynacek at redhat.com
Fri Oct 31 02:16:45 PDT 2014


---
Changes in v3:
 - check correct errno
Changes in v2:
 - show long explanation only when errno == EROFS

 src/core/machine-id-setup.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index efb074f..e54b879 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -184,14 +184,24 @@ int machine_id_setup(const char *root) {
                  * will be owned by root it doesn't matter much, but maybe
                  * people look. */
 
+                int old_errno;
+
                 mkdir_parents(etc_machine_id, 0755);
                 fd = open(etc_machine_id, O_RDWR|O_CREAT|O_CLOEXEC|O_NOCTTY, 0444);
+                old_errno = errno;
                 if (fd >= 0)
                         writable = true;
                 else {
                         fd = open(etc_machine_id, O_RDONLY|O_CLOEXEC|O_NOCTTY);
                         if (fd < 0) {
-                                log_error("Cannot open %s: %m", etc_machine_id);
+                                if (old_errno == EROFS)
+                                        log_error("System cannot boot: Missing /etc/machine-id and /etc is mounted read-only.\n"
+                                                  "Booting up is supported only when:\n"
+                                                  "1) /etc/machine-id exists and is populated.\n"
+                                                  "2) /etc/machine-id exists and is empty.\n"
+                                                  "3) /etc/machine-id is missing and /etc is writable.\n");
+                                else
+                                        log_error("Cannot open %s: %m", etc_machine_id);
                                 return -errno;
                         }
 
-- 
1.9.3



More information about the systemd-devel mailing list