File error.c

 ** ** 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:								     **
 ** 									     **
 ** ************************************************************************ **
References Variables: Id error.c
  _stderr error.c

Included Files


Preprocessor definitions

#define ARGLIST_SIZE 10

#define ERR_LINELEN 80

#define ERR_BUFSIZE 4096

#define MEAS_VERB_NDX 1


Typedef ErrWeights

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 ErrFacilities

typedef struct _err_facility ErrFacilities
struct _err_facility  
   {  
      ErrWeights Weight;  
      char* facility;  
      char* def_facility;  
   }  

Typedef FacilityNames

typedef struct _facil_names FacilityNames
struct _facil_names  
   {  
      char* name;  
      int token;  
   }  

Typedef ErrMeasr

typedef struct {...} ErrMeasr
struct  
   {  
      ErrWeights error_weight;  
      char* message;  
      ErrCode ret_nov;  
      ErrCode ret_adv;  
      ErrCode ret_exp;  
   }  

Typedef ErrTransTab

typedef struct {...} ErrTransTab
struct  
   {  
      ErrType error_type;  
      ErrWeights error_weight;  
      char* messages;  
   }  

Global Variable error_line

char* error_line
Visible in:   ModuleCmd_Avail.c
    ModuleCmd_Bootstrap.c
    ModuleCmd_Clear.c
    ModuleCmd_Display.c
    ModuleCmd_Help.c
    ModuleCmd_Init.c
    ModuleCmd_List.c
    ModuleCmd_Load.c
    ModuleCmd_Purge.c
    ModuleCmd_Refresh.c
    ModuleCmd_Switch.c
    ModuleCmd_Update.c
    ModuleCmd_Use.c
    ModuleCmd_Whatis.c
    cmdAlias.c
    cmdConflict.c
    cmdInfo.c
    cmdIsLoaded.c
    cmdLog.c
    cmdMisc.c
    cmdModule.c
    cmdPath.c
    cmdSetenv.c
    cmdTrace.c
    cmdUlvl.c
    cmdUname.c
    cmdVerbose.c
    cmdVersion.c
    cmdWhatis.c
    cmdXResource.c
    error.c
    getopt.c
    init.c
    locate_module.c
    main.c
    modules_def.h
    utility.c
Used in: ErrorString() error.c
  add_param() error.c
  main() main.c

Local Variables

Id
static char Id[]
Used in:   error.c

UseId
static void* UseId[]

module_name
static char module_name[]

Used in: CheckFacility()  
  ErrorString()  
  FlushError()  
  GetFacilityPtr()  
  GetFacility_sub()  
  Module_Error()  
  Module_Tracing()  
  Module_Verbosity()  
  add_param()  

quiet_on_error
static int quiet_on_error

Used in: Disable_Error()  
  Enable_Error()  
  Module_Error()  
  Restore_Error()  
  save_error_state()  

unknown
static char unknown[]

Used in: Module_Error()  

buffer
static char buffer[80]

Used in: Module_Error()  
  PrintError()  
  add_param()  

strsize
static int strsize

Used in: ErrorString()  
  add_param()  

_stderr
static char _stderr[]

Used in:   error.c
  FlushError()  

_stdout
static char _stdout[]

Used in: FlushError()  

_null
static char _null[]

Used in: FlushError()  

_none
static char _none[]

Used in: FlushError()  

_unknown
static char _unknown[]

Used in: Print_Tracing()  

Facilities
static ErrFacilities Facilities[]

Used in: GetFacility_sub()  

facility_names
static FacilityNames facility_names[]

Used in: CheckFacility()  

level_names
static FacilityNames level_names[]

Used in: CheckFacility()  

Measurements
static ErrMeasr Measurements[]

Used in: GetFacilityPtr()  
  MeasLookup()  
  Module_Verbosity()  

TransTab
static ErrTransTab TransTab[]

Used in: ErrorLookup()  

Global Function CheckFacility()

 ** ** 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 )
Prototyped in: modules_def.h
Calls: Module_Error() error.c
  null_free() utility.c
  scan_facility() error.c
  stringer() utility.c
Called by: cmdModuleLog() cmdLog.c
References Variables: facility_names error.c
  level_names error.c
  module_name error.c

Global Function Disable_Error()

void Disable_Error ( void )
Calls: save_error_state() error.c
References Variables: quiet_on_error error.c

Global Function Enable_Error()

void Enable_Error ( void )
Calls: save_error_state() error.c
References Variables: quiet_on_error error.c

Global Function GetFacilityPtr()

 ** ** 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 )
Prototyped in: modules_def.h
Calls: GetFacility_sub() error.c
  Module_Error() error.c
  null_free() utility.c
  stringer() utility.c
  strlen(), strncmp(), toupper()
Called by: cmdModuleLog() cmdLog.c
References Variables: Measurements error.c
  module_name error.c

Global Function Module_Error()

 ** ** 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, ... )
Prototyped in: modules_def.h
Calls: ErrorLookup() error.c
  FlushError() error.c
  MeasLookup() error.c
  Module_Error() error.c
  null_free() utility.c
  __builtin_va_arg(), __builtin_va_start(), exit(), malloc(), realloc(), sprintf()
Called by: AddModule() cmdVersion.c
  AddName() cmdVersion.c
  AliasLookup() cmdVersion.c
  CallModuleProcedure() cmdModule.c
  ChangeTraceSel() cmdTrace.c
  CheckFacility() error.c
  CheckModuleVersion() cmdVersion.c
  CheckTracing() cmdTrace.c
  CheckTracingList() cmdTrace.c
  Check_Switches() main.c
  Copy_Hash_Tables() utility.c
  ErrorString() error.c
  Execute_TclFile() cmdModule.c
  ExpandVersions() cmdVersion.c
  FlushError() error.c
  GetFacilityPtr() error.c
  GetFacility_sub() error.c
  GetModuleName() locate_module.c
  InitializeModuleCommands() init.c
  Initialize_Tcl() init.c
  Locate_ModuleFile() locate_module.c
  ModuleCmd_Apropos() ModuleCmd_Whatis.c
  ModuleCmd_Avail() ModuleCmd_Avail.c
  ModuleCmd_Bootstrap() ModuleCmd_Bootstrap.c
  ModuleCmd_Display() ModuleCmd_Display.c
  ModuleCmd_Init() ModuleCmd_Init.c
  ModuleCmd_List() ModuleCmd_List.c
  ModuleCmd_Load() ModuleCmd_Load.c
  ModuleCmd_Purge() ModuleCmd_Purge.c
  ModuleCmd_Refresh() ModuleCmd_Refresh.c
  ModuleCmd_Switch() ModuleCmd_Switch.c
  ModuleCmd_UnUse() ModuleCmd_Use.c
  ModuleCmd_Update() ModuleCmd_Update.c
  ModuleCmd_Use() ModuleCmd_Use.c
  ModuleCmd_Whatis() ModuleCmd_Whatis.c
  Module_Error() error.c
  Module_Tcl_ExitCmd() init.c
  Module_Tracing() error.c
  Module_Verbosity() error.c
  Open_Aliasfile() utility.c
  Output_Modulefile_Aliases() utility.c
  Output_Modulefile_Changes() utility.c
  PerModuleHelp() ModuleCmd_Help.c
  Read_Modulefile() cmdModule.c
  Remove_Path() cmdPath.c
  Setup_Environment() init.c
  SortedDirList() locate_module.c
  SourceRC() locate_module.c
  SourceVers() locate_module.c
  SplitIntoList() locate_module.c
  TieStdout() init.c
  UnTieStdout() init.c
  VersionLookup() cmdVersion.c
  __IsLoaded() utility.c
  _add_file_list() ModuleCmd_Avail.c
  _getopt_internal() getopt.c
  add_param() error.c
  append_to_modulesbeginenv() ModuleCmd_Use.c
  checkConflict() cmdConflict.c
  check_dir() ModuleCmd_Avail.c
  check_magic() utility.c
  cmdConflict() cmdConflict.c
  cmdIsLoaded() cmdIsLoaded.c
  cmdModule() cmdModule.c
  cmdModuleAlias() cmdVersion.c
  cmdModuleInfo() cmdInfo.c
  cmdModuleLog() cmdLog.c
  cmdModuleTrace() cmdTrace.c
  cmdModuleUser() cmdUlvl.c
  cmdModuleUser_sub() cmdUlvl.c
  cmdModuleVerbose() cmdVerbose.c
  cmdModuleVersion() cmdVersion.c
  cmdModuleWhatis() cmdWhatis.c
  cmdPrereq() cmdConflict.c
  cmdRemovePath() cmdPath.c
  cmdSetAlias() cmdAlias.c
  cmdSetEnv() cmdSetenv.c
  cmdSetPath() cmdPath.c
  cmdSystem() cmdMisc.c
  cmdUname() cmdUname.c
  cmdUnsetEnv() cmdSetenv.c
  cmdXResource() cmdXResource.c
  dirlst_to_list() ModuleCmd_Avail.c
  getEntries() cmdXResource.c
  getLMFILES() utility.c
  getOld() cmdXResource.c
  get_dir() ModuleCmd_Avail.c
  initBuffers() cmdXResource.c
  main() main.c
  mkdirnm() ModuleCmd_Avail.c
  output_set_variable() utility.c
  output_unset_variable() utility.c
  print_aligned_files() ModuleCmd_Avail.c
  print_dir() ModuleCmd_Avail.c
  readFile() cmdXResource.c
  scan_versions() cmdVersion.c
  stringer() utility.c
  tmpfile_mod() utility.c
  whatis_dir() ModuleCmd_Whatis.c
  xdup() utility.c
References Variables: buffer error.c
  module_name error.c
  quiet_on_error error.c
  sw_userlvl main.c
  sw_verbose main.c
  unknown error.c

Global Function Module_Tracing()

 ** ** 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 )
Prototyped in: modules_def.h
Calls: FlushError() error.c
  Module_Error() error.c
Called by: cmdModule() cmdModule.c
References Variables: module_name error.c

Global Function Module_Verbosity()

void Module_Verbosity ( int argc, char** argv )
Prototyped in: modules_def.h
Calls: FlushError() error.c
  Module_Error() error.c
Called by: cmdModuleVerbose() cmdVerbose.c
References Variables: Measurements error.c
  g_current_module main.c
  linenum cmdModule.c
  module_name error.c
  sw_verbose main.c

Global Function Restore_Error()

void Restore_Error ( void )
Calls: save_error_state() error.c
References Variables: quiet_on_error error.c

Local Function ErrorLookup()

 ** ** 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 )
Prototyped in: error.c
Called by: Module_Error() error.c
References Variables: TransTab error.c

Local Function ErrorString()

 ** ** 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 )
Prototyped in: error.c
Calls: Module_Error() error.c
  add_param() error.c
  stringer() utility.c
  realloc()
Called by: PrintError() error.c
References Variables: error_line error.c
  module_name error.c
  strsize error.c

Local Function FlushError()

 ** ** 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 )
Prototyped in: error.c
Calls: GetFacility() error.c
  Module_Error() error.c
  PrintError() error.c
  Print_Tracing() error.c
  null_free() utility.c
  stringer() utility.c
  fclose(), fopen(), fprintf(), strcmp(), strstr(), strtok()
Called by: Module_Error() error.c
  Module_Tracing() error.c
  Module_Verbosity() error.c
References Variables: _none error.c
  _null error.c
  _stderr error.c
  _stdout error.c
  module_name error.c

Local Function GetFacility()

 ** ** 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 )
Prototyped in: error.c
Calls: GetFacility_sub() error.c
Called by: FlushError() error.c

Local Function GetFacility_sub()

static ErrFacilities* GetFacility_sub ( ErrWeights Weight )
Prototyped in: error.c
Calls: Module_Error() error.c
  sprintf()
Called by: GetFacility() error.c
  GetFacilityPtr() error.c
References Variables: Facilities error.c
  module_name error.c

Local Function MeasLookup()

 ** ** 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 )
Prototyped in: error.c
Called by: Module_Error() error.c
References Variables: Measurements error.c

Local Function PrintError()

 ** ** 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 )
Prototyped in: error.c
Calls: ErrorString() error.c
  sprintf()
Called by: FlushError() error.c
References Variables: buffer error.c
  g_current_module main.c
  linenum cmdModule.c

Local Function Print_Tracing()

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

Local Function add_param()

 ** ** 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 )
Prototyped in: error.c
Calls: Module_Error() error.c
  atoi(), realloc(), strcpy(), strlen()
Called by: ErrorString() error.c
References Variables: buffer error.c
  error_line error.c
  module_name error.c
  strsize error.c

Local Function save_error_state()

 ** ** 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 )
Called by: Disable_Error() error.c
  Enable_Error() error.c
  Restore_Error() error.c
References Variables: quiet_on_error error.c

Local Function scan_facility()

 ** ** 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 )
Prototyped in: error.c
Calls: strcmp()
Called by: CheckFacility() error.c