** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: error.c **
** First Edition: 1991/10/23 **
** **
** Authors: Jens Hamisch, jens@Strawberry.COM **
** **
** Description: The modules error logger **
** **
** Exports: Module_Error **
** GetFacilityPtr **
** CheckFacility **
** Enable_Error **
** Disable_Error **
** Restore_Error **
** **
** Notes: **
** **
** ************************************************************************ **
Included Files
- #include "modules_def.h"
- #include <stdio.h>
- #include <stdarg.h>
- #include <tcl.h>
- #include "config.h"
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <ctype.h>
- #include <sys/stat.h>
- #include <sys/termios.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <dirent.h>
- #include <errno.h>
Preprocessor definitions
#define ARGLIST_SIZE 10
#define ERR_LINELEN 80
#define ERR_BUFSIZE 4096
#define MEAS_VERB_NDX 1
typedef enum _err_weights ErrWeights
| enum _err_weights
|
|
| {
|
|
|
WGHT_NONE;
|
|
|
WGHT_VERBOSE;
|
|
|
WGHT_INFO;
|
|
|
WGHT_DEBUG;
|
|
|
WGHT_TRACE;
|
|
|
WGHT_WARN;
|
|
|
WGHT_PROB;
|
|
|
WGHT_ERROR;
|
|
|
WGHT_FATAL;
|
|
|
WGHT_PANIC;
|
|
| }
|
|
typedef struct _err_facility ErrFacilities
| struct _err_facility
|
|
| {
|
|
|
ErrWeights Weight;
|
|
|
char* facility;
|
|
|
char* def_facility;
|
|
| }
|
|
typedef struct _facil_names FacilityNames
| struct _facil_names
|
|
| {
|
|
|
char* name;
|
|
|
int token;
|
|
| }
|
|
typedef struct {...} ErrMeasr
| struct
|
|
| {
|
|
|
ErrWeights error_weight;
|
|
|
char* message;
|
|
|
ErrCode ret_nov;
|
|
|
ErrCode ret_adv;
|
|
|
ErrCode ret_exp;
|
|
| }
|
|
typedef struct {...} ErrTransTab
| struct
|
|
| {
|
|
|
ErrType error_type;
|
|
|
ErrWeights error_weight;
|
|
|
char* messages;
|
|
| }
|
|
char* error_line
Local Variables
Id
static char Id[]
UseId
static void* UseId[]
module_name
static char module_name[]
quiet_on_error
static int quiet_on_error
unknown
static char unknown[]
buffer
static char buffer[80]
strsize
static int strsize
_stderr
static char _stderr[]
_stdout
static char _stdout[]
_null
static char _null[]
_none
static char _none[]
_unknown
static char _unknown[]
Facilities
static ErrFacilities Facilities[]
facility_names
static FacilityNames facility_names[]
level_names
static FacilityNames level_names[]
Measurements
static ErrMeasr Measurements[]
TransTab
static ErrTransTab TransTab[]
** ** Function-Header ***************************************************** **
** **
** Function: CheckFacility **
** **
** Description: Check the passwd string to be a valid combination **
** of <syslog_facility>.<syslog_level> **
** **
** First Edition: 1995/12/21 **
** **
** Parameters: char *string Input facility string **
** int *facility Buffer for the real facility **
** int *level Buffer for the real level **
** **
** Result: int 1 Success **
** 0 Failure. String not valid **
** **
** ************************************************************************ **
int CheckFacility ( char* string, int* facility, int* level )
void Disable_Error ( void )
void Enable_Error ( void )
** ** Function-Header ***************************************************** **
** **
** Function: GetFacilityPtr **
** **
** Description: Scan the passed facility names table for the given **
** string and pass back the assigned token **
** **
** First Edition: 1995/12/21 **
** **
** Parameters: char *facility Name of the facility **
** **
** Result: char** NULL Invalid facility name **
** Otherwise Pointer to the facilty string**
** reference **
** **
** ************************************************************************ **
char** GetFacilityPtr ( char* facility )
** ** Function-Header ***************************************************** **
** **
** Function: Module_Error **
** **
** Description: Error handling for the modules package **
** **
** First Edition: 1995/08/06 **
** **
** Parameters: ErrType error_type Type of the error **
** char *module Affected module **
** int lineo Line number **
** ... Argument list **
** **
** Result: ErrCode OK No error **
** PROBLEM Problem. Program may **
** continue running **
** ERROR Caller should try to **
** exit gracefully **
** **
** Attached Globals: **
** **
** ************************************************************************ **
int Module_Error ( ErrType error_type, char* module, int lineno, ... )
** ** Function-Header ***************************************************** **
** **
** Function: Module_Tracing **
** Print_Tracing **
** Module_Verbosity **
** **
** Description: Display a tracing or verbose message **
** **
** First Edition: 1995/12/27 **
** **
** Parameters: int result Result code of th module command **
** int argc Number od arguments to the module **
** command **
** char **argv Argument array **
** char *buffer Print buffer **
** **
** Result: - **
** **
** Attached Globals: g_current_module The module which is handled **
** by the current command **
** **
** ************************************************************************ **
void Module_Tracing ( int result, int argc, char** argv )
void Module_Verbosity ( int argc, char** argv )
void Restore_Error ( void )
** ** Function-Header ***************************************************** **
** **
** Function: ErrorLookup **
** **
** Description: Look up the passed error type in the translation tab.**
** **
** First Edition: 1995/08/06 **
** **
** Parameters: ErrType error_type Type of the error **
** **
** Result: ErrTransTab* NULL Not found **
** else Pointer to the acc. entry **
** **
** Attached Globals: **
** **
** ************************************************************************ **
static ErrTransTab* ErrorLookup ( ErrType error_type )
** ** Function-Header ***************************************************** **
** **
** Function: ErrorString **
** **
** Description: Print the error message **
** **
** First Edition: 1995/08/06 **
** **
** Parameters: char *ErrMsgs Error message **
** int argc Number of arguments **
** char **argv Argument array **
** **
** Result: char* NULL Parse or alloc error **
** else Pointer to the error string **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static char* ErrorString ( char* ErrMsgs, int argc, char** argv )
** ** Function-Header ***************************************************** **
** **
** Function: FlushError **
** **
** Description: Print the error message. Decide which facility to **
** use and schedule the according logger routine **
** **
** First Edition: 1995/12/21 **
** **
** Parameters: ErrType Type Error type as passed **
** char *module Module name **
** int lineno Line number **
** ErrWeights Weight Error Weight **
** char *WeightMsg Printable Weight **
** char *ErrMsgs Error message **
** int argc Number of arguments **
** char **argv Argument array **
** **
** Result: int 1 Everything OK **
** 0 Error occured while printing **
** **
** ************************************************************************ **
static int FlushError ( ErrType Type, char* module, int lineno, ErrWeights Weight, char* WeightMsg, char* ErrMsgs, int argc, char** argv )
** ** Function-Header ***************************************************** **
** **
** Function: GetFacility **
** **
** Description: Get the log facility according to the passed error **
** weight **
** **
** First Edition: 1995/12/21 **
** **
** Parameters: ErrWeights Weight Error Weight **
** **
** Result: char* NULL No facility found **
** Otherwise Pointer to the colon separa- **
** ted facility string **
** **
** ************************************************************************ **
static char* GetFacility ( ErrWeights Weight )
static ErrFacilities* GetFacility_sub ( ErrWeights Weight )
** ** Function-Header ***************************************************** **
** **
** Function: MeasLookup **
** **
** Description: Look up the passed error weight in the measurement **
** table **
** **
** First Edition: 1995/08/06 **
** **
** Parameters: ErrWeights weigth Weight of the error **
** **
** Result: ErrMeasr* NULL Not found **
** else Pointer to the acc. entry **
** **
** Attached Globals: **
** **
** ************************************************************************ **
static ErrMeasr* MeasLookup ( ErrWeights weigth )
** ** Function-Header ***************************************************** **
** **
** Function: PrintError **
** **
** Description: Print the error message **
** **
** First Edition: 1995/08/06 **
** **
** Parameters: char *errbuffer Buffer to hold the **
** error messge **
** ErrType Type Error type as passed **
** char *module Module name **
** int lineno Line number **
** ErrWeights Weight Error Weight **
** char *WeightMsg Printable Weight **
** char *ErrMsgs Error message **
** int argc Number of arguments **
** char **argv Argument array **
** **
** Result: int 1 Everything OK **
** 0 Error occured while printing **
** **
** Notes: According to the error type, the passed module and line num- **
** ber will be handled as a module-file related one or depending**
** on the packages source code: **
** **
** src -> ERR_IN_MODULEFILE -> modulefile -> ERR_INTERNAL -> src**
** **
** ************************************************************************ **
static int PrintError ( char* errbuffer, ErrType Type, char* module, int lineno, ErrWeights Weight, char* WeightMsg, char* ErrMsgs, int argc, char** argv )
static void Print_Tracing ( char* buffer, int result, int argc, char** argv )
| Prototyped in:
| error.c
|
| Calls:
| getegid(), geteuid(), getgid(), getgrgid(), getpwuid(), getuid(), sprintf(), strcat(), strcpy(), strlen()
|
| Called by:
| FlushError()
| error.c
|
| References Variables:
| _unknown
| error.c
|
** ** Function-Header ***************************************************** **
** **
** Function: add_param **
** **
** Description: Put an argument to the error string **
** **
** First Edition: 1995/08/06 **
** **
** Parameters: char **Control Parameter control **
** char **Target Target to print to **
** int *Length Current length of the**
** output string **
** int argc Number of arguments **
** char **argv Argument array **
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static void add_param ( char** Control, char** Target, int* Length, int argc, char** argv )
** ** Function-Header ***************************************************** **
** **
** Function: Enable_Error, Disable_Error, Restore_Error **
** **
** Description: Enables, disables, or restores error logging **
** Sometimes an error isn't really an error **
** **
** First Edition: 1999/11/11 **
** **
** Parameters: none **
** **
** Result: none **
** **
** ************************************************************************ **
static void save_error_state ( int reset )
** ** Function-Header ***************************************************** **
** **
** Function: scan_facility **
** **
** Description: Scan the passed facility names table for the given **
** string and pass back the assigned token **
** **
** First Edition: 1995/12/21 **
** **
** Parameters: char *s String to be checked **
** FacilityNames *table Table of valid names and **
** tokens **
** int size Size of the table **
** **
** Result: int -1 name not found in the table **
** Otherwise Assigned token **
** **
** ************************************************************************ **
static int scan_facility ( char* s, FacilityNames* table, int size )