From 369ca6dab1fb8fd6289701af80e632667dadb5a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 21 Oct 2018 19:48:20 +0200 Subject: [PATCH] systemd-nspawn: do not crash on /var/log/journal creation if not required When running a read-only file system, we might not be able to create /var/log/journal. Do not fail on this, unless actually requested by the --link-journal options. $ systemd-nspawn --image=image.squashfs ... --- src/nspawn/nspawn.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d6a7d5b9ad..ca80483205 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2026,7 +2026,7 @@ static int setup_journal(const char *directory) { _cleanup_free_ char *d = NULL; const char *p, *q; bool try; - char id[33]; + char id[33], *dirname; int r; /* Don't link journals in ephemeral mode */ @@ -2050,17 +2050,15 @@ static int setup_journal(const char *directory) { return -EEXIST; } - r = userns_mkdir(directory, "/var", 0755, 0, 0); - if (r < 0) - return log_error_errno(r, "Failed to create /var: %m"); - - r = userns_mkdir(directory, "/var/log", 0755, 0, 0); - if (r < 0) - return log_error_errno(r, "Failed to create /var/log: %m"); - - r = userns_mkdir(directory, "/var/log/journal", 0755, 0, 0); - if (r < 0) - return log_error_errno(r, "Failed to create /var/log/journal: %m"); + FOREACH_STRING(dirname, "/var", "/var/log", "/var/log/journal") { + r = userns_mkdir(directory, dirname, 0755, 0, 0); + if (r < 0) { + bool ignore = r == -EROFS && try; + log_full_errno(ignore ? LOG_DEBUG : LOG_ERR, r, + "Failed to create %s%s: %m", dirname, ignore ? ", ignoring" : ""); + return ignore ? 0 : r; + } + } (void) sd_id128_to_string(arg_uuid, id); -- 2.25.1