00e68d9
From 48aab8bd94f75072a8d44f351a66cf74db450275 Mon Sep 17 00:00:00 2001
00e68d9
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
00e68d9
Date: Mon, 17 Oct 2016 01:15:03 -0400
00e68d9
Subject: [PATCH] pid1: do not use mtime==0 as sign of masking (#4388)
00e68d9
00e68d9
It is allowed for unit files to have an mtime==0, so instead of assuming that
00e68d9
any file that had mtime==0 was masked, use the load_state to filter masked
00e68d9
units.
00e68d9
00e68d9
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1384150.
00e68d9
(cherry picked from commit ba25d39e449347952522162c3fa110b04308e28c)
00e68d9
---
00e68d9
 src/core/unit.c | 20 ++++++++++++--------
00e68d9
 1 file changed, 12 insertions(+), 8 deletions(-)
00e68d9
00e68d9
diff --git a/src/core/unit.c b/src/core/unit.c
00e68d9
index 6726ce0749..d94b3eb5ab 100644
00e68d9
--- a/src/core/unit.c
00e68d9
+++ b/src/core/unit.c
00e68d9
@@ -2950,7 +2950,7 @@ int unit_coldplug(Unit *u) {
00e68d9
         return 0;
00e68d9
 }
00e68d9
 
00e68d9
-static bool fragment_mtime_newer(const char *path, usec_t mtime) {
00e68d9
+static bool fragment_mtime_newer(const char *path, usec_t mtime, bool path_masked) {
00e68d9
         struct stat st;
00e68d9
 
00e68d9
         if (!path)
00e68d9
@@ -2960,12 +2960,12 @@ static bool fragment_mtime_newer(const char *path, usec_t mtime) {
00e68d9
                 /* What, cannot access this anymore? */
00e68d9
                 return true;
00e68d9
 
00e68d9
-        if (mtime > 0)
00e68d9
+        if (path_masked)
00e68d9
+                /* For masked files check if they are still so */
00e68d9
+                return !null_or_empty(&st);
00e68d9
+        else
00e68d9
                 /* For non-empty files check the mtime */
00e68d9
                 return timespec_load(&st.st_mtim) > mtime;
00e68d9
-        else if (!null_or_empty(&st))
00e68d9
-                /* For masked files check if they are still so */
00e68d9
-                return true;
00e68d9
 
00e68d9
         return false;
00e68d9
 }
00e68d9
@@ -2976,18 +2976,22 @@ bool unit_need_daemon_reload(Unit *u) {
00e68d9
 
00e68d9
         assert(u);
00e68d9
 
00e68d9
-        if (fragment_mtime_newer(u->fragment_path, u->fragment_mtime))
00e68d9
+        /* For unit files, we allow masking… */
00e68d9
+        if (fragment_mtime_newer(u->fragment_path, u->fragment_mtime,
00e68d9
+                                 u->load_state == UNIT_MASKED))
00e68d9
                 return true;
00e68d9
 
00e68d9
-        if (fragment_mtime_newer(u->source_path, u->source_mtime))
00e68d9
+        /* Source paths should not be masked… */
00e68d9
+        if (fragment_mtime_newer(u->source_path, u->source_mtime, false))
00e68d9
                 return true;
00e68d9
 
00e68d9
         (void) unit_find_dropin_paths(u, &t);
00e68d9
         if (!strv_equal(u->dropin_paths, t))
00e68d9
                 return true;
00e68d9
 
00e68d9
+        /* … any drop-ins that are masked are simply omitted from the list. */
00e68d9
         STRV_FOREACH(path, u->dropin_paths)
00e68d9
-                if (fragment_mtime_newer(*path, u->dropin_mtime))
00e68d9
+                if (fragment_mtime_newer(*path, u->dropin_mtime, false))
00e68d9
                         return true;
00e68d9
 
00e68d9
         return false;