File sk/cd_watchdog.c

  $Revision: 1.8 $

Socket module - cd_watchdog.c - Socket watchdog - when activated, checks the socket for new data and discards it. If the socket is closed, it triggers predefined functions - executes a function and/or cancels a thread.
Status: NOT REVUED, TESTED
Design and implementation by Marek Bukowy.
Modification history: marek (August 2000) Created the watchdog part marek (December 2000) Modified watchdog deactivation - replaced signals by pthread cancellation.

Included Files


Global Variable Lock

pthread_mutex_t Lock
Included from /home/shane/code/RIP/include/ca_defs.h
Visible in:  aa/aa.c
   ac/access_control.c
   ca/ca_configFns.c
   ca/ca_initFn.c
   ca/ca_sanityCheck.c
   ca/ca_sourceLoader.c
   ca/ca_values.c
   co/constants.c
   df/defs.c
   er/er.c
   er/er_arrays.c
   er/er_macro.c
   er/er_paths.c
   er/er_print.c
   ip/ip.c
   ma/bitmask.c
   mm/mm.c
   nh/nh.c
   pa/gpg.c
   pa/spawn.c
   pc/pc_commands.c
   pc/protocol_config.c
   pm/pm_serials.c
   pm/protocol_mirror.c
   pr/properties.c
   pw/protocol_whois.c
   qc/mg_getopt.c
   qc/query_command.c
   qi/query_instructions.c
   rp/rp_convert.c
   rp/rp_load.c
   rp/rp_search.c
   rp/rp_tree.c
   rp/rp_update.c
   rx/rx_node.c
   rx/rx_print.c
   rx/rx_search.c
   rx/rx_tree.c
   sk/cd_socket.c
   sk/cd_watchdog.c
Used in: ca_get_adminIntElement()ca/ca_configFns.c
  ca_get_adminStrElement()ca/ca_configFns.c
  ca_get_boolean()ca/ca_configFns.c
  ca_get_dirlist()ca/ca_configFns.c
  ca_get_int()ca/ca_configFns.c
  ca_get_string()ca/ca_configFns.c
  ca_set_boolean()ca/ca_configFns.c
  ca_srchandle2Intelement()ca/ca_configFns.c
  ca_srchandle2Strelement()ca/ca_configFns.c

Local Variables

sk_init_once
Uncomment this to use watchdog deactivation by signal (may be risky)
#define WATCHDOG_BY_SIGNAL

static pthread_once_t sk_init_once
Used in: SK_init()


Global Function SK_init()

  Initialisation function, should be called exactly once 
  (well, it ignores repeated calls). The actions depend on cancellation
  mode (signal or pthread_cancel).
void SK_init ( void )
Prototyped in: /home/shane/code/RIP/include/sk.h
Calls: pthread_once()
References Functions: sk_real_init()sk/cd_watchdog.c
References Variables: sk_init_oncesk/cd_watchdog.c

Global Function SK_watch_setclear()

void SK_watch_setclear ( sk_conn_st* condat )
sk_conn_st* condat
pointer to the connection data structure.
Prototyped in: /home/shane/code/RIP/include/sk.h
Called by: QI_execute()qi/query_instructions.c
  sql_execute_watched()qi/query_instructions.c

Global Function SK_watch_setexec()

void SK_watch_setexec ( sk_conn_st* condat, void* (*function)(void*), void* args )
sk_conn_st* condat
pointer to the connection data structure.
void* (*function)(void*)
function to be invoked
void* args
argument to be passed to the function.
Prototyped in: /home/shane/code/RIP/include/sk.h
Called by: sql_execute_watched()qi/query_instructions.c

Global Function SK_watch_setkill()

void SK_watch_setkill ( sk_conn_st* condat, pthread_t killthis )
sk_conn_st* condat
pointer to the connection data structure.
pthread_t killthis
thread id of the thread to be cancelled, or 0.
Prototyped in: /home/shane/code/RIP/include/sk.h

Global Function SK_watchexec()

void SK_watchexec ( sk_conn_st* condat )
sk_conn_st* condat
pointer to the connection data structure.
Prototyped in: /home/shane/code/RIP/include/sk.h
Called by: SK_watchtrigger()sk/cd_watchdog.c

Global Function SK_watchkill()

void SK_watchkill ( sk_conn_st* condat )
sk_conn_st* condat
pointer to the connection data structure.
Prototyped in: /home/shane/code/RIP/include/sk.h
Calls: pthread_cancel()
Called by: SK_watchtrigger()sk/cd_watchdog.c

Global Function SK_watchstart()

   starts sk_watchdog thread unless already started,
   and registers its threadid in the condat structure

dies if watchdog already running
The structure may (and normally, should) contain the predefined actions set by SK_watch_set... functions.
er_ret_t SK_watchstart ( sk_conn_st* condat )
er_ret_t SK_watchstart
Returns SK_OK on success.
sk_conn_st* condat
pointer to the connection data structure
Prototyped in: /home/shane/code/RIP/include/sk.h
Calls: fprintf(), pthread_attr_destroy(), pthread_attr_getstacksize(), pthread_attr_init(), pthread_attr_setstacksize(), pthread_create(), pthread_mutex_init(), pthread_mutex_lock()
Called by: QI_execute()qi/query_instructions.c
  sql_execute_watched()qi/query_instructions.c
References Functions: sk_watchdog()sk/cd_watchdog.c

Global Function SK_watchstop()

  stops running sk_watchdog thread. 
  If it is not running ( == not registered in the connection struct), 
  it does nothing.
er_ret_t SK_watchstop ( sk_conn_st* condat )
er_ret_t SK_watchstop
always succeeds (returns SK_OK)
sk_conn_st* condat
pointer to the connection data structure
Prototyped in: /home/shane/code/RIP/include/sk.h
Calls: pthread_cancel(), pthread_join(), pthread_mutex_destroy(), pthread_mutex_lock()
Called by: QI_execute()qi/query_instructions.c
  sql_execute_watched()qi/query_instructions.c

Global Function SK_watchtrigger()

void SK_watchtrigger ( sk_conn_st* condat )
sk_conn_st* condat
pointer to the connection data structure.
Prototyped in: /home/shane/code/RIP/include/sk.h
Calls: SK_watchexec()sk/cd_watchdog.c
  SK_watchkill()sk/cd_watchdog.c
Called by: sk_watchdog()sk/cd_watchdog.c

Local Function asctime_r()

static char* asctime_r ( const struct tm* __tm, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_asctime_r()

Local Function ctime_r()

static char* ctime_r ( const time_t* __time, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_ctime_r()

Local Function getlogin_r()

static int getlogin_r ( char* __name, int __len )
Included from: /usr/include/unistd.h
Calls: __posix_getlogin_r()

Local Function readdir_r()

static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
Included from: /usr/include/dirent.h
Calls: __posix_readdir_r()

Local Function sigwait()

static int sigwait ( const sigset_t* __setp, int* __signo )
Included from: /usr/include/signal.h
Calls: __posix_sigwait()

Local Function sk_real_init()

  initialisation for the PTHREAD_CANCEL mode is not needed.
static void sk_real_init ( void )
Used in: SK_init()sk/cd_watchdog.c

Local Function sk_watchdog()

  watchdog (CANCEL VERSION) - started as a separate thread. 

Selects on the given socket; discards all input. whenever it sees end of file (socket closed), it * sets a corresponding flag in the condat structure, * triggers the predefined actions (by SK_watchtrigger).
static void* sk_watchdog ( void* arg )
void* arg
- pointer to the connection data structure
Calls: ER_dbg_va()er/er.c
  SK_watchtrigger()sk/cd_watchdog.c
  memset(), pthread_mutex_unlock(), pthread_setcancelstate(), pthread_setcanceltype(), read(), select()
Used in: SK_watchstart()sk/cd_watchdog.c

Local Function ttyname_r()

static int ttyname_r ( int __fildes, char* __buf, size_t __size )
Included from: /usr/include/unistd.h
Calls: __posix_ttyname_r()