From 4d680aeea1e479f08f3dbdb7430def5d9eefe2ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 11 Dec 2013 22:00:33 -0500 Subject: [PATCH] nspawn: complain and continue if machine has same id If --link-journal=host or --link-journal=guest is used, this totally cannot work and we exit with an error. If however --link-journal=auto or --link-journal=no is used, just display a warning. Having the same machine id can happen if booting from the same filesystem as the host. Since other things mostly function correctly, let's allow that. https://bugs.freedesktop.org/show_bug.cgi?id=68369 --- src/nspawn/nspawn.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index b3ca10ea9..c5faac479 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -804,14 +804,11 @@ static int setup_hostname(void) { } static int setup_journal(const char *directory) { - sd_id128_t machine_id; + sd_id128_t machine_id, this_id; _cleanup_free_ char *p = NULL, *b = NULL, *q = NULL, *d = NULL; char *id; int r; - if (arg_link_journal == LINK_NO) - return 0; - p = strappend(directory, "/etc/machine-id"); if (!p) return log_oom(); @@ -835,6 +832,24 @@ static int setup_journal(const char *directory) { return r; } + r = sd_id128_get_machine(&this_id); + if (r < 0) { + log_error("Failed to retrieve machine ID: %s", strerror(-r)); + return r; + } + + if (sd_id128_equal(machine_id, this_id)) { + log_full(arg_link_journal == LINK_AUTO ? LOG_WARNING : LOG_ERR, + "Host and machine ids are equal (%s): refusing to link journals", id); + if (arg_link_journal == LINK_AUTO) + return 0; + return + -EEXIST; + } + + if (arg_link_journal == LINK_NO) + return 0; + free(p); p = strappend("/var/log/journal/", id); q = strjoin(directory, "/var/log/journal/", id, NULL); -- 2.30.2