Cross reference for modules/sk/cd_watchdog.c of index.

# File modules/sk/cd_watchdog.c

      $Revision: 1.2 $

      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

- `#include "modules/sk/sk.h"`
  - `#include "include/stubs.h"`
    - `#include <stdlib.h>`
    - `#include <stdio.h>`
    - `#include <ctype.h>`
  - `#include <sys/types.h>`
  - `#include <sys/socket.h>`
  - `#include <netinet/in.h>`
  - `#include <netdb.h>`
  - `#include <pthread.h>`
  - `#include <stdlib.h>`
  - `#include <errno.h>`
  - `#include <fcntl.h>`
  - `#include <signal.h>`
  - `#include <stdio.h>`
  - `#include "include/iproutines.h"`
    - `#include <sys/types.h>`
    - `#include <glib.h>`
    - `#include <include/inet6def.h>`
    - `#include <include/erroutines.h>`

## Preprocessor definitions

String sizes

`#define STR_S 63`

## 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: | modules/sk/sk.h
Calls: | pthread_once()
References Functions: | sk_real_init() | modules/sk/cd_watchdog.c
References Variables: | sk_init_once | modules/sk/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: | modules/sk/sk.h
Called by: | QI_execute() | modules/qi/query_instructions.c
| sql_execute_watched() | modules/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: | modules/sk/sk.h
Called by: | sql_execute_watched() | modules/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: | modules/sk/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: | modules/sk/sk.h
Called by: | SK_watchtrigger() | modules/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: | modules/sk/sk.h
Calls: | pthread_cancel()
Called by: | SK_watchtrigger() | modules/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: | modules/sk/sk.h
Calls: | fprintf(), pthread_create(), pthread_mutex_init(), pthread_mutex_lock()
Called by: | QI_execute() | modules/qi/query_instructions.c
| sql_execute_watched() | modules/qi/query_instructions.c
References Functions: | sk_watchdog() | modules/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: | modules/sk/sk.h
Calls: | pthread_cancel(), pthread_join(), pthread_mutex_destroy(), pthread_mutex_lock()
Called by: | QI_execute() | modules/qi/query_instructions.c
| sql_execute_watched() | modules/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: | modules/sk/sk.h
Calls: | SK_watchexec() | modules/sk/cd_watchdog.c
| SK_watchkill() | modules/sk/cd_watchdog.c
Called by: | sk_watchdog() | modules/sk/cd_watchdog.c

## Local Function sk_real_init()

      initialisation for the PTHREAD_CANCEL mode is not needed.

`static void sk_real_init ( void )`

Used in: | SK_init() | modules/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() | modules/er/er.c
| SK_watchtrigger() | modules/sk/cd_watchdog.c
| memset(), pthread_mutex_unlock(), pthread_setcancelstate(), pthread_setcanceltype(), read(), select()
Used in: | SK_watchstart() | modules/sk/cd_watchdog.c