From 4d1f490c9386d1a824ce8269de5ed7938cbf8096 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2017 17:48:48 +0100 Subject: [PATCH 1/3] units: enable resolved bus activation though a symlink in /etc The change: -/usr/lib/systemd/system/dbus-org.freedesktop.resolve1.service +/etc/systemd/system/dbus-org.freedesktop.resolve1.service If resolved is disabled, without this, talking to the resolved bus API will activate it regardless whether it is enabled or not, let's fix that. --- Makefile.am | 6 ++---- units/systemd-resolved.service.m4.in | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index dd10aabd36..09e550da65 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5565,14 +5565,12 @@ dist_dbuspolicy_DATA += \ dist_dbussystemservice_DATA += \ src/resolve/org.freedesktop.resolve1.service -SYSTEM_UNIT_ALIASES += \ - systemd-resolved.service dbus-org.freedesktop.resolve1.service - BUSNAMES_TARGET_WANTS += \ org.freedesktop.resolve1.busname GENERAL_ALIASES += \ - $(systemunitdir)/systemd-resolved.service $(pkgsysconfdir)/system/multi-user.target.wants/systemd-resolved.service + $(systemunitdir)/systemd-resolved.service $(pkgsysconfdir)/system/multi-user.target.wants/systemd-resolved.service \ + $(systemunitdir)/systemd-resolved.service $(pkgsysconfdir)/system/dbus-org.freedesktop.resolve1.service nodist_pkgsysconf_DATA += \ src/resolve/resolved.conf diff --git a/units/systemd-resolved.service.m4.in b/units/systemd-resolved.service.m4.in index 0f0440ddaf..d3b8f81601 100644 --- a/units/systemd-resolved.service.m4.in +++ b/units/systemd-resolved.service.m4.in @@ -38,3 +38,4 @@ SystemCallFilter=~@clock @cpu-emulation @debug @keyring @module @mount @obsolete [Install] WantedBy=multi-user.target +Alias=dbus-org.freedesktop.resolve1.service From b053cd5f8e48e04ac576296404848bbb8dd26854 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2017 17:56:10 +0100 Subject: [PATCH 2/3] nspawn: tweak check whether resolved is around a bit Let's check D-Bus instead of files in /run to see if resolved is running. This is a bit nicer as bus names are automatically cleaned up when resolved dies, which is not the case for files in /run. See: #4649 --- src/nspawn/nspawn.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index b172b44933..72d1bb54de 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -41,6 +41,7 @@ #include #include +#include "sd-bus.h" #include "sd-daemon.h" #include "sd-id128.h" @@ -49,6 +50,7 @@ #include "base-filesystem.h" #include "blkid-util.h" #include "btrfs-util.h" +#include "bus-util.h" #include "cap-list.h" #include "capability-util.h" #include "cgroup-util.h" @@ -1323,6 +1325,19 @@ static int setup_timezone(const char *dest) { return 0; } +static int resolved_running(void) { + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; + int r; + + /* Check if resolved is running */ + + r = sd_bus_open_system(&bus); + if (r < 0) + return r; + + return bus_name_has_owner(bus, "org.freedesktop.resolve1", NULL); +} + static int setup_resolv_conf(const char *dest) { _cleanup_free_ char *resolved = NULL, *etc = NULL; const char *where; @@ -1346,8 +1361,8 @@ static int setup_resolv_conf(const char *dest) { return 0; } - if (access("/run/systemd/resolve/resolv.conf", F_OK) >= 0 && - access("/usr/lib/systemd/resolv.conf", F_OK) >= 0) { + if (access("/usr/lib/systemd/resolv.conf", F_OK) >= 0 && + resolved_running() > 0) { /* resolved is enabled on the host. In this, case bind mount its static resolv.conf file into the * container, so that the container can use the host's resolver. Given that network namespacing is From dec718065b59babdbc502e87149c310a7a297172 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 16 Feb 2017 17:57:30 +0100 Subject: [PATCH 3/3] units: order systemd-nspawn@.service after systemd-resolved.service This way, the nspawn internal check whether resolved is running will succeed if it is enabled. Fixes: #4649 --- units/systemd-nspawn@.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/units/systemd-nspawn@.service.in b/units/systemd-nspawn@.service.in index e8d1fff7ab..8c0685aef5 100644 --- a/units/systemd-nspawn@.service.in +++ b/units/systemd-nspawn@.service.in @@ -10,7 +10,7 @@ Description=Container %i Documentation=man:systemd-nspawn(1) PartOf=machines.target Before=machines.target -After=network.target +After=network.target systemd-resolved.service [Service] ExecStart=@bindir@/systemd-nspawn --quiet --keep-unit --boot --link-journal=try-guest --network-veth -U --settings=override --machine=%i