X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fmanager.c;h=b181aa0453eb9a7b593d20d10f5cfa428bc8316a;hb=6294b8a92db8579210d4fc9ce74097a15005b3e6;hp=76c8daceacc797d94bede6e03ed84f72e48e6232;hpb=2cba2e03524ec0922ddc70f933e8a89b7d23b4ec;p=elogind.git diff --git a/src/core/manager.c b/src/core/manager.c index 76c8dacea..b181aa045 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -80,8 +80,8 @@ #define GC_QUEUE_USEC_MAX (10*USEC_PER_SEC) /* Initial delay and the interval for printing status messages about running jobs */ -#define JOBS_IN_PROGRESS_WAIT_SEC 5 -#define JOBS_IN_PROGRESS_PERIOD_SEC 1 +#define JOBS_IN_PROGRESS_WAIT_USEC (5*USEC_PER_SEC) +#define JOBS_IN_PROGRESS_PERIOD_USEC (USEC_PER_SEC / 3) #define JOBS_IN_PROGRESS_PERIOD_DIVISOR 3 /* Where clients shall send notification messages to */ @@ -97,12 +97,16 @@ static int manager_dispatch_jobs_in_progress(sd_event_source *source, usec_t use static int manager_dispatch_run_queue(sd_event_source *source, void *userdata); static int manager_watch_jobs_in_progress(Manager *m) { + usec_t next; + assert(m); if (m->jobs_in_progress_event_source) return 0; - return sd_event_add_monotonic(m->event, JOBS_IN_PROGRESS_WAIT_SEC, 0, manager_dispatch_jobs_in_progress, m, &m->jobs_in_progress_event_source); + next = now(CLOCK_MONOTONIC) + JOBS_IN_PROGRESS_WAIT_USEC; + log_debug("queuing for "USEC_FMT, next); + return sd_event_add_monotonic(m->event, next, 0, manager_dispatch_jobs_in_progress, m, &m->jobs_in_progress_event_source); } #define CYLON_BUFFER_EXTRA (2*(sizeof(ANSI_RED_ON)-1) + sizeof(ANSI_HIGHLIGHT_RED_ON)-1 + 2*(sizeof(ANSI_HIGHLIGHT_OFF)-1)) @@ -136,6 +140,16 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po } } +void manager_flip_auto_status(Manager *m, bool enable) { + if (enable) { + if (m->show_status == SHOW_STATUS_AUTO) + manager_set_show_status(m, SHOW_STATUS_TEMPORARY); + } else { + if (m->show_status == SHOW_STATUS_TEMPORARY) + manager_set_show_status(m, SHOW_STATUS_AUTO); + } +} + static void manager_print_jobs_in_progress(Manager *m) { _cleanup_free_ char *job_of_n = NULL; Iterator i; @@ -148,6 +162,8 @@ static void manager_print_jobs_in_progress(Manager *m) { assert(m); + manager_flip_auto_status(m, true); + print_nr = (m->jobs_in_progress_iteration / JOBS_IN_PROGRESS_PERIOD_DIVISOR) % m->n_running_jobs; HASHMAP_FOREACH(j, m->jobs, i) @@ -1637,12 +1653,12 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t case 20: log_debug("Enabling showing of status."); - manager_set_show_status(m, true); + manager_set_show_status(m, SHOW_STATUS_YES); break; case 21: log_debug("Disabling showing of status."); - manager_set_show_status(m, false); + manager_set_show_status(m, SHOW_STATUS_NO); break; case 22: @@ -1741,11 +1757,21 @@ static int manager_dispatch_idle_pipe_fd(sd_event_source *source, int fd, uint32 static int manager_dispatch_jobs_in_progress(sd_event_source *source, usec_t usec, void *userdata) { Manager *m = userdata; + int r; + uint64_t next; assert(m); + assert(source); manager_print_jobs_in_progress(m); - return 0; + + next = now(CLOCK_MONOTONIC) + JOBS_IN_PROGRESS_PERIOD_USEC; + log_debug("requeuing for "USEC_FMT, next); + r = sd_event_source_set_time(source, next); + if (r < 0) + return r; + + return sd_event_source_set_enabled(source, SD_EVENT_ONESHOT); } int manager_loop(Manager *m) { @@ -1996,28 +2022,17 @@ void manager_dispatch_bus_name_owner_changed( } int manager_open_serialization(Manager *m, FILE **_f) { - _cleanup_free_ char *path = NULL; + const char *path; int fd = -1; FILE *f; assert(_f); - if (m->running_as == SYSTEMD_SYSTEM) - asprintf(&path, "/run/systemd/dump-"PID_FMT"-XXXXXX", getpid()); - else - asprintf(&path, "/tmp/systemd-dump-"PID_FMT"-XXXXXX", getpid()); - - if (!path) - return -ENOMEM; - - RUN_WITH_UMASK(0077) { - fd = mkostemp(path, O_RDWR|O_CLOEXEC); - } - + path = m->running_as == SYSTEMD_SYSTEM ? "/run/systemd" : "/tmp"; + fd = open_tmpfile(path, O_RDWR|O_CLOEXEC); if (fd < 0) return -errno; - unlink(path); log_debug("Serializing state to %s", path); f = fdopen(fd, "w+"); @@ -2451,11 +2466,16 @@ void manager_check_finished(Manager *m) { m->jobs_in_progress_event_source = sd_event_source_unref(m->jobs_in_progress_event_source); if (hashmap_size(m->jobs) > 0) { - if (m->jobs_in_progress_event_source) - sd_event_source_set_time(m->jobs_in_progress_event_source, JOBS_IN_PROGRESS_PERIOD_SEC); + if (m->jobs_in_progress_event_source) { + uint64_t next = now(CLOCK_MONOTONIC) + JOBS_IN_PROGRESS_WAIT_USEC; + log_debug("requeuing for "USEC_FMT, next); + sd_event_source_set_time(m->jobs_in_progress_event_source, next); + } return; } + manager_flip_auto_status(m, false); + /* Notify Type=idle units that we are done now */ m->idle_pipe_event_source = sd_event_source_unref(m->idle_pipe_event_source); manager_close_idle_pipe(m); @@ -2754,15 +2774,16 @@ void manager_recheck_journal(Manager *m) { log_open(); } -void manager_set_show_status(Manager *m, bool b) { +void manager_set_show_status(Manager *m, ShowStatus mode) { assert(m); + assert(IN_SET(mode, SHOW_STATUS_AUTO, SHOW_STATUS_NO, SHOW_STATUS_YES, SHOW_STATUS_TEMPORARY)); if (m->running_as != SYSTEMD_SYSTEM) return; - m->show_status = b; + m->show_status = mode; - if (b) + if (mode > 0) touch("/run/systemd/show-status"); else unlink("/run/systemd/show-status"); @@ -2777,7 +2798,7 @@ static bool manager_get_show_status(Manager *m) { if (m->no_console_output) return false; - if (m->show_status) + if (m->show_status > 0) return true; /* If Plymouth is running make sure we show the status, so