summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-05-03 14:08:39 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-05-03 14:08:39 -0400
commita82394c889b18f047902017b3fad915e1246562f (patch)
tree797748e8c7fe8c121dd5a24457c1fa61f4906d90 /src/core
parentd43bbb52de220e6008a649b128fe32da995b5e1e (diff)
parent1691cfd8d995607f2d1eda460525011edf601192 (diff)
Merge pull request #2921 from keszybz/do-not-report-masked-units-as-changed
Diffstat (limited to 'src/core')
-rw-r--r--src/core/load-fragment.c8
-rw-r--r--src/core/unit.c62
2 files changed, 33 insertions, 37 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 67867dfbe9..1a8c03904c 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3630,10 +3630,12 @@ static int load_from_path(Unit *u, const char *path) {
if (fstat(fileno(f), &st) < 0)
return -errno;
- if (null_or_empty(&st))
+ if (null_or_empty(&st)) {
u->load_state = UNIT_MASKED;
- else {
+ u->fragment_mtime = 0;
+ } else {
u->load_state = UNIT_LOADED;
+ u->fragment_mtime = timespec_load(&st.st_mtim);
/* Now, parse the file contents */
r = config_parse(u->id, filename, f,
@@ -3648,8 +3650,6 @@ static int load_from_path(Unit *u, const char *path) {
u->fragment_path = filename;
filename = NULL;
- u->fragment_mtime = timespec_load(&st.st_mtim);
-
if (u->source_path) {
if (stat(u->source_path, &st) >= 0)
u->source_mtime = timespec_load(&st.st_mtim);
diff --git a/src/core/unit.c b/src/core/unit.c
index 5b8b0130bd..4ace6b075b 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2951,34 +2951,36 @@ int unit_coldplug(Unit *u) {
return 0;
}
+static bool fragment_mtime_changed(const char *path, usec_t mtime) {
+ struct stat st;
+
+ if (!path)
+ return false;
+
+ if (stat(path, &st) < 0)
+ /* What, cannot access this anymore? */
+ return true;
+
+ if (mtime > 0)
+ /* For non-empty files check the mtime */
+ return timespec_load(&st.st_mtim) != mtime;
+ else if (!null_or_empty(&st))
+ /* For masked files check if they are still so */
+ return true;
+
+ return false;
+}
+
bool unit_need_daemon_reload(Unit *u) {
_cleanup_strv_free_ char **t = NULL;
char **path;
- struct stat st;
unsigned loaded_cnt, current_cnt;
assert(u);
- if (u->fragment_path) {
- zero(st);
- if (stat(u->fragment_path, &st) < 0)
- /* What, cannot access this anymore? */
- return true;
-
- if (u->fragment_mtime > 0 &&
- timespec_load(&st.st_mtim) != u->fragment_mtime)
- return true;
- }
-
- if (u->source_path) {
- zero(st);
- if (stat(u->source_path, &st) < 0)
- return true;
-
- if (u->source_mtime > 0 &&
- timespec_load(&st.st_mtim) != u->source_mtime)
- return true;
- }
+ if (fragment_mtime_changed(u->fragment_path, u->fragment_mtime) ||
+ fragment_mtime_changed(u->source_path, u->source_mtime))
+ return true;
(void) unit_find_dropin_paths(u, &t);
loaded_cnt = strv_length(t);
@@ -2989,21 +2991,15 @@ bool unit_need_daemon_reload(Unit *u) {
return false;
if (strv_overlap(u->dropin_paths, t)) {
- STRV_FOREACH(path, u->dropin_paths) {
- zero(st);
- if (stat(*path, &st) < 0)
- return true;
-
- if (u->dropin_mtime > 0 &&
- timespec_load(&st.st_mtim) > u->dropin_mtime)
+ STRV_FOREACH(path, u->dropin_paths)
+ if (fragment_mtime_changed(*path, u->dropin_mtime))
return true;
- }
return false;
- } else
- return true;
- } else
- return true;
+ }
+ }
+
+ return true;
}
void unit_reset_failed(Unit *u) {