From 38880bff01a4ed858b8b3d53aa00057b27d5bfc9 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 21 Aug 2023 17:19:35 -0400 Subject: [PATCH] composefs: Hard error except on ENOENT even in "optional" case Since we enabled composefs at build time, the default (non-composefs) case now always prints `composefs: Optional support failed: No such file or directory` But that's normal and expected. Rework things here so that in the very special case where we are in "maybe/optional" mode and we get ENOENT, then we output a much more normal-looking message that doesn't include the string "failed". Now on the flip side - if I have explicitly enabled signature checking, I think we *do* want to make that fatal even if composefs is in "maybe" mode. (This part is more debatable; perhaps we should just disallow the case of "maybe" + signatures at all; but I think this is an improvement in that direction) --- src/switchroot/ostree-prepare-root.c | 41 +++++++++++++++------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/switchroot/ostree-prepare-root.c b/src/switchroot/ostree-prepare-root.c index a75c1981..f6c3a814 100644 --- a/src/switchroot/ostree-prepare-root.c +++ b/src/switchroot/ostree-prepare-root.c @@ -264,6 +264,24 @@ validate_signature (GBytes *data, GVariant *signatures, GPtrArray *pubkeys) return FALSE; } + +// Output a friendly message based on an errno for common cases +static const char * +composefs_error_message (int errsv) +{ + switch (errsv) + { + case ENOVERITY: + return "fsverity not enabled on composefs image"; + case EWRONGVERITY: + return "Wrong fsverity digest in composefs image"; + case ENOSIGNATURE: + return "Missing signature for fsverity in composefs image"; + default: + return strerror (errsv); + } +} + #endif typedef struct @@ -495,29 +513,14 @@ main (int argc, char *argv[]) else { int errsv = errno; - const char *errmsg; - switch (errsv) - { - case ENOVERITY: - errmsg = "fsverity not enabled on composefs image"; - break; - case EWRONGVERITY: - errmsg = "Wrong fsverity digest in composefs image"; - break; - case ENOSIGNATURE: - errmsg = "Missing signature for fsverity in composefs image"; - break; - default: - errmsg = strerror (errno); - break; - } - if (composefs_config->enabled == OT_TRISTATE_MAYBE) + g_assert (composefs_config->enabled != OT_TRISTATE_NO); + if (composefs_config->enabled == OT_TRISTATE_MAYBE && errsv == ENOENT) { - g_print ("composefs: optional support failed: %s\n", errmsg); + g_print ("composefs: No image present\n"); } else { - g_assert (composefs_config->enabled == OT_TRISTATE_YES); + const char *errmsg = composefs_error_message (errsv); errx (EXIT_FAILURE, "composefs: failed to mount: %s", errmsg); } } -- 2.30.2