nspawn: complain and continue if machine has same id

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
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-12-11 22:39:41 -05:00
parent 50f72bca65
commit 4d680aeea1
+19 -4
View 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);