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