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

Lennart Poettering lennart at poettering.net
Thu Oct 30 10:08:15 PDT 2014


On Thu, 30.10.14 12:36, Jan Synacek (jsynacek at redhat.com) wrote:

> ---
> Changes in v2:
>  - show long explanation only when errno == EROFS
> 
>  src/core/machine-id-setup.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
> index efb074f..2360904 100644
> --- a/src/core/machine-id-setup.c
> +++ b/src/core/machine-id-setup.c
> @@ -191,7 +191,14 @@ int machine_id_setup(const char *root) {
>                  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 (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;
>                          }

This looks wrong. You need to remember the EROFS from the first
open(). The second open() will return ENOENT if the file is missing,
not EROFS...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list