chiark / gitweb /
core/path: catch errors when adding watches
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Mar 2013 06:49:11 +0000 (01:49 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 3 Mar 2013 13:55:53 +0000 (08:55 -0500)
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.

man/systemd.path.xml
src/core/path.c

index cc2d366198270c71c3e487cf30c7f10d10691843..1975142d2c0648211f8c00e0258fb9f188021d30 100644 (file)
                 point in the file system hierarchy, a dependency
                 between both units is created automatically.</para>
 
-                <para>Unless <varname>DefaultDependencies=</varname>
-                is set to <option>false</option>, path units will
-                implicitly have dependencies of type
-                <varname>Conflicts=</varname> and
+                <para>Unless <varname>DefaultDependencies=false</varname>
+                is used, path units will implicitly have dependencies of
+                type <varname>Conflicts=</varname> and
                 <varname>Before=</varname> on
                 <filename>shutdown.target</filename>. 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.</para>
+                late system shutdown should disable this option.
+                </para>
         </refsect1>
 
         <refsect1>
                                 assignments of these options will not
                                 have any effect.</para>
 
-                                <para>If a path is already existing
+                                <para>If a path already exists
                                 (in case of
                                 <varname>PathExists=</varname> and
                                 <varname>PathExistsGlob=</varname>) or
                                 activated, then the configured unit is
                                 immediately activated as
                                 well. Something similar does not apply
-                                to <varname>PathChanged=</varname>.
+                                to <varname>PathChanged=</varname> and
+                                <varname>PathModified=</varname>.</para>
+
+                                <para>If the path itself or any of the
+                                containing directories are not
+                                accessible, <command>systemd</command>
+                                will watch for permission changes and
+                                notice that conditions are satisfied
+                                when permissions allow that.
                                 </para></listitem>
                         </varlistentry>
                         <varlistentry>
index dcb3b1ff60a7a3d7e4f4aa9af3f62bdfd16cefd0..fc101280a1e7c53df895726137f3a3a27dbb80cc 100644 (file)
@@ -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: