chiark / gitweb /
nspawn: complain and continue if machine has same id
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 12 Dec 2013 03:00:33 +0000 (22:00 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 12 Dec 2013 03:39:41 +0000 (22:39 -0500)
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

index b3ca10ea9116c67168e904592f55e532d194e1a3..c5faac4797396e29d54b2f39e86bc336d94cac34 100644 (file)
@@ -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);