watchdog.c File Reference

SIGALRM/Watchdog for Windows/Linux. More...

#include "ctl/ctldef.h"
#include "ctl/watchdog.h"
#include <unistd.h>
#include <signal.h>

Include dependency graph for watchdog.c:

Go to the source code of this file.

Functions

ctl_watchdog_handler ctl_watchdog_init (ctl_watchdog_handler handler)
void ctl_watchdog_kick (int milliseconds)
void ctl_watchdog_shutdown ()


Detailed Description

SIGALRM/Watchdog for Windows/Linux.

Author:
David Mace In a POSIX compliant OS, uses SIGALRM as a watchdog timer Under Windows, create a sleeping thread to wake up and invoke callback

Definition in file watchdog.c.


Function Documentation

ctl_watchdog_handler ctl_watchdog_init ( ctl_watchdog_handler  handler  ) 

Initialize the watchdog; you have one minute to kick it

Parameters:
handler Watchdog handler callback to call when 'kick' doesn't happen
Returns:
Old handler, if any

Definition at line 59 of file watchdog.c.

References assertcodeptr, and ctl_mstime().

00060 {
00061     ctl_watchdog_handler old = wd_handler;
00062     wd_handler = NULL == handler ? ctl_watchdog_handler_default : handler;
00063     assertcodeptr(wd_handler);
00064 #ifdef WIN32
00065     msexpire = ctl_mstime() + 60000;
00066     hSleepy = CreateEvent( NULL, FALSE, FALSE, NULL );
00067     hThread = (HANDLE)_beginthread( WatchdogThreadProc, 0, NULL );
00068 #else
00069     {   /* Assume POSIX */
00070         struct sigaction action;
00071         action.sa_handler = sigalrm_callback;
00072         sigemptyset(&action.sa_mask);
00073         action.sa_flags = 0;
00074         /* alarm() is our watchdog */
00075         sigaction(SIGALRM, &action, NULL);
00076     }
00077     alarm(60);
00078 #endif
00079     return old;
00080 }

Here is the call graph for this function:

void ctl_watchdog_kick ( int  milliseconds  ) 

Initialize the watchdog

Parameters:
milliseconds How long until watchdog callback is triggered We only have second precision, but it gets confusing consistently dealing with milliseconds in other places

Definition at line 87 of file watchdog.c.

References ctl_mstime().

00088 {
00089 #ifdef WIN32
00090     msexpire = ctl_mstime() + milliseconds;
00091     SetEvent( hSleepy );
00092 #else
00093     alarm((milliseconds+999)/1000);
00094 #endif
00095 }

Here is the call graph for this function:

void ctl_watchdog_shutdown (  ) 

Stop the watchdog

Definition at line 100 of file watchdog.c.

00101 {
00102 #ifdef WIN32
00103     msexpire = 0;
00104     SetEvent( hSleepy );
00105     WaitForSingleObject( hThread, INFINITE );
00106     CloseHandle(hSleepy);
00107     hSleepy = NULL;
00108 #else
00109     alarm(0);
00110 #endif
00111 }


Generated on Fri Jan 2 15:28:36 2009 for Squat by  doxygen 1.5.6