X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fmanager.c;h=2e89f19839add470275f2b72bb1e74ec5a79ca1d;hb=7989e1f2d79891ff73dea0ede1c98c47b62547db;hp=42423985bc8fe11ee61950beaa317660b3d4a08e;hpb=9e9e2b722cf796b58e959cd174d87ce0ec0bc996;p=elogind.git diff --git a/src/core/manager.c b/src/core/manager.c index 42423985b..2e89f1983 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -95,7 +95,7 @@ static int manager_setup_notify(Manager *m) { struct sockaddr_un un; } sa; struct epoll_event ev; - int one = 1; + int one = 1, r; assert(m); @@ -116,12 +116,15 @@ static int manager_setup_notify(Manager *m) { sa.un.sun_path[0] = 0; - if (bind(m->notify_watch.fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) { + r = bind(m->notify_watch.fd, &sa.sa, + offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)); + if (r < 0) { log_error("bind() failed: %m"); return -errno; } - if (setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) { + r = setsockopt(m->notify_watch.fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)); + if (r < 0) { log_error("SO_PASSCRED failed: %m"); return -errno; } @@ -130,7 +133,8 @@ static int manager_setup_notify(Manager *m) { ev.events = EPOLLIN; ev.data.ptr = &m->notify_watch; - if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev) < 0) { + r = epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev); + if (r < 0) { log_error("Failed to add notification socket fd to epoll: %m"); return -errno; } @@ -148,6 +152,9 @@ static int manager_setup_notify(Manager *m) { static int manager_jobs_in_progress_mod_timer(Manager *m) { struct itimerspec its; + if (m->jobs_in_progress_watch.type != WATCH_JOBS_IN_PROGRESS) + return 0; + zero(its); its.it_value.tv_sec = JOBS_IN_PROGRESS_WAIT_SEC; @@ -223,36 +230,26 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po assert(pos <= width+1); /* 0 or width+1 mean that the center light is behind the corner */ if (pos > 1) { - if (pos > 2) { - memset(p, ' ', pos-2); - p += pos-2; - } - memcpy(p, ANSI_RED_ON, strlen(ANSI_RED_ON)); - p += strlen(ANSI_RED_ON); + if (pos > 2) + p = mempset(p, ' ', pos-2); + p = stpcpy(p, ANSI_RED_ON); *p++ = '*'; } if (pos > 0 && pos <= width) { - memcpy(p, ANSI_HIGHLIGHT_RED_ON, strlen(ANSI_HIGHLIGHT_RED_ON)); - p += strlen(ANSI_HIGHLIGHT_RED_ON); + p = stpcpy(p, ANSI_HIGHLIGHT_RED_ON); *p++ = '*'; } - memcpy(p, ANSI_HIGHLIGHT_OFF, strlen(ANSI_HIGHLIGHT_OFF)); - p += strlen(ANSI_HIGHLIGHT_OFF); + p = stpcpy(p, ANSI_HIGHLIGHT_OFF); if (pos < width) { - memcpy(p, ANSI_RED_ON, strlen(ANSI_RED_ON)); - p += strlen(ANSI_RED_ON); + p = stpcpy(p, ANSI_RED_ON); *p++ = '*'; - if (pos < width-1) { - memset(p, ' ', width-1-pos); - p += width-1-pos; - } - memcpy(p, ANSI_HIGHLIGHT_OFF, strlen(ANSI_HIGHLIGHT_OFF)); - p += strlen(ANSI_HIGHLIGHT_OFF); + if (pos < width-1) + p = mempset(p, ' ', width-1-pos); + p = stpcpy(p, ANSI_HIGHLIGHT_OFF); } - *p = 0; } static void manager_print_jobs_in_progress(Manager *m) { @@ -269,8 +266,9 @@ static void manager_print_jobs_in_progress(Manager *m) { if (j->state == JOB_RUNNING && counter++ == print_nr) break; - if (!j) - return; + /* m->n_running_jobs must be consistent with the contents of m->jobs, + * so the above loop must have succeeded in finding j. */ + assert(counter == print_nr + 1); cylon_pos = m->jobs_in_progress_iteration % 14; if (cylon_pos >= 8) @@ -1143,7 +1141,7 @@ unsigned manager_dispatch_run_queue(Manager *m) { m->dispatching_run_queue = false; - if (hashmap_size(m->jobs) > 0) + if (m->n_running_jobs > 0) manager_watch_jobs_in_progress(m); return n; @@ -1194,7 +1192,7 @@ static int manager_process_notify_fd(Manager *m) { uint8_t buf[CMSG_SPACE(sizeof(struct ucred))]; } control; Unit *u; - char **tags; + char _cleanup_strv_free_ **tags = NULL; zero(iovec); iovec.iov_base = buf; @@ -1247,8 +1245,6 @@ static int manager_process_notify_fd(Manager *m) { if (UNIT_VTABLE(u)->notify_message) UNIT_VTABLE(u)->notify_message(u, ucred->pid, tags); - - strv_free(tags); } return 0; @@ -1673,6 +1669,8 @@ static int process_event(Manager *m, struct epoll_event *ev) { NULL); /* Restart the watch */ + epoll_ctl(m->epoll_fd, EPOLL_CTL_DEL, m->time_change_watch.fd, + NULL); close_nointr_nofail(m->time_change_watch.fd); watch_init(&m->time_change_watch); manager_setup_time_change(m); @@ -1902,7 +1900,8 @@ void manager_send_unit_plymouth(Manager *m, Unit *u) { /* We set SOCK_NONBLOCK here so that we rather drop the * message then wait for plymouth */ - if ((fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0)) < 0) { + fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); + if (fd < 0) { log_error("socket() failed: %m"); return; } @@ -2337,6 +2336,12 @@ static bool manager_is_booting_or_shutting_down(Manager *m) { return false; } +bool manager_is_reloading_or_reexecuting(Manager *m) { + assert(m); + + return m->n_reloading != 0; +} + void manager_reset_failed(Manager *m) { Unit *u; Iterator i; @@ -2367,6 +2372,9 @@ void manager_check_finished(Manager *m) { assert(m); + if (m->n_running_jobs == 0) + manager_unwatch_jobs_in_progress(m); + if (hashmap_size(m->jobs) > 0) { manager_jobs_in_progress_mod_timer(m); return; @@ -2378,8 +2386,6 @@ void manager_check_finished(Manager *m) { /* Turn off confirm spawn now */ m->confirm_spawn = false; - manager_unwatch_jobs_in_progress(m); - if (dual_timestamp_is_set(&m->finish_timestamp)) return; @@ -2479,9 +2485,9 @@ static int create_generator_dir(Manager *m, char **generator, const char *name) return log_oom(); if (!mkdtemp(p)) { - free(p); log_error("Failed to create generator directory %s: %m", p); + free(p); return -errno; } }