From 60eef55f01edba78e9664dcf7bf77d2fa0a30671 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 25 Nov 2009 16:23:06 -0500 Subject: [PATCH] Add a watchdog timer for ShutDownAndCore(PANIC) Add a watchdog timer that is started when ShutDownAndCore(PANIC) is called, to ensure we actually panic and do not e.g. get stuck in deadlock. Reviewed-on: http://gerrit.openafs.org/873 Tested-by: Andrew Deason Reviewed-by: Alistair Ferguson Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear (cherry picked from commit 9bff2027cb963343778001512d5cdf00cc7094c6) Change-Id: If91606ff50aa19a614edf51e274d055bb8b30618 Reviewed-on: http://gerrit.openafs.org/991 Tested-by: Andrew Deason Reviewed-by: Derrick Brashear --- src/viced/viced.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/viced/viced.c b/src/viced/viced.c index 20705f0b6..59e69777f 100644 --- a/src/viced/viced.c +++ b/src/viced/viced.c @@ -173,6 +173,12 @@ int SawLock; #endif time_t StartTime; +/** + * seconds to wait until forcing a panic during ShutDownAndCore(PANIC) + * in case we get stuck. + */ +static int panic_timeout = 30 * 60; + int rxpackets = 150; /* 100 */ int nSmallVns = 400; /* 200 */ int large = 400; /* 200 */ @@ -639,12 +645,36 @@ CheckSignal(void *unused) return NULL; } /*CheckSignal */ +static void * +ShutdownWatchdogLWP(void *unused) +{ + sleep(panic_timeout); + ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic " + "within %d seconds; forcing panic\n", panic_timeout)); + assert(0); + return NULL; +} + void ShutDownAndCore(int dopanic) { time_t now = time(0); char tbuffer[32]; + if (dopanic) { +#ifdef AFS_PTHREAD_ENV + pthread_t watchdogPid; + pthread_attr_t tattr; + assert(pthread_attr_init(&tattr) == 0); + assert(pthread_create(&watchdogPid, &tattr, ShutdownWatchdogLWP, NULL) == 0); +#else + PROCESS watchdogPid; + assert(LWP_CreateProcess + (ShutdownWatchdogLWP, stack * 1024, LWP_MAX_PRIORITY - 2, + NULL, "ShutdownWatchdog", &watchdogPid) == LWP_SUCCESS); +#endif + } + ViceLog(0, ("Shutting down file server at %s", afs_ctime(&now, tbuffer, sizeof(tbuffer)))); -- 2.39.5