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