From ae053b30da4db588f7fabe09e5f85cbebdc421ad Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 13 May 2022 11:03:39 +0200 Subject: [PATCH] BUG/MEDIUM: wdt: don't trigger the watchdog when p is unitialized In wdt_handler(), does not try to trigger the watchdog if the prev_cpu_time wasn't initialized. This prevents an unexpected trigger of the watchdog when it wasn't initialized yet. This case could happen in the master just after loading the configuration. This would show a trace where the value is equal to the value in the trace, and the value would be 0. For example: Thread 1 is about to kill the process. *>Thread 1 : id=0x0 act=1 glob=1 wq=0 rq=0 tl=0 tlsz=0 rqsz=0 stuck=1 prof=0 harmless=0 wantrdv=0 cpu_ns: poll=0 now=6005541706 diff=6005541706 curr_task=0 Thanks to Christian Ruppert for repporting the problem. Could be backported in every stable versions. --- src/wdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wdt.c b/src/wdt.c index b9d6ca758..6bb7d85a6 100644 --- a/src/wdt.c +++ b/src/wdt.c @@ -74,8 +74,10 @@ void wdt_handler(int sig, siginfo_t *si, void *arg) p = ha_thread_ctx[thr].prev_cpu_time; n = now_cpu_time_thread(thr); - /* not yet reached the deadline of 1 sec */ - if (n - p < 1000000000UL) + /* not yet reached the deadline of 1 sec, + * or p wasn't initialized yet + */ + if (!p || n - p < 1000000000UL) goto update_and_leave; if ((threads_harmless_mask|sleeping_thread_mask|threads_to_dump) & (1UL << thr)) {