chiark / gitweb /
path: don't mention too many inotify msgs
[elogind.git] / src / path.c
index f4a0a288bb0708c9142f34f1a8c64ce1e1fcde59..0d594197779f40366bb2dcc31035a313a346a669 100644 (file)
@@ -39,6 +39,17 @@ static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = {
         [PATH_FAILED] = UNIT_FAILED
 };
 
         [PATH_FAILED] = UNIT_FAILED
 };
 
+static void path_unwatch_one(Path *p, PathSpec *s) {
+
+        if (s->inotify_fd < 0)
+                return;
+
+        unit_unwatch_fd(UNIT(p), &s->watch);
+
+        close_nointr_nofail(s->inotify_fd);
+        s->inotify_fd = -1;
+}
+
 static void path_done(Unit *u) {
         Path *p = PATH(u);
         PathSpec *s;
 static void path_done(Unit *u) {
         Path *p = PATH(u);
         PathSpec *s;
@@ -46,7 +57,9 @@ static void path_done(Unit *u) {
         assert(p);
 
         while ((s = p->specs)) {
         assert(p);
 
         while ((s = p->specs)) {
+                path_unwatch_one(p, s);
                 LIST_REMOVE(PathSpec, spec, p->specs, s);
                 LIST_REMOVE(PathSpec, spec, p->specs, s);
+                free(s->path);
                 free(s);
         }
 }
                 free(s);
         }
 }
@@ -168,17 +181,6 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) {
                         s->path);
 }
 
                         s->path);
 }
 
-static void path_unwatch_one(Path *p, PathSpec *s) {
-
-        if (s->inotify_fd < 0)
-                return;
-
-        unit_unwatch_fd(UNIT(p), &s->watch);
-
-        close_nointr_nofail(s->inotify_fd);
-        s->inotify_fd = -1;
-}
-
 static int path_watch_one(Path *p, PathSpec *s) {
         static const int flags_table[_PATH_TYPE_MAX] = {
                 [PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB,
 static int path_watch_one(Path *p, PathSpec *s) {
         static const int flags_table[_PATH_TYPE_MAX] = {
                 [PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB,
@@ -355,9 +357,13 @@ static void path_enter_waiting(Path *p, bool initial, bool recheck) {
                         good = access(s->path, F_OK) >= 0;
                         break;
 
                         good = access(s->path, F_OK) >= 0;
                         break;
 
-                case PATH_DIRECTORY_NOT_EMPTY:
-                        good = dir_is_empty(s->path) == 0;
+                case PATH_DIRECTORY_NOT_EMPTY: {
+                        int k;
+
+                        k = dir_is_empty(s->path);
+                        good = !(k == -ENOENT || k > 0);
                         break;
                         break;
+                }
 
                 case PATH_CHANGED: {
                         bool b;
 
                 case PATH_CHANGED: {
                         bool b;
@@ -377,6 +383,7 @@ static void path_enter_waiting(Path *p, bool initial, bool recheck) {
         }
 
         if (good) {
         }
 
         if (good) {
+                log_debug("%s got triggered.", p->meta.id);
                 path_enter_running(p);
                 return;
         }
                 path_enter_running(p);
                 return;
         }
@@ -479,7 +486,7 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {
             p->state != PATH_RUNNING)
                 return;
 
             p->state != PATH_RUNNING)
                 return;
 
-        log_debug("inotify wakeup on %s.", u->meta.id);
+        /* log_debug("inotify wakeup on %s.", u->meta.id); */
 
         if (events != EPOLLIN) {
                 log_error("Got Invalid poll event on inotify.");
 
         if (events != EPOLLIN) {
                 log_error("Got Invalid poll event on inotify.");