]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Add a watchdog timer for ShutDownAndCore(PANIC)
authorAndrew Deason <adeason@sinenomine.net>
Wed, 25 Nov 2009 21:23:06 +0000 (16:23 -0500)
committerDerrick Brashear <shadow|account-1000005@unknown>
Thu, 17 Dec 2009 18:24:48 +0000 (10:24 -0800)
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 <adeason@sinenomine.net>
Reviewed-by: Alistair Ferguson <alistair.ferguson@mac.com>
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit 9bff2027cb963343778001512d5cdf00cc7094c6)

Change-Id: If91606ff50aa19a614edf51e274d055bb8b30618
Reviewed-on: http://gerrit.openafs.org/991
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
src/viced/viced.c

index 20705f0b67e8ca5f946f2cd2f8c3a28640e45f9c..59e69777f6825567f67c71ced7483b96bf234a1a 100644 (file)
@@ -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))));