X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fpath.c;h=3e2856920338d1db3216f2ee98b079a4e9a48200;hp=27c45447297882b3c44d522567fc1d7bfb915a90;hb=782195a3c31a79428874a32e0264c0aa97a664f7;hpb=398ef8ba0266cca453d90a90b3a2aa1caa44189f diff --git a/src/path.c b/src/path.c index 27c454472..3e2856920 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) { @@ -101,6 +101,22 @@ static int path_verify(Path *p) { return 0; } +static int path_add_default_dependencies(Path *p) { + int r; + + assert(p); + + if (p->meta.manager->running_as == MANAGER_SYSTEM) { + if ((r = unit_add_dependency_by_name(UNIT(p), UNIT_BEFORE, SPECIAL_BASIC_TARGET, NULL, true)) < 0) + return r; + + if ((r = unit_add_two_dependencies_by_name(UNIT(p), UNIT_AFTER, UNIT_REQUIRES, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0) + return r; + } + + return unit_add_two_dependencies_by_name(UNIT(p), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true); +} + static int path_load(Unit *u) { Path *p = PATH(u); int r; @@ -123,9 +139,8 @@ static int path_load(Unit *u) { if ((r = path_add_mount_links(p)) < 0) return r; - /* Path units shouldn't stay around on shutdown */ if (p->meta.default_dependencies) - if ((r = unit_add_two_dependencies_by_name(u, UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true)) < 0) + if ((r = path_add_default_dependencies(p)) < 0) return r; } @@ -134,12 +149,10 @@ static int path_load(Unit *u) { static void path_dump(Unit *u, FILE *f, const char *prefix) { Path *p = PATH(u); - const char *prefix2; - char *p2; PathSpec *s; - p2 = strappend(prefix, "\t"); - prefix2 = p2 ? p2 : prefix; + assert(p); + assert(f); fprintf(f, "%sPath State: %s\n" @@ -153,8 +166,6 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) { prefix, path_type_to_string(s->type), s->path); - - free(p2); } static void path_unwatch_one(Path *p, PathSpec *s) { @@ -170,9 +181,9 @@ static void path_unwatch_one(Path *p, PathSpec *s) { 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, + [PATH_EXISTS] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB, [PATH_CHANGED] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_MOVED_FROM|IN_MOVED_TO, - [PATH_DIRECTORY_NOT_EMPTY] = IN_DELETE_SELF|IN_MOVE_SELF|IN_CREATE|IN_MOVED_TO + [PATH_DIRECTORY_NOT_EMPTY] = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB|IN_CREATE|IN_MOVED_TO }; bool exists = false; @@ -210,9 +221,9 @@ static int path_watch_one(Path *p, PathSpec *s) { *slash = 0; - flags = IN_DELETE_SELF|IN_MOVE_SELF; + flags = IN_DELETE_SELF|IN_MOVE_SELF|IN_ATTRIB; if (!exists) - flags |= IN_CREATE | IN_MOVED_TO | IN_ATTRIB; + flags |= IN_CREATE | IN_MOVED_TO; if (inotify_add_watch(s->inotify_fd, k, flags) >= 0) exists = true; @@ -294,7 +305,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) { @@ -304,6 +315,10 @@ static void path_enter_running(Path *p) { assert(p); dbus_error_init(&error); + /* Don't start job if we are supposed to go down */ + if (p->meta.job && p->meta.job->type == JOB_STOP) + return; + if ((r = manager_add_job(p->meta.manager, JOB_START, p->unit, JOB_REPLACE, true, &error, NULL)) < 0) goto fail; @@ -372,13 +387,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; } @@ -441,7 +457,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); @@ -481,16 +498,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); @@ -545,11 +568,22 @@ fail: log_error("Failed find path unit: %s", strerror(-r)); } +static void path_reset_failed(Unit *u) { + Path *p = PATH(u); + + assert(p); + + if (p->state == PATH_FAILED) + path_set_state(p, PATH_DEAD); + + p->failure = false; +} + 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); @@ -583,5 +617,8 @@ const UnitVTable path_vtable = { .fd_event = path_fd_event, + .reset_failed = path_reset_failed, + + .bus_interface = "org.freedesktop.systemd1.Path", .bus_message_handler = bus_path_message_handler };