XRootD
XrdSysError.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d S y s E r r o r . c c */
4 /* */
5 /*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /*Produced by Andrew Hanushevsky for Stanford University under contract */
7 /* DE-AC02-76-SFO0515 with the Deprtment of Energy */
8 /* */
9 /* This file is part of the XRootD software suite. */
10 /* */
11 /* XRootD is free software: you can redistribute it and/or modify it under */
12 /* the terms of the GNU Lesser General Public License as published by the */
13 /* Free Software Foundation, either version 3 of the License, or (at your */
14 /* option) any later version. */
15 /* */
16 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19 /* License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24 /* */
25 /* The copyright holder's institutional names and contributor's names may not */
26 /* be used to endorse or promote products derived from this software without */
27 /* specific prior written permission of the institution or contributor. */
28 /******************************************************************************/
29 
30 #include <cctype>
31 #ifndef WIN32
32 #include <unistd.h>
33 #include <cstdlib>
34 #include <cstdio>
35 #include <cstring>
36 #include <strings.h>
37 #include <sys/types.h>
38 #include <sys/uio.h>
39 #else
40 #include <cstdlib>
41 #include <cstdio>
42 #include <cstring>
43 #include <sys/types.h>
44 #include "XrdSys/XrdWin32.hh"
45 #endif
46 
47 #include "XrdSys/XrdSysE2T.hh"
48 #include "XrdSys/XrdSysError.hh"
49 #include "XrdSys/XrdSysHeaders.hh"
50 #include "XrdSys/XrdSysLogger.hh"
51 #include "XrdSys/XrdSysPlatform.hh"
52 
53 /******************************************************************************/
54 /* d e f i n e s */
55 /******************************************************************************/
56 
57 #define Set_IOV_Item(x, y) {iov[iovpnt].iov_base = (caddr_t)x;\
58  iov[iovpnt++].iov_len = y;}
59 
60 #define Set_IOV_Buff(x) {iov[iovpnt].iov_base = (caddr_t)x;\
61  iov[iovpnt++].iov_len = strlen(x);}
62 
63 /******************************************************************************/
64 /* G l o b a l s */
65 /******************************************************************************/
66 
67 XrdSysError_Table *XrdSysError::etab = 0;
68 
69 /******************************************************************************/
70 /* b a s e F D */
71 /******************************************************************************/
72 
73 int XrdSysError::baseFD() {return Logger->originalFD();}
74 
75 /******************************************************************************/
76 /* e c 2 t e x t */
77 /******************************************************************************/
78 
79 const char *XrdSysError::ec2text(int ecode)
80 {
81  int xcode;
82  const char *etxt = 0;
83  XrdSysError_Table *etp = etab;
84 
85  xcode = (ecode < 0 ? -ecode : ecode);
86  while((etp != 0) && !(etxt = etp->Lookup(xcode))) etp = etp->next;
87  if (!etxt) etxt = XrdSysE2T(xcode);
88  return etxt;
89 }
90 
91 /******************************************************************************/
92 /* E m s g */
93 /******************************************************************************/
94 
95 int XrdSysError::Emsg(const char *esfx, int ecode, const char *txt1,
96  const char *txt2)
97 {
98  struct iovec iov[16];
99  int iovpnt = 0;
100  const char *etxt = ec2text(ecode);
101 
102  Set_IOV_Item(0,0); // 0
103  if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen); // 1
104  if (esfx ) Set_IOV_Buff(esfx); // 2
105  Set_IOV_Item(": Unable to ", 12); // 3
106  Set_IOV_Buff(txt1); // 4
107  if (txt2 && txt2[0]){Set_IOV_Item(" ", 1); // 5
108  Set_IOV_Buff(txt2); } // 6
109  Set_IOV_Item("; ", 2); // 7
110  Set_IOV_Buff(etxt); // 8
111  Set_IOV_Item("\n", 1); // 9
112  Logger->Put(iovpnt, iov);
113 
114  return ecode;
115 }
116 
117 void XrdSysError::Emsg(const char *esfx, const char *txt1,
118  const char *txt2,
119  const char *txt3)
120 {
121  struct iovec iov[16];
122  int iovpnt = 0;
123 
124  Set_IOV_Item(0,0); // 0
125  if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen); // 1
126  if (esfx ) Set_IOV_Buff(esfx); // 2
127  Set_IOV_Item(": ", 2); // 3
128  Set_IOV_Buff(txt1); // 4
129  if (txt2 && txt2[0]){Set_IOV_Item(" ", 1); // 5
130  Set_IOV_Buff(txt2);} // 6
131  if (txt3 && txt3[0]){Set_IOV_Item(" ", 1); // 7
132  Set_IOV_Buff(txt3);} // 8
133  Set_IOV_Item("\n", 1); // 9
134  Logger->Put(iovpnt, iov);
135 }
136 
137 /******************************************************************************/
138 /* S a y */
139 /******************************************************************************/
140 
141 void XrdSysError::Say(const char *txt1, const char *txt2, const char *txt3,
142  const char *txt4, const char *txt5, const char *txt6)
143 {
144  struct iovec iov[9];
145  int iovpnt = 0;
146  if (txt1) Set_IOV_Buff(txt1) // 0
147  else Set_IOV_Item(0,0);
148  if (txt2 && txt2[0]) Set_IOV_Buff(txt2); // 1
149  if (txt3 && txt3[0]) Set_IOV_Buff(txt3); // 2
150  if (txt4 && txt4[0]) Set_IOV_Buff(txt4); // 3
151  if (txt5 && txt5[0]) Set_IOV_Buff(txt5); // 4
152  if (txt6 && txt6[0]) Set_IOV_Buff(txt6); // 5
153  Set_IOV_Item("\n", 1); // 6
154  Logger->Put(iovpnt, iov);
155 }
156 
157 /******************************************************************************/
158 /* T b e g */
159 /******************************************************************************/
160 
161 void XrdSysError::TBeg(const char *txt1, const char *txt2, const char *txt3)
162 {
163  std::cerr <<Logger->traceBeg();
164  if (txt1) std::cerr <<txt1 <<' ';
165  if (txt2) std::cerr <<epfx <<txt2 <<": ";
166  if (txt3) std::cerr <<txt3;
167 }
168 
169 /******************************************************************************/
170 /* T E n d */
171 /******************************************************************************/
172 
173 void XrdSysError::TEnd() {std::cerr <<std::endl; Logger->traceEnd();}
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
#define Set_IOV_Item(x, y)
Definition: XrdSysError.cc:57
#define Set_IOV_Buff(x)
Definition: XrdSysError.cc:60
char * Lookup(int mnum)
Definition: XrdSysError.hh:50
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0)
Definition: XrdSysError.cc:161
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
Definition: XrdSysError.cc:141
int baseFD()
Definition: XrdSysError.cc:73
static const char * ec2text(int ecode)
Definition: XrdSysError.cc:79
void Put(int iovcnt, struct iovec *iov)
char * traceBeg()
XrdSysLogger Logger
Definition: XrdGlobals.cc:47