]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: set source_mtime after load dropins
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 31 May 2020 12:35:40 +0000 (14:35 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 2 Jun 2020 20:53:55 +0000 (22:53 +0200)
Dropins may specify SourcePath= too, but we would do the stat only
after loading the main fragment, before loading of the drop-ins.

Fixes #13634.

src/core/load-fragment.c
src/core/unit.c

index a967627946c716b38337cc137d7df75f8e69c746..a24c7877f900926da521b5615549479750a5d7a6 100644 (file)
@@ -4804,7 +4804,6 @@ static int merge_by_names(Unit **u, Set *names, const char *id) {
 int unit_load_fragment(Unit *u) {
         const char *fragment;
         _cleanup_set_free_free_ Set *names = NULL;
-        struct stat st;
         int r;
 
         assert(u);
@@ -4836,6 +4835,7 @@ int unit_load_fragment(Unit *u) {
         if (fragment) {
                 /* Open the file, check if this is a mask, otherwise read. */
                 _cleanup_fclose_ FILE *f = NULL;
+                struct stat st;
 
                 /* Try to open the file name. A symlink is OK, for example for linked files or masks. We
                  * expect that all symlinks within the lookup paths have been already resolved, but we don't
@@ -4872,13 +4872,6 @@ int unit_load_fragment(Unit *u) {
                 }
         }
 
-        if (u->source_path) {
-                if (stat(u->source_path, &st) >= 0)
-                        u->source_mtime = timespec_load(&st.st_mtim);
-                else
-                        u->source_mtime = 0;
-        }
-
         /* We do the merge dance here because for some unit types, the unit might have aliases which are not
          * declared in the file system. In particular, this is true (and frequent) for device and swap units.
          */
index e1eb6ac7866b676e6bada5db0928c85d66e7786e..507a439e97dcb66dd1b9eb11179ebf3585e2132d 100644 (file)
@@ -1457,7 +1457,20 @@ int unit_load_fragment_and_dropin(Unit *u, bool fragment_required) {
          * target unit needlessly. But we cannot be sure which drops-ins have already
          * been loaded and which not, at least without doing complicated book-keeping,
          * so let's always reread all drop-ins. */
-        return unit_load_dropin(unit_follow_merge(u));
+        r = unit_load_dropin(unit_follow_merge(u));
+        if (r < 0)
+                return r;
+
+        if (u->source_path) {
+                struct stat st;
+
+                if (stat(u->source_path, &st) >= 0)
+                        u->source_mtime = timespec_load(&st.st_mtim);
+                else
+                        u->source_mtime = 0;
+        }
+
+        return 0;
 }
 
 void unit_add_to_target_deps_queue(Unit *u) {