X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fpath.c;h=1455b47995e4943f2bf3affb10d8b558e2fa3951;hp=a8b10724495b6198d246d269122c44f1168f8304;hb=3fc546f93d92c09188d5018ea47def33b149c2e9;hpb=36af55d99711e9accdf42d8a7df60e069f4086c0 diff --git a/src/path.c b/src/path.c index a8b107244..1455b4799 100644 --- a/src/path.c +++ b/src/path.c @@ -39,6 +39,17 @@ static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = { [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; @@ -46,7 +57,9 @@ static void path_done(Unit *u) { assert(p); while ((s = p->specs)) { + path_unwatch_one(p, s); LIST_REMOVE(PathSpec, spec, p->specs, s); + free(s->path); free(s); } } @@ -168,17 +181,6 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) { 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, @@ -187,7 +189,7 @@ static int path_watch_one(Path *p, PathSpec *s) { }; bool exists = false; - char *k; + char *k, *slash; int r; assert(p); @@ -211,23 +213,23 @@ static int path_watch_one(Path *p, PathSpec *s) { if ((s->primary_wd = inotify_add_watch(s->inotify_fd, k, flags_table[s->type])) >= 0) exists = true; - for (;;) { + do { int flags; - char *slash; /* This assumes the path was passed through path_kill_slashes()! */ if (!(slash = strrchr(k, '/'))) break; - *slash = 0; + /* Trim the path at the last slash. Keep the slash if it's the root dir. */ + slash[slash == k] = 0; - flags = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB; + flags = IN_MOVE_SELF; if (!exists) - flags |= IN_CREATE | IN_MOVED_TO; + flags |= IN_DELETE_SELF | IN_ATTRIB | IN_CREATE | IN_MOVED_TO; if (inotify_add_watch(s->inotify_fd, k, flags) >= 0) exists = true; - } + } while (slash != k); return 0; @@ -277,7 +279,7 @@ static void path_set_state(Path *p, PathState state) { path_state_to_string(old_state), path_state_to_string(state)); - unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state]); + unit_notify(UNIT(p), state_translation_table[old_state], state_translation_table[state], true); } static void path_enter_waiting(Path *p, bool initial, bool recheck); @@ -381,6 +383,7 @@ static void path_enter_waiting(Path *p, bool initial, bool recheck) { } if (good) { + log_debug("%s got triggered.", p->meta.id); path_enter_running(p); return; } @@ -483,7 +486,7 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) { 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.");