[systemd-devel] [PATCH 1/4] manager: print a warning after 2/3 of the start timeout
Lennart Poettering
mzerqung at 0pointer.de
Mon Oct 27 10:49:22 PDT 2014
On Sat, 25.10.14 21:43, Zbigniew Jędrzejewski-Szmek (zbyszek at in.waw.pl) wrote:
> ---
> This could use some more polishing, but is useful as is I think...
I love the idea!
> +static int manager_log_running_jobs(Manager *m) {
> + unsigned n;
> +
> + assert(m);
> +
> + n = hashmap_size(m->jobs);
> +
> + if (n > 0) {
> + unsigned i = 0;
> + _cleanup_strv_free_ char **strv;
> + _cleanup_free_ char *all = NULL;
> +
> + Iterator it;
> + Job *j;
> +
> + strv = new(char*, n + 1);
> + if (!strv)
> + return log_oom();
> +
> + HASHMAP_FOREACH(j, m->jobs, it) {
> + strv[i] = strjoin(j->unit->id, "/", job_type_to_string(j->type),
> + "/", job_state_to_string(j->state), NULL);
> + if (!strv[i])
> + return log_oom();
> + i++;
> + }
> + strv[i] = NULL;
> +
> + all = strv_join(strv, ",\n\t");
> + if (!all)
> + return log_oom();
> +
> + log_info("Active jobs (%u running):\n\t%s.", m->n_running_jobs, all);
> + } else
> + log_info("No jobs seem to be running.");
> +
> + return 0;
> +}
A long-standing TODO list item has been to print something like this
if the user hits C-A-Del 3 times within 1s or so (under the assumption
that he might do this if shutdown gets stuck for some reason). If we have
this function in place, maybe that's something to quickly hookup with
C-A-Del too? (using the ratelimit infrastruturce should make the patch
for detecting the 3-times-within-1s thing trivial)...
> +
> static int manager_watch_jobs_in_progress(Manager *m) {
> usec_t next;
>
> @@ -1015,15 +1054,39 @@ static int manager_distribute_fds(Manager *m, FDSet *fds) {
>
> static int on_start_timeout(sd_event_source *s, usec_t usec, void *userdata) {
> Manager *m = userdata;
> + int r;
>
> assert(s);
> assert(m);
>
> + if (!m->start_timeout_warned) {
> + log_warning("2/3 of the start timeout have passed.");
> + m->start_timeout_warned = true;
> +
> + (void) manager_log_running_jobs(m);
> +
> + r = sd_event_source_set_time(m->start_timeout_event_source,
> + now(CLOCK_MONOTONIC) +
> m->start_timeout_usec / 3);
I think it would be nicer to use the original startup timestamp for
this, instead of invoking now() here again...
In fact, I think I should have used m->userspace_timestamp.monotonic
as base for this in the first place....
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list