$Revision: 1.27 $
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
Included Files
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
char* er_pathtypes[]
er_list_t RX_mod_err[]
er_list_t ER_mod_err[]
er_list_t IP_mod_err[]
er_list_t UP_mod_err[]
er_list_t UT_mod_err[]
er_list_t WH_mod_err[]
er_list_t RP_mod_err[]
er_list_t QI_mod_err[]
er_list_t QC_mod_err[]
er_list_t PW_mod_err[]
er_list_t SK_mod_err[]
er_list_t TH_mod_err[]
er_list_t SQ_mod_err[]
er_list_t PM_mod_err[]
er_list_t MM_mod_err[]
er_list_t SV_mod_err[]
er_list_t AC_mod_err[]
er_list_t UD_mod_err[]
er_list_t PA_mod_err[]
er_list_t PC_mod_err[]
er_fac_t er_fac_err[]
er_aspstr_t er_asparr[]
er_form_el er_formarr[]
er_level_t er_level_a[]
GList* er_pathlist
er_mask_t er_asparray[FAC_LAST]
rw_lock_t er_paths_lock
GHashTable* er_macro_hash
char er_progname[32]
char er_pid[16]
pthread_mutex_t er_pathlist_mutex
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
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
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.
int ER_is_errorlogged ( er_fac_code_t facwhere, int errcode )
int ER_is_traced ( er_fac_code_t facwhere, er_mask_t asp )
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
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.
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
|
char* er_format_line ( char* erbuf, er_fac_code_t facwhere, er_mask_t asp, int mode, int errcode, char* tmbuf )
int er_get_printmode ( er_path_t* pathstruct )
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
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
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
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
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
|