diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-11 22:00:33 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-11 22:39:41 -0500 |
commit | 4d680aeea1e479f08f3dbdb7430def5d9eefe2ee (patch) | |
tree | 8fd1e3c149131c552dffa7d6d7fc2f5f1bf4893c | |
parent | 50f72bca65ad291685e5b79903cb6ac3fbc8364d (diff) |
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
-rw-r--r-- | src/nspawn/nspawn.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index b3ca10ea91..c5faac4797 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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); |