daandemeyer / rpms / systemd

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