teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0132-nspawn-complain-and-continue-if-machine-has-same-id.patch

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