Cross reference for modules/er/er.c of index.

# File modules/er/er.c

      $Revision: 1.26 $

      Error reporting (er) er.c - library of functions to uniformly report errors.

      Status: NOT REVUED, PARTLY TESTED

      NOTE: MALLOC ALERT!!! THE REPORTING FUNCTIONS MAY NOT USE DYNAMIC MEMORY!!!
      for one: they wouldn't work if we run out of memory...
      for two: the memory wrappers may have logging enabled, and it would loop.

      Design and implementation by: Marek Bukowy

References Variables: | AC_mod_err | modules/er/er.c
| ER_mod_err | modules/er/er.c
| IP_mod_err | modules/er/er.c
| MM_mod_err | modules/er/er.c
| PA_mod_err | modules/er/er.c
| PC_mod_err | modules/er/er.c
| PM_mod_err | modules/er/er.c
| PW_mod_err | modules/er/er.c
| QC_mod_err | modules/er/er.c
| QI_mod_err | modules/er/er.c
| RP_mod_err | modules/er/er.c
| RX_mod_err | modules/er/er.c
| SK_mod_err | modules/er/er.c
| SQ_mod_err | modules/er/er.c
| SV_mod_err | modules/er/er.c
| TH_mod_err | modules/er/er.c
| UD_mod_err | modules/er/er.c
| UP_mod_err | modules/er/er.c
| UT_mod_err | modules/er/er.c
| WH_mod_err | modules/er/er.c

## Included Files

- `#include <pthread.h>`

- `#include <time.h>`

- `#include <sys/types.h>`

- `#include <sys/stat.h>`

- `#include <fcntl.h>`

- `#include <sys/wait.h>`

- `#include "modules/er/erroutines.h"`
  - `#include <stdio.h>`
  - `#include <unistd.h>`
  - `#include <stdlib.h>`
  - `#include <assert.h>`
  - `#include <time.h>`
  - `#include <stdarg.h>`
  - `#include <strings.h>`
  - `#include <glib.h>`
  - `#include <pthread.h>`
  - `#include <include/bitmask.h>`
  - `#include <include/stubs.h>`
  - `#include "include/thread.h"`
    - `#include <pthread.h>`
  - `#include "modules/er/er_facilities.h"`
    - `#include <include/erroutines.h>`
    - `#include "include/er_RX_errors.h"`
    - `#include "modules/er/er_ER_errors.h"`
    - `#include "include/er_IP_errors.h"`
    - `#include "include/er_UP_errors.h"`
    - `#include "include/er_UT_errors.h"`
    - `#include "include/er_WH_errors.h"`
    - `#include "include/er_RP_errors.h"`
    - `#include "include/er_QI_errors.h"`
    - `#include "include/er_QC_errors.h"`
    - `#include "include/er_PW_errors.h"`
    - `#include "include/er_SK_errors.h"`
    - `#include "include/er_TH_errors.h"`
    - `#include "include/er_SQ_errors.h"`
    - `#include "include/er_PM_errors.h"`
    - `#include "include/er_MM_errors.h"`
    - `#include "include/er_SV_errors.h"`
    - `#include "include/er_AC_errors.h"`
    - `#include "include/er_UD_errors.h"`
    - `#include "include/er_PA_errors.h"`
    - `#include "include/er_PC_errors.h"`
  - `#include "modules/er/er_aspects.h"`
    - `#include "modules/er/erroutines.h"`
  - `#include "modules/er/er_formats.h"`

- `#include "modules/er/er_macro.h"`
  - `#include "include/sk.h"`
    - `#include "include/stubs.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>`

- `#include "modules/er/er_paths.h"`
  - `#include <glib.h>`

## Preprocessor definitions

`#define ER_IMPL`

Fork & exec a program specified with argv, the print msg on its stdin and exit. No redirection of stdout/stderr is done.
MT-note: Solaris fork1() duplicates only the calling thread. So does Posix fork().
char **argv argv array for the exec call
char *msg text payload to be printed on the stdin of forked process
int usepath flag indicating if the PATH environmental variable should be used by the exec call.

`#define PIP_WR 1`

`#define PIP_RD 0`

## Global Variable er_pathtypes

`char* er_pathtypes[]`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c

## Global Variable RX_mod_err

`er_list_t RX_mod_err[]`

Included from | include/er_RX_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable ER_mod_err

`er_list_t ER_mod_err[]`

Included from | modules/er/er_ER_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable IP_mod_err

`er_list_t IP_mod_err[]`

Included from | include/er_IP_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable UP_mod_err

`er_list_t UP_mod_err[]`

Included from | include/er_UP_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable UT_mod_err

`er_list_t UT_mod_err[]`

Included from | include/er_UT_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable WH_mod_err

`er_list_t WH_mod_err[]`

Included from | include/er_WH_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable RP_mod_err

`er_list_t RP_mod_err[]`

Included from | include/er_RP_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable QI_mod_err

`er_list_t QI_mod_err[]`

Included from | include/er_QI_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable QC_mod_err

`er_list_t QC_mod_err[]`

Included from | include/er_QC_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable PW_mod_err

`er_list_t PW_mod_err[]`

Included from | include/er_PW_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable SK_mod_err

`er_list_t SK_mod_err[]`

Included from | include/er_SK_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable TH_mod_err

`er_list_t TH_mod_err[]`

Included from | include/er_TH_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable SQ_mod_err

`er_list_t SQ_mod_err[]`

Included from | include/er_SQ_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable PM_mod_err

`er_list_t PM_mod_err[]`

Included from | include/er_PM_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable MM_mod_err

`er_list_t MM_mod_err[]`

Included from | include/er_MM_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable SV_mod_err

`er_list_t SV_mod_err[]`

Included from | include/er_SV_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable AC_mod_err

`er_list_t AC_mod_err[]`

Included from | include/er_AC_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable UD_mod_err

`er_list_t UD_mod_err[]`

Included from | include/er_UD_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable PA_mod_err

`er_list_t PA_mod_err[]`

Included from | include/er_PA_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable PC_mod_err

`er_list_t PC_mod_err[]`

Included from | include/er_PC_errors.h
Visible in: |  | modules/er/er.c
Used in: |  | modules/er/er.c

## Global Variable er_fac_err

`er_fac_t er_fac_err[]`

Included from | modules/er/er_facilities.h
Visible in: |  | modules/er/er.c
Used in: | er_format_line() | modules/er/er.c

## Global Variable er_asparr

`er_aspstr_t er_asparr[]`

Included from | modules/er/er_aspects.h
Visible in: |  | modules/er/er.c

## Global Variable er_formarr

`er_form_el er_formarr[]`

Included from | modules/er/er_formats.h
Visible in: |  | modules/er/er.c

## Global Variable er_level_a

`er_level_t er_level_a[]`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c

## Global Variable er_pathlist

`GList* er_pathlist`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c
Used in: | er_logit() | modules/er/er.c

## Global Variable er_asparray

`er_mask_t er_asparray[FAC_LAST]`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c
Used in: | ER_is_traced() | modules/er/er.c

## Global Variable er_paths_lock

`rw_lock_t er_paths_lock`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c
Used in: | ER_init() | modules/er/er.c
| ER_is_traced() | modules/er/er.c
| er_logit() | modules/er/er.c

## Global Variable er_macro_hash

`GHashTable* er_macro_hash`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c
Used in: | ER_init() | modules/er/er.c

## Global Variable er_progname

`char er_progname[32]`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c
Used in: | ER_init() | modules/er/er.c
| er_format_line() | modules/er/er.c

## Global Variable er_pid

`char er_pid[16]`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c
Used in: | ER_init() | modules/er/er.c
| er_format_line() | modules/er/er.c

## Global Variable er_pathlist_mutex

`pthread_mutex_t er_pathlist_mutex`

Included from | modules/er/erroutines.h
Visible in: |  | modules/er/er.c

## Global Function ER_dbg_va()

      Entry point for debug/trace messages - this function will display a
      message tagged with the DEBUG severity.

      int sev                severity of the message

`void ER_dbg_va ( er_fac_code_t facwhere, er_mask_t asp, char* txt, ... )`

`er_fac_code_t facwhere`
  code of facility from which the error is reported
`er_mask_t asp`
  aspect of the message
`char* txt`
  printf-style format
`...`
  printf-style arguments, if any

Prototyped in: | modules/er/erroutines.h
Calls: | ER_is_traced() | modules/er/er.c
| er_getmsg_parts() | modules/er/er.c
| er_logit() | modules/er/er.c
| __builtin_next_arg(), __builtin_saveregs()
Called by: | AC_decay() | modules/ac/access_control.c
| AC_decay_hook() | modules/ac/access_control.c
| AC_prune() | modules/ac/access_control.c

## Global Function ER_inf_va()

      Entry point for informational messages - this function will display a
      message tagged with the INFO severity.

      int sev                severity of the message

`void ER_inf_va ( er_fac_code_t facwhere, er_mask_t asp, char* txt, ... )`

`er_fac_code_t facwhere`
  code of facility from which the error is reported
`er_mask_t asp`
  aspect of the message
`char* txt`
  printf-style format
`...`
  printf-style arguments, if any

Prototyped in: | modules/er/erroutines.h
Calls: | er_asp_va() | modules/er/er.c
| __builtin_next_arg(), __builtin_saveregs()
Called by: | AC_ban_set() | modules/ac/access_control.c

## Global Function ER_init()

      Initialisation function - setting global variables.
      Can be done only by the master thread

`void ER_init ( char* progname, int processdefs )`

`char* progname`
  program name to be used in the log entries
`int processdefs`
  flag if the error definitions of the CA config file should be processed.

Prototyped in: | modules/er/erroutines.h
Calls: | ER_macro_predef(), ER_proc_ca_err(), ER_proc_ca_macro(), TH_init_read_write_lock(), g_hash_table_new(), getpid(), snprintf(), strncpy()
References Functions: | g_str_equal(), g_str_hash()
References Variables: | er_macro_hash | modules/er/er.c
| er_paths_lock | modules/er/er.c
| er_pid | modules/er/er.c
| er_progname | modules/er/er.c

## Global Function ER_is_errorlogged()

`int ER_is_errorlogged ( er_fac_code_t facwhere, int errcode )`

Called by: | ER_perror() | modules/er/er.c

## Global Function ER_is_traced()

`int ER_is_traced ( er_fac_code_t facwhere, er_mask_t asp )`

Prototyped in: | modules/er/erroutines.h
Calls: | TH_acquire_read_lock(), TH_release_read_lock()
Called by: | ER_dbg_va() | modules/er/er.c
References Variables: | er_asparray | modules/er/er.c
| er_paths_lock | modules/er/er.c

## Global Function ER_perror()

      Entry point for predefined errors - this function will display a
      predefined message for this error along with additional text.

`void ER_perror ( er_fac_code_t facwhere, int errcode, char* format, ... )`

`er_fac_code_t facwhere`
  code of facility from which the error is reported
`int errcode`
  error code
`char* format`
  printf-style format for additional text, or ""
`...`
  printf-style arguments, if any

Prototyped in: | modules/er/erroutines.h
Calls: | ER_is_errorlogged() | modules/er/er.c
| er_getmsg_parts() | modules/er/er.c
| er_logit() | modules/er/er.c
| __builtin_next_arg(), __builtin_saveregs()

## Global Function NOERR()

      Simple check if the error code is a success (severity = 0).
      Detects (some) invalid codes - those whose facility part is 0.

`int NOERR ( er_ret_t a )`

`int NOERR`
  returns 1 if the code is valid and is a success returns 0 if the code is invalid or is a real error (the severity is non-zero).
`er_ret_t a`
  error code to be checked.

Prototyped in: | modules/er/erroutines.h
Called by: | AC_asc_acl_command_set() | modules/ac/access_control.c
| AC_asc_all_set() | modules/ac/access_control.c
| AC_asc_ban_set() | modules/ac/access_control.c
| AC_asc_set_nodeny() | modules/ac/access_control.c
| AC_ban_set() | modules/ac/access_control.c
| AC_commit() | modules/ac/access_control.c
| AC_commit_credit_l() | modules/ac/access_control.c
| AC_findcreate_acl_l() | modules/ac/access_control.c
| AC_prune() | modules/ac/access_control.c

## Global Function er_forkexec()

      Fork & exec a program specified with argv, the print msg
      on its stdin and exit. No redirection of stdout/stderr is done.

      MT-note: Solaris fork1() duplicates only the calling thread.
      So does Posix fork().

`void er_forkexec ( char** argv, char* msg, int usepath )`

`char** argv`
  argv array for the exec call
`char* msg`
  text payload to be printed on the stdin of forked process
`int usepath`
  flag indicating if the PATH environmental variable should be used by the exec call.

Calls: | close(), dup2(), execv(), execvp(), exit(), fork1(), perror(), pipe(), strlen(), wait(), write()
Called by: | er_logtopath() | modules/er/er.c

## Global Function er_format_line()

`char* er_format_line ( char* erbuf, er_fac_code_t facwhere, er_mask_t asp, int mode, int errcode, char* tmbuf )`

Calls: | __eprintf(), er_getfacsym(), er_getsevsym(), pthread_self(), snprintf(), sprintf()
Called by: | er_logit() | modules/er/er.c
References Variables: | er_fac_err | modules/er/er.c
| er_pid | modules/er/er.c
| er_progname | modules/er/er.c

## Global Function er_get_printmode()

`int er_get_printmode ( er_path_t* pathstruct )`

## Global Function er_getmsg_parts()

      Internal message construction. Message parts are gathered according to the
      specified format bitmask. The resulting message consisting of those parts
      as well as the printf-style constructed message text itself is printed into
      the given buffer.

`void er_getmsg_parts ( char* buf, unsigned buflen, char* fmttxt, va_list args )`

`char* buf`
  pointer to the predefined buffer
`unsigned buflen`
  buffer length
`char* fmttxt`
  printf-style format
`va_list args`
  printf-style arguments, if any

Calls: | vsnprintf()
Called by: | ER_dbg_va() | modules/er/er.c
| ER_perror() | modules/er/er.c
| er_asp_va() | modules/er/er.c

## Global Function er_logit()

      Browses the list of available paths, runs the filter check on every
      path and logs the given message to all suitable paths.

`void er_logit ( er_fac_code_t facwhere, er_mask_t asp, int errcode, char* msg )`

`er_fac_code_t facwhere`
  message's facility of call
`er_mask_t asp`
  message's aspect (if severity is INFO or DEBUG)
`int errcode`
  message's error code
`char* msg`
  text payload of the message

Calls: | er_format_line() | modules/er/er.c
| er_logtopath() | modules/er/er.c
| er_msgsel() | modules/er/er.c
| TH_acquire_read_lock(), TH_release_read_lock(), g_list_first(), gettimeofday(), localtime_r(), strftime()
Called by: | ER_dbg_va() | modules/er/er.c
| ER_perror() | modules/er/er.c
| er_asp_va() | modules/er/er.c
References Variables: | er_pathlist | modules/er/er.c
| er_paths_lock | modules/er/er.c

## Global Function er_msgsel()

      Message selection routine. Checks if the message coming from the
      current thread, tagged with the given error code, facility and
      aspect matches the given filter.

`int er_msgsel ( er_filter_t* filtptr, er_fac_code_t facwhere, er_mask_t asp, er_ret_t errcode )`

`int er_msgsel`
  returns 1 for a match, 0 otherwise.
`er_filter_t* filtptr`
  filter to be matched
`er_fac_code_t facwhere`
  message's facility of call
`er_mask_t asp`
  message's aspect (if severity is INFO or DEBUG)
`er_ret_t errcode`
  message's error code

Calls: | MA_isset(), pthread_self()
Called by: | er_logit() | modules/er/er.c

## Local Function er_asp_va()

      Internal function for message collection.

`static void er_asp_va ( er_fac_code_t facwhere, int sev, er_mask_t asp, char* txt, va_list args )`

`er_fac_code_t facwhere`
  code of facility from which the error is reported
`int sev`
  severity of the message
`er_mask_t asp`
  aspect of the message
`char* txt`
  printf-style format
`va_list args`
  printf-style arguments, if any

Calls: | er_getmsg_parts() | modules/er/er.c
| er_logit() | modules/er/er.c
Called by: | ER_inf_va() | modules/er/er.c

## Local Function er_logtopath()

      Main function logging a message to a path. The formatted message
      parts and the message text itself are given separately to avoid
      wasting time to remake them, because the message text may be the
      same while the path formats are different.

`static void er_logtopath ( er_path_t* pathptr, char* form, char* msg )`

`er_path_t* pathptr`
  pointer to the path structure where the message should go.
`char* form`
  format part of the message
`char* msg`
  payload part of the message

Calls: | er_forkexec() | modules/er/er.c
| close(), fprintf(), gettimeofday(), localtime_r(), open(), perror(), strcat(), strcpy(), strftime(), strlen(), write()
Called by: | er_logit() | modules/er/er.c