]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/killall: Log the process names not killed after 10s
authorBenjamin Robin <dev@benjarobin.fr>
Sat, 6 Apr 2019 16:40:44 +0000 (18:40 +0200)
committerBenjamin Robin <dev@benjarobin.fr>
Wed, 10 Apr 2019 17:27:38 +0000 (19:27 +0200)
src/core/killall.c

index 7ff9e3a24606bb166c2a66c1efa95c30d9ae5f41..056b36f07bba24144ebae05a045d17e74b8ad3ae 100644 (file)
@@ -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) {