summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-02-18 11:54:34 -0500
committerGitHub <noreply@github.com>2017-02-18 11:54:34 -0500
commit581a07f9f0e32923f42aaccf58d11cd96f0d95f1 (patch)
tree9b574c0844f643cf482fa8a2bad09f6d4eff5d4a
parentcc39016131a535382ca6bc4c5eb018ff7643ed83 (diff)
parentdec718065b59babdbc502e87149c310a7a297172 (diff)
Merge pull request #5369 from poettering/nspawn-resolved
fixes for running nspawn+resolved in combination
-rw-r--r--Makefile.am6
-rw-r--r--src/nspawn/nspawn.c19
-rw-r--r--units/systemd-nspawn@.service.in2
-rw-r--r--units/systemd-resolved.service.m4.in1
4 files changed, 21 insertions, 7 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/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index efd3b014a3..751f26272b 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -41,6 +41,7 @@
#include <sys/wait.h>
#include <unistd.h>
+#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
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
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