From 2c32f4f47d19f274987862acf671ed2ab98f1dff Mon Sep 17 00:00:00 2001 From: Benjamin Robin Date: Sat, 6 Apr 2019 18:40:44 +0200 Subject: [PATCH] core/killall: Log the process names not killed after 10s --- src/core/killall.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/core/killall.c b/src/core/killall.c index 7ff9e3a2460..056b36f07bb 100644 --- a/src/core/killall.c +++ b/src/core/killall.c @@ -77,8 +77,28 @@ static bool ignore_proc(pid_t pid, bool warn_rootfs) { return true; } +static void log_children_no_yet_killed(Set *pids) { + void *p; + Iterator i; + _cleanup_free_ char *lst_child = NULL; + + SET_FOREACH(p, pids, i) { + _cleanup_free_ char *s = NULL; + + if (get_process_comm(PTR_TO_PID(p), &s) == 0) { + if (!strextend(&lst_child, ", ", s, NULL)) + break; + } + } + + if (!isempty(lst_child)) + log_notice("Waiting for process:%s", lst_child + 1); +} + static int wait_for_children(Set *pids, sigset_t *mask, usec_t timeout) { usec_t until; + usec_t date_log_child; + usec_t n; assert(mask); @@ -88,11 +108,15 @@ static int wait_for_children(Set *pids, sigset_t *mask, usec_t timeout) { if (set_isempty(pids)) return 0; - until = now(CLOCK_MONOTONIC) + timeout; + n = now(CLOCK_MONOTONIC); + until = usec_add(n, timeout); + date_log_child = usec_add(n, 10u * USEC_PER_SEC); + if (date_log_child > until) + date_log_child = usec_add(n, timeout / 2u); + for (;;) { struct timespec ts; int k; - usec_t n; void *p; Iterator i; @@ -135,10 +159,20 @@ static int wait_for_children(Set *pids, sigset_t *mask, usec_t timeout) { return 0; n = now(CLOCK_MONOTONIC); + if (date_log_child > 0 && n >= date_log_child) { + log_children_no_yet_killed(pids); + /* Log the children not yet killed only once */ + date_log_child = 0; + } + if (n >= until) return set_size(pids); - timespec_store(&ts, until - n); + if (date_log_child > 0) + timespec_store(&ts, MIN(until - n, date_log_child - n)); + else + timespec_store(&ts, until - n); + k = sigtimedwait(mask, NULL, &ts); if (k != SIGCHLD) {