X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fpath.c;h=b3bc8a5a0d77bb38883ab57e47dca11d9c0a79ca;hp=2f1e0aea632631bc59bf11701cd64f3fcfde60e7;hb=b9ba604e8720c30deb7095b049b577eec1cbb74a;hpb=e364ad0628b5930a671ae5be863b960f4bd748a8 diff --git a/src/path.c b/src/path.c index 2f1e0aea6..b3bc8a5a0 100644 --- a/src/path.c +++ b/src/path.c @@ -1,4 +1,4 @@ -/*-*- Mode: C; c-basic-offset: 8 -*-*/ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*** This file is part of systemd. @@ -36,7 +36,7 @@ static const UnitActiveState state_translation_table[_PATH_STATE_MAX] = { [PATH_DEAD] = UNIT_INACTIVE, [PATH_WAITING] = UNIT_ACTIVE, [PATH_RUNNING] = UNIT_ACTIVE, - [PATH_MAINTENANCE] = UNIT_MAINTENANCE + [PATH_FAILED] = UNIT_FAILED }; static void path_done(Unit *u) { @@ -301,7 +301,7 @@ static void path_enter_dead(Path *p, bool success) { if (!success) p->failure = true; - path_set_state(p, p->failure ? PATH_MAINTENANCE : PATH_DEAD); + path_set_state(p, p->failure ? PATH_FAILED : PATH_DEAD); } static void path_enter_running(Path *p) { @@ -383,13 +383,14 @@ static int path_start(Unit *u) { Path *p = PATH(u); assert(p); - assert(p->state == PATH_DEAD || p->state == PATH_MAINTENANCE); + assert(p->state == PATH_DEAD || p->state == PATH_FAILED); if (p->unit->meta.load_state != UNIT_LOADED) return -ENOENT; p->failure = false; -path_enter_waiting(p, true); + path_enter_waiting(p, true); + return 0; } @@ -452,7 +453,8 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) { Path *p = PATH(u); int l; ssize_t k; - struct inotify_event *buf = NULL; + uint8_t *buf = NULL; + struct inotify_event *e; PathSpec *s; assert(p); @@ -492,16 +494,22 @@ static void path_fd_event(Unit *u, int fd, uint32_t events, Watch *w) { goto fail; } - if ((size_t) k < sizeof(struct inotify_event) || - (size_t) k < sizeof(struct inotify_event) + buf->len) { - log_error("inotify event too small."); - goto fail; - } + e = (struct inotify_event*) buf; - if (s->type == PATH_CHANGED && s->primary_wd == buf->wd) - path_enter_running(p); - else - path_enter_waiting(p, false); + while (k > 0) { + size_t step; + + if (s->type == PATH_CHANGED && s->primary_wd == e->wd) + path_enter_running(p); + else + path_enter_waiting(p, false); + + step = sizeof(struct inotify_event) + e->len; + assert(step <= (size_t) k); + + e = (struct inotify_event*) ((uint8_t*) e + step); + k -= step; + } free(buf); @@ -556,12 +564,12 @@ fail: log_error("Failed find path unit: %s", strerror(-r)); } -static void path_reset_maintenance(Unit *u) { +static void path_reset_failed(Unit *u) { Path *p = PATH(u); assert(p); - if (p->state == PATH_MAINTENANCE) + if (p->state == PATH_FAILED) path_set_state(p, PATH_DEAD); p->failure = false; @@ -571,7 +579,7 @@ static const char* const path_state_table[_PATH_STATE_MAX] = { [PATH_DEAD] = "dead", [PATH_WAITING] = "waiting", [PATH_RUNNING] = "running", - [PATH_MAINTENANCE] = "maintenance" + [PATH_FAILED] = "failed" }; DEFINE_STRING_TABLE_LOOKUP(path_state, PathState); @@ -605,7 +613,8 @@ const UnitVTable path_vtable = { .fd_event = path_fd_event, - .reset_maintenance = path_reset_maintenance, + .reset_failed = path_reset_failed, + .bus_interface = "org.freedesktop.systemd1.Path", .bus_message_handler = bus_path_message_handler };