From: Zbigniew Jędrzejewski-Szmek Date: Sun, 3 Mar 2013 06:49:11 +0000 (-0500) Subject: core/path: catch errors when adding watches X-Git-Tag: v198~106 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=28a79bd28b706e33825ec01fc651dbd76a252ea3 core/path: catch errors when adding watches Errors because of oom conditions or descriptor exhaustion should not be ignored. We probably cannot recover from those conditions. Current behaviour wrt. insufficient permissions is described in the man page. It might make sense in case of user sessions, so I left it as is. --- diff --git a/man/systemd.path.xml b/man/systemd.path.xml index cc2d36619..1975142d2 100644 --- a/man/systemd.path.xml +++ b/man/systemd.path.xml @@ -88,16 +88,15 @@ point in the file system hierarchy, a dependency between both units is created automatically. - Unless DefaultDependencies= - is set to , path units will - implicitly have dependencies of type - Conflicts= and + Unless DefaultDependencies=false + is used, path units will implicitly have dependencies of + type Conflicts= and Before= on shutdown.target. These ensure that path units are terminated cleanly prior to system shutdown. Only path units involved with early boot or - late system shutdown should disable this - option. + late system shutdown should disable this option. + @@ -157,7 +156,7 @@ assignments of these options will not have any effect. - If a path is already existing + If a path already exists (in case of PathExists= and PathExistsGlob=) or @@ -168,7 +167,15 @@ activated, then the configured unit is immediately activated as well. Something similar does not apply - to PathChanged=. + to PathChanged= and + PathModified=. + + If the path itself or any of the + containing directories are not + accessible, systemd + will watch for permission changes and + notice that conditions are satisfied + when permissions allow that. diff --git a/src/core/path.c b/src/core/path.c index dcb3b1ff6..fc101280a 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -79,6 +79,11 @@ int path_spec_watch(PathSpec *s, Unit *u) { s->primary_wd = inotify_add_watch(s->inotify_fd, k, flags_table[s->type]); if (s->primary_wd >= 0) exists = true; + else if (errno != EACCES && errno != ENOENT) { + log_error("Failed to add watch on %s: %m", k); + r = -errno; + goto fail; + } do { int flags; @@ -97,8 +102,20 @@ int path_spec_watch(PathSpec *s, Unit *u) { if (inotify_add_watch(s->inotify_fd, k, flags) >= 0) exists = true; + else if (errno != EACCES && errno != ENOENT) { + log_error("Failed to add watch on %s: %m", k); + r = -errno; + goto fail; + } } while (slash != k); + if (!exists) { + log_error("Failed to add watch on any of the components of %s: %m", + s->path); + r = -errno; + goto fail; + } + return 0; fail: