File error.c

 ** ** Module Header ******************************************************* **
 ** 									     **
 **   Modules Revision 3.0						     **
 **   Providing a flexible user environment				     **
 ** 									     **
 **   File:		error.c						     **
 **   First Edition:	91/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: Iderror.c
  _stderrerror.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_Clear.c
   ModuleCmd_Display.c
   ModuleCmd_Help.c
   ModuleCmd_Init.c
   ModuleCmd_List.c
   ModuleCmd_Load.c
   ModuleCmd_Purge.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
   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:	95/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
  scan_facility()error.c
  strdup()
Called by: cmdModuleLog()cmdLog.c
References Variables: facility_nameserror.c
  level_nameserror.c
  module_nameerror.c

Global Function Disable_Error()

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

Global Function Enable_Error()

void Enable_Error ( void )
Calls: save_error_state()error.c
References Variables: quiet_on_errorerror.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:	95/12/21					     **
 ** 									     **
 **   Parameters:	char	*facility	Name of the facility	     **
 ** 									     **
 **   Result:		char**	NULL		Invalif 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
  malloc(), strlen(), strncmp(), toupper()
Called by: cmdModuleLog()cmdLog.c
References Variables: Measurementserror.c
  module_nameerror.c

Global Function Module_Error()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		Module_Error					     **
 ** 									     **
 **   Description:	Error handling for the modules package		     **
 ** 									     **
 **   First Edition:	95/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
  __builtin_next_arg(), 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_Display()ModuleCmd_Display.c
  ModuleCmd_Init()ModuleCmd_Init.c
  ModuleCmd_Load()ModuleCmd_Load.c
  ModuleCmd_Purge()ModuleCmd_Purge.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
  Output_Modulefile_Aliases()utility.c
  Output_Modulefile_Changes()utility.c
  PerModuleHelp()ModuleCmd_Help.c
  Read_Modulefile()cmdModule.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_cache()ModuleCmd_Avail.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
  create_cache_list()ModuleCmd_Avail.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
  store_files()ModuleCmd_Avail.c
  whatis_dir()ModuleCmd_Whatis.c
References Variables: buffererror.c
  module_nameerror.c
  quiet_on_errorerror.c
  sw_userlvlmain.c
  sw_verbosemain.c
  unknownerror.c

Global Function Module_Tracing()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		Module_Tracing					     **
 **			Print_Tracing					     **
 **			Module_Verbosity				     **
 ** 									     **
 **   Description:	Display a tracing or verbose message		     **
 ** 									     **
 **   First Edition:	95/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_nameerror.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: Measurementserror.c
  g_current_modulemain.c
  linenumcmdModule.c
  module_nameerror.c
  sw_verbosemain.c

Global Function Restore_Error()

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

Local Function ErrorLookup()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		ErrorLookup					     **
 ** 									     **
 **   Description:	Look up the passed error type in the translation tab.**
 ** 									     **
 **   First Edition:	95/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: TransTaberror.c

Local Function ErrorString()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		ErrorString					     **
 ** 									     **
 **   Description:	Print the error message				     **
 ** 									     **
 **   First Edition:	95/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
  malloc(), realloc()
Called by: PrintError()error.c
References Variables: error_lineerror.c
  module_nameerror.c
  strsizeerror.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:	95/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
  fclose(), fopen(), fprintf(), malloc(), strcmp(), strcpy(), strlen(), strstr(), strtok()
Called by: Module_Error()error.c
  Module_Tracing()error.c
  Module_Verbosity()error.c
References Variables: _noneerror.c
  _nullerror.c
  _stderrerror.c
  _stdouterror.c
  module_nameerror.c

Local Function GetFacility()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		GetFacility					     **
 ** 									     **
 **   Description:	Get the log facility according to the passed error   **
 **			weight						     **
 ** 									     **
 **   First Edition:	95/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: Facilitieserror.c
  module_nameerror.c

Local Function MeasLookup()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		MeasLookup					     **
 ** 									     **
 **   Description:	Look up the passed error weight in the measurement   **
 **			table						     **
 ** 									     **
 **   First Edition:	95/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: Measurementserror.c

Local Function PrintError()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		PrintError					     **
 ** 									     **
 **   Description:	Print the error message				     **
 ** 									     **
 **   First Edition:	95/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: buffererror.c
  g_current_modulemain.c
  linenumcmdModule.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: _unknownerror.c

Local Function add_param()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		add_param					     **
 ** 									     **
 **   Description:	Put an argument to the error string		     **
 ** 									     **
 **   First Edition:	95/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: buffererror.c
  error_lineerror.c
  module_nameerror.c
  strsizeerror.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_errorerror.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:	95/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