2014-11-07 13:36:25 +01:00
|
|
|
---
|
2015-02-13 10:43:21 +01:00
|
|
|
src/core/manager.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++
|
2014-11-07 13:36:25 +01:00
|
|
|
src/core/manager.h | 5 ++
|
2015-02-13 10:43:21 +01:00
|
|
|
2 files changed, 98 insertions(+)
|
2014-11-07 13:36:25 +01:00
|
|
|
|
2015-06-23 14:56:50 +02:00
|
|
|
Index: systemd-221/src/core/manager.c
|
2015-02-13 10:43:21 +01:00
|
|
|
===================================================================
|
2015-06-23 14:56:50 +02:00
|
|
|
--- systemd-221.orig/src/core/manager.c
|
|
|
|
+++ systemd-221/src/core/manager.c
|
|
|
|
@@ -32,6 +32,7 @@
|
|
|
|
#include <fcntl.h>
|
2014-11-07 13:36:25 +01:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/timerfd.h>
|
|
|
|
+#include <resolv.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_AUDIT
|
|
|
|
#include <libaudit.h>
|
2015-06-23 14:56:50 +02:00
|
|
|
@@ -308,6 +309,91 @@ static int manager_check_ask_password(Ma
|
2014-11-07 13:36:25 +01:00
|
|
|
return m->have_ask_password;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int manager_setup_resolv_conf_change(Manager *);
|
|
|
|
+
|
|
|
|
+static int manager_dispatch_resolv_conf_fd(sd_event_source *source,
|
|
|
|
+ int fd, uint32_t revents, void *userdata) {
|
|
|
|
+ Manager *m = userdata;
|
|
|
|
+
|
|
|
|
+ assert(m);
|
|
|
|
+ assert(m->resolv_conf_inotify_fd == fd);
|
|
|
|
+
|
|
|
|
+ if (revents != EPOLLIN) {
|
|
|
|
+ log_warning("Got unexpected poll event for notify fd.");
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (fd >= 0)
|
|
|
|
+ flush_fd(fd);
|
|
|
|
+
|
|
|
|
+ m->resolv_conf_event_source = sd_event_source_unref(m->resolv_conf_event_source);
|
2015-02-13 10:43:21 +01:00
|
|
|
+ m->resolv_conf_inotify_fd = safe_close(m->resolv_conf_inotify_fd);
|
2014-11-07 13:36:25 +01:00
|
|
|
+ manager_setup_resolv_conf_change(m);
|
|
|
|
+ return m->resolv_conf_noent ? 0 : res_init();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int manager_setup_resolv_conf_change(Manager *m) {
|
|
|
|
+ int r;
|
|
|
|
+
|
|
|
|
+ assert(m);
|
|
|
|
+ assert(m->resolv_conf_inotify_fd < 0);
|
|
|
|
+
|
|
|
|
+ m->resolv_conf_inotify_fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC);
|
|
|
|
+ if (m->resolv_conf_inotify_fd < 0) {
|
|
|
|
+ log_error("inotify_init1() failed: %m");
|
|
|
|
+ r = -errno;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+ if (inotify_add_watch(m->resolv_conf_inotify_fd, "/etc/resolv.conf",
|
|
|
|
+ IN_CLOSE_WRITE|IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF) < 0) {
|
|
|
|
+ if (errno == ENOENT) {
|
|
|
|
+ m->resolv_conf_noent = true;
|
|
|
|
+ if (inotify_add_watch(m->resolv_conf_inotify_fd, "/etc", IN_CREATE|IN_MOVED_TO) < 0) {
|
|
|
|
+ log_error("Failed to add watch on /etc: %m");
|
|
|
|
+ r = -errno;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log_error("Failed to add watch on /etc/resolv.conf: %m");
|
|
|
|
+ r = -errno;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (inotify_add_watch(m->resolv_conf_inotify_fd, "/etc/host.conf",
|
|
|
|
+ IN_CLOSE_WRITE|IN_MODIFY|IN_ATTRIB|IN_DELETE_SELF) < 0 && errno != ENOENT) {
|
|
|
|
+ log_error("Failed to add watch on /etc/host.conf: %m");
|
|
|
|
+ r = -errno;
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ r = sd_event_add_io(m->event, &m->resolv_conf_event_source,
|
|
|
|
+ m->resolv_conf_inotify_fd, EPOLLIN,
|
|
|
|
+ manager_dispatch_resolv_conf_fd, m);
|
|
|
|
+ if (r < 0) {
|
|
|
|
+ log_error("Failed to add event source for resolver: %s", strerror(-r));
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ r = sd_event_source_set_priority(m->resolv_conf_event_source, -10);
|
|
|
|
+ if (r < 0) {
|
|
|
|
+ log_error("Failed to add event source for resolver: %s", strerror(-r));
|
|
|
|
+ m->resolv_conf_event_source = sd_event_source_unref(m->resolv_conf_event_source);
|
|
|
|
+ goto fail;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+fail:
|
2015-02-13 10:43:21 +01:00
|
|
|
+ m->resolv_conf_inotify_fd = safe_close(m->resolv_conf_inotify_fd);
|
2014-11-07 13:36:25 +01:00
|
|
|
+ return 0; /* Ignore error here */
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void manager_shutdown_resolv_conf_change(Manager *m) {
|
|
|
|
+ assert(m);
|
|
|
|
+
|
|
|
|
+ m->resolv_conf_event_source = sd_event_source_unref(m->resolv_conf_event_source);
|
2015-02-13 10:43:21 +01:00
|
|
|
+ m->resolv_conf_inotify_fd = safe_close(m->resolv_conf_inotify_fd);
|
2014-11-07 13:36:25 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int manager_watch_idle_pipe(Manager *m) {
|
|
|
|
int r;
|
|
|
|
|
2015-06-23 14:56:50 +02:00
|
|
|
@@ -585,6 +671,7 @@ int manager_new(ManagerRunningAs running
|
2015-02-13 10:43:21 +01:00
|
|
|
m->pin_cgroupfs_fd = m->notify_fd = m->signal_fd = m->time_change_fd = m->dev_autofs_fd = m->private_listen_fd = m->kdbus_fd = m->utab_inotify_fd = -1;
|
2014-11-07 13:36:25 +01:00
|
|
|
m->current_job_id = 1; /* start as id #1, so that we can leave #0 around as "null-like" value */
|
|
|
|
|
|
|
|
+ m->resolv_conf_inotify_fd = -1;
|
|
|
|
m->ask_password_inotify_fd = -1;
|
|
|
|
m->have_ask_password = -EINVAL; /* we don't know */
|
|
|
|
|
2015-06-23 14:56:50 +02:00
|
|
|
@@ -651,6 +738,10 @@ int manager_new(ManagerRunningAs running
|
2014-11-07 13:36:25 +01:00
|
|
|
if (r < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
+ r = manager_setup_resolv_conf_change(m);
|
|
|
|
+ if (r < 0)
|
|
|
|
+ goto fail;
|
|
|
|
+
|
|
|
|
m->udev = udev_new();
|
|
|
|
if (!m->udev) {
|
|
|
|
r = -ENOMEM;
|
2015-06-23 14:56:50 +02:00
|
|
|
@@ -929,6 +1020,8 @@ Manager* manager_free(Manager *m) {
|
2015-02-13 10:43:21 +01:00
|
|
|
if (!m)
|
|
|
|
return NULL;
|
2014-11-07 13:36:25 +01:00
|
|
|
|
|
|
|
+ manager_shutdown_resolv_conf_change(m);
|
|
|
|
+
|
|
|
|
manager_clear_jobs_and_units(m);
|
|
|
|
|
|
|
|
for (c = 0; c < _UNIT_TYPE_MAX; c++)
|
2015-06-23 14:56:50 +02:00
|
|
|
Index: systemd-221/src/core/manager.h
|
2015-02-13 10:43:21 +01:00
|
|
|
===================================================================
|
2015-06-23 14:56:50 +02:00
|
|
|
--- systemd-221.orig/src/core/manager.h
|
|
|
|
+++ systemd-221/src/core/manager.h
|
|
|
|
@@ -181,6 +181,11 @@ struct Manager {
|
2015-02-13 10:43:21 +01:00
|
|
|
int utab_inotify_fd;
|
|
|
|
sd_event_source *mount_utab_event_source;
|
2014-11-07 13:36:25 +01:00
|
|
|
|
|
|
|
+ /* Watch out any change of /etc/resolv.conf */
|
|
|
|
+ int resolv_conf_inotify_fd;
|
|
|
|
+ sd_event_source *resolv_conf_event_source;
|
|
|
|
+ bool resolv_conf_noent;
|
|
|
|
+
|
|
|
|
/* Data specific to the swap filesystem */
|
|
|
|
FILE *proc_swaps;
|
|
|
|
sd_event_source *swap_event_source;
|