From: Zbigniew Jędrzejewski-Szmek Date: Sun, 21 Oct 2018 17:48:20 +0000 (+0200) Subject: systemd-nspawn: do not crash on /var/log/journal creation if not required X-Git-Tag: v240~499 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=369ca6dab1fb8fd6289701af80e632667dadb5a4;p=thirdparty%2Fsystemd.git 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 ... --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d6a7d5b9ad0..ca804832057 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);