summaryrefslogtreecommitdiffstats
path: root/src/core/path.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-11-18 14:20:05 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-11-18 14:20:05 +0100
commitd7cf8c24d4ef6ed4c9d711ee82ba57a529baad34 (patch)
tree71977d4dd01408defd05f725f6607279542f5585 /src/core/path.c
parentcore/path: serialize the previous_exists state (diff)
downloadsystemd-d7cf8c24d4ef6ed4c9d711ee82ba57a529baad34.tar.xz
systemd-d7cf8c24d4ef6ed4c9d711ee82ba57a529baad34.zip
core/path: fix spurious triggering of PathExists= on restart/reload
Our handling of the condition was inconsistent. Normally, we'd only fire when the file was created (or removed and subsequently created again). But on restarts, we'd do a "recheck" from path_coldplug(), and if the file existed, we'd always trigger. Daemon restarts and reloads should not be observeable, in the sense that they should not trigger units which were already triggered and would not be started again under normal circumstances. Note that the mechanism for checks is racy: we get a notification from inotify, and by the time we check, the file could have been created and removed again, or removed and created again. It would be better if we inotify would give as an unambiguous signal that the file was created, but it doesn't: IN_DELETE_SELF triggers on inode removal, not directory entry, so we need to include IN_ATTRIB, which obviously triggers on other conditions. Fixes #12801.
Diffstat (limited to 'src/core/path.c')
-rw-r--r--src/core/path.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/core/path.c b/src/core/path.c
index ed3a0132c2..1491a07fa5 100644
--- a/src/core/path.c
+++ b/src/core/path.c
@@ -175,12 +175,14 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
}
static bool path_spec_check_good(PathSpec *s, bool initial) {
- bool good = false;
+ bool b, good = false;
switch (s->type) {
case PATH_EXISTS:
- good = access(s->path, F_OK) >= 0;
+ b = access(s->path, F_OK) >= 0;
+ good = b && !s->previous_exists;
+ s->previous_exists = b;
break;
case PATH_EXISTS_GLOB:
@@ -196,14 +198,11 @@ static bool path_spec_check_good(PathSpec *s, bool initial) {
}
case PATH_CHANGED:
- case PATH_MODIFIED: {
- bool b;
-
+ case PATH_MODIFIED:
b = access(s->path, F_OK) >= 0;
good = !initial && b != s->previous_exists;
s->previous_exists = b;
break;
- }
default:
;