summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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