00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 const char *XrdSysErrorCVSID = "$Id: XrdSysError.cc 28902 2009-06-11 12:36:21Z ganis $";
00014
00015 #include <ctype.h>
00016 #ifndef WIN32
00017 #include <unistd.h>
00018 #include <errno.h>
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021 #include <string.h>
00022 #include <strings.h>
00023 #include <sys/types.h>
00024 #include <sys/uio.h>
00025 #else
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <sys/types.h>
00030 #include "XrdSys/XrdWin32.hh"
00031 #endif
00032
00033 #include "XrdSys/XrdSysError.hh"
00034 #include "XrdSys/XrdSysHeaders.hh"
00035 #include "XrdSys/XrdSysLogger.hh"
00036 #include "XrdSys/XrdSysPlatform.hh"
00037
00038
00039
00040
00041
00042 #define Set_IOV_Item(x, y) {iov[iovpnt].iov_base = (caddr_t)x;\
00043 iov[iovpnt++].iov_len = y;}
00044
00045 #define Set_IOV_Buff(x) {iov[iovpnt].iov_base = (caddr_t)x;\
00046 iov[iovpnt++].iov_len = strlen(x);}
00047
00048
00049
00050
00051
00052 XrdSysError_Table *XrdSysError::etab = 0;
00053
00054
00055
00056
00057
00058 int XrdSysError::baseFD() {return Logger->originalFD();}
00059
00060
00061
00062
00063
00064 char *XrdSysError::ec2text(int ecode)
00065 {
00066 int xcode;
00067 char *etxt = 0;
00068 XrdSysError_Table *etp = etab;
00069
00070 xcode = (ecode < 0 ? -ecode : ecode);
00071 while((etp != 0) && !(etxt = etp->Lookup(xcode))) etp = etp->next;
00072 if (!etxt) etxt = strerror(xcode);
00073 return etxt;
00074 }
00075
00076
00077
00078
00079
00080 int XrdSysError::Emsg(const char *esfx, int ecode, const char *txt1,
00081 const char *txt2)
00082 {
00083 struct iovec iov[16];
00084 int iovpnt = 0;
00085 char ebuff[16], etbuff[80], *etxt = 0;
00086
00087 if (!(etxt = ec2text(ecode)))
00088 {snprintf(ebuff, sizeof(ebuff), "reason unknown (%d)", ecode);
00089 etxt = ebuff;
00090 } else if (isupper(static_cast<int>(*etxt)))
00091 {strlcpy(etbuff, etxt, sizeof(etbuff));
00092 *etbuff = static_cast<char>(tolower(static_cast<int>(*etxt)));
00093 etxt = etbuff;
00094 }
00095
00096 Set_IOV_Item(0,0);
00097 if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen);
00098 if (esfx ) Set_IOV_Buff(esfx);
00099 Set_IOV_Item(": Unable to ", 12);
00100 Set_IOV_Buff(txt1);
00101 if (txt2 && txt2[0]){Set_IOV_Item(" ", 1);
00102 Set_IOV_Buff(txt2); }
00103 Set_IOV_Item("; ", 2);
00104 Set_IOV_Buff(etxt);
00105 Set_IOV_Item("\n", 1);
00106 Logger->Put(iovpnt, iov);
00107
00108 return ecode;
00109 }
00110
00111 void XrdSysError::Emsg(const char *esfx, const char *txt1,
00112 const char *txt2,
00113 const char *txt3)
00114 {
00115 struct iovec iov[16];
00116 int iovpnt = 0;
00117
00118 Set_IOV_Item(0,0);
00119 if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen);
00120 if (esfx ) Set_IOV_Buff(esfx);
00121 Set_IOV_Item(": ", 2);
00122 Set_IOV_Buff(txt1);
00123 if (txt2 && txt2[0]){Set_IOV_Item(" ", 1);
00124 Set_IOV_Buff(txt2);}
00125 if (txt3 && txt3[0]){Set_IOV_Item(" ", 1);
00126 Set_IOV_Buff(txt3);}
00127 Set_IOV_Item("\n", 1);
00128 Logger->Put(iovpnt, iov);
00129 }
00130
00131
00132
00133
00134
00135 void XrdSysError::Say(const char *txt1, const char *txt2, const char *txt3,
00136 const char *txt4, const char *txt5, const char *txt6)
00137 {
00138 struct iovec iov[9];
00139 int iovpnt = 0;
00140 if (txt1) Set_IOV_Buff(txt1)
00141 else Set_IOV_Item(0,0);
00142 if (txt2 && txt2[0]) Set_IOV_Buff(txt2);
00143 if (txt3 && txt3[0]) Set_IOV_Buff(txt3);
00144 if (txt4 && txt4[0]) Set_IOV_Buff(txt4);
00145 if (txt5 && txt5[0]) Set_IOV_Buff(txt5);
00146 if (txt6 && txt6[0]) Set_IOV_Buff(txt6);
00147 Set_IOV_Item("\n", 1);
00148 Logger->Put(iovpnt, iov);
00149 }
00150
00151
00152
00153
00154
00155 void XrdSysError::TBeg(const char *txt1, const char *txt2, const char *txt3)
00156 {
00157 cerr <<Logger->traceBeg();
00158 if (txt1) cerr <<txt1 <<' ';
00159 if (txt2) cerr <<epfx <<txt2 <<": ";
00160 if (txt3) cerr <<txt3;
00161 }
00162
00163
00164
00165
00166
00167 void XrdSysError::TEnd() {cerr <<endl; Logger->traceEnd();}