00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <unistd.h>
00024 #include <stdlib.h>
00025 #include <syslog.h>
00026 #include <errno.h>
00027 #include <string.h>
00028 #include "snprintf.h"
00029
00030 #if defined(hpux9)
00031 extern "C" {
00032 extern void openlog(const char *, int, int);
00033 extern void syslog(int, const char *, ...);
00034 }
00035 #endif
00036
00037 #ifdef __sun
00038 # ifndef _REENTRANT
00039 # if __SUNPRO_CC > 0x420
00040 # define GLOBAL_ERRNO
00041 # endif
00042 # endif
00043 #endif
00044
00045 #include "rpderr.h"
00046 #include "rpdp.h"
00047
00048
00049 extern int gDebug;
00050
00051 namespace ROOT {
00052
00053 extern bool gSysLog;
00054
00055
00056 int GetErrno()
00057 {
00058 #ifdef GLOBAL_ERRNO
00059 return ::errno;
00060 #else
00061 return errno;
00062 #endif
00063 }
00064
00065
00066 void ResetErrno()
00067 {
00068 #ifdef GLOBAL_ERRNO
00069 ::errno = 0;
00070 #else
00071 errno = 0;
00072 #endif
00073 }
00074
00075
00076 void ErrorInfo(const char *va_(fmt), ...)
00077 {
00078
00079
00080 char buf[kMAXSECBUF];
00081 va_list ap;
00082
00083 va_start(ap,va_(fmt));
00084 vsnprintf(buf, sizeof(buf), fmt, ap);
00085 va_end(ap);
00086
00087 if (gSysLog) {
00088 syslog(LOG_INFO, "%s\n", buf);
00089 } else {
00090 fprintf(stderr, "%s\n", buf);
00091 }
00092 }
00093
00094
00095 void ErrorInit(const char *ident)
00096 {
00097
00098
00099 openlog(ident, (LOG_PID | LOG_CONS), LOG_DAEMON);
00100 }
00101
00102
00103 void Perror(char *buf, int size)
00104 {
00105
00106
00107 int len = strlen(buf);
00108 #if (defined(__sun) && defined (__SVR4)) || defined (__linux) || \
00109 defined(_AIX) || defined(__MACH__)
00110 snprintf(buf+len, size, " (%s)", strerror(GetErrno()));
00111 #else
00112 if (GetErrno() >= 0 && GetErrno() < sys_nerr)
00113 snprintf(buf+len, size, " (%s)", sys_errlist[GetErrno()]);
00114 #endif
00115 }
00116
00117
00118 void Error(ErrorHandler_t func, int code, const char *va_(fmt), ...)
00119 {
00120
00121
00122 char buf[kMAXSECBUF];
00123 va_list ap;
00124
00125 va_start(ap,va_(fmt));
00126 vsnprintf(buf, sizeof(buf), fmt, ap);
00127 va_end(ap);
00128
00129 if (gSysLog) {
00130 syslog(LOG_ERR, "%s\n", buf);
00131 } else {
00132 fprintf(stderr, "%s\n", buf);
00133 }
00134
00135
00136
00137 if (func) (*func)(code,(const char *)buf, sizeof(buf));
00138 }
00139
00140 }