/*
* Error handling routines.
*
* The functions in this file are independent of any application
* variables, and may be used in any C program. Either of the names
* CLIENT of SERVER may be defined when compiling this function.
* If neither are defined, we assume SERVER.
*/
#include "gopherd.h"
void my_perror();
#ifndef NULL
#define NULL ((void *) 0)
#endif
extern char *pname;
#ifndef NOSYSLOG
/*
* Under useful OS's, these server routines use the syslog(3) facility.
* They don't append a newline for example.
*/
#ifndef VMS_SERVER
/*
* Get around the existance of syslog.h in the wais source code...
* Arghhh!!!
*/
#ifdef WAISSEARCH
#include "/usr/include/syslog.h"
#else
#include <syslog.h>
#endif
#else
/*
* VMS implementations require their own syslog.h file
*/
#ifdef MULTINET
#include "syslog.h"
#endif
#endif
#else /* no syslog() */
/*
* There really ought to be a better way to handle server logging
* under System V
*/
#ifndef VMS_SERVER
#define syslog(a,b) fprintf(stderr, "%s\n", (b))
#define openlog(a,b,c) fprintf(stderr, "%s\n", (a))
#else
#define syslog(a,b) VMS$fprintf(stderr, "%s\n", (b))
#define openlog(a,b,c) VMS$fprintf(stderr, "%s\n", (a))
#endif
char emesgstr[255] = {0}; /* used by all server routines */
/*
* Identify ourselves, for syslog() messages.
*
* LOG_PID is an option that says prepend each message with our pid.
* LOG_CONS is an option that says write to the console if unable to
* send the message to syslogd.
* LOG_DAEMON is our facility.
*/
void
err_init()
{
#ifndef VMS_SERVER
/* have to be able to reopen, since daemon_start keeps closing us */
closelog(); /* in case we've been closed by daemon_start */
#endif
#ifdef LOG_DAEMON
openlog("gopherd", (LOG_PID|LOG_CONS), LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_INFO));
#else
/* old old syslog - probably Ultrix */
openlog("gopherd", LOG_PID);
#endif
}
/*
* Fatal error. Print a message and terminate.
* Don't print the system's errno value.
*
* err_quit(str, arg1, arg2, ...)
*/
/*
* Fatal error related to a system call. Print the message and terminate.
* Don't dump core, but do print the systems errno value and its associated
* message.
*/
/*
* Print the UNIX errno value.
* We just append it the the end of the emesgstr[] array.
*/
void my_perror()
{
int len;
char *sys_err_str();
len = strlen(emesgstr);
sprintf(emesgstr + len, " %s", sys_err_str());
}
extern int errno; /* UNIX error number */
extern int sys_nerr; /* # of error message strings in sys table */
#ifndef VMS_SERVER
extern char *sys_errlist[]; /* the system error message table */
#endif
#ifdef SYS5
int t_errno;
int t_nerr;
char *t_errlist[1];
#endif
/*
* Return a string containing some additional operating system
* dependent information.
* Note that different versions of UNIX assign different meanings
* to the same value of "errno". This means that if an error
* condition is being sent ot another UNIX system, we must interpret
* the errno value on the system that generated the error, and not
* just send the decimal value of errno to the other system.
*/