-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdSsiLogging.cc
162 lines (144 loc) · 6.34 KB
/
XrdSsiLogging.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/******************************************************************************/
/* */
/* X r d S s i L o g g i n g . c c */
/* */
/* (c) 2016 by the Board of Trustees of the Leland Stanford, Jr., University */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <fcntl.h>
#include <iostream>
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "XrdVersion.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdSsi/XrdSsiLogger.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysLogPI.hh"
#include "XrdSys/XrdSysPlugin.hh"
/******************************************************************************/
/* G l o b a l O b j e c t s */
/******************************************************************************/
namespace XrdSsi
{
extern XrdSsiLogger::MCB_t *msgCB;
}
using namespace std;
using namespace XrdSsi;
/******************************************************************************/
/* L o g P l u g i n H o o k s */
/******************************************************************************/
/******************************************************************************/
/* C o n f i g L o g */
/******************************************************************************/
namespace
{
void ConfigLog(const char *cFN)
{
XrdVERSIONINFODEF(myVersion, ssi, XrdVNUMBER, XrdVERSION);
const char *lName;
char eBuff[2048], *var, *val, **lDest, *logPath = 0, *svcPath = 0;
XrdSysPlugin *myLib;
XrdSsiLogger::MCB_t **theCB;
XrdOucEnv myEnv;
XrdOucStream cStrm(0, getenv("XRDINSTANCE"), &myEnv, "=====> ");
int cfgFD, retc, NoGo = 0;
// Try to open the configuration file.
//
if ((cfgFD = open(cFN, O_RDONLY, 0)) < 0)
{cerr <<"Config " <<XrdSysE2T(errno) <<" opening " <<cFN <<endl;
return;
}
cStrm.Attach(cfgFD);
static const char *cvec[] = { "*** ssi logging plugin config:", 0 };
cStrm.Capture(cvec);
// Now start reading records until eof.
//
while((var = cStrm.GetMyFirstWord()))
{ if (!strcmp(var, "ssi.loglib")) {lDest = &logPath; lName = "log";}
else if (!strcmp(var, "ssi.svclib")) {lDest = &svcPath; lName = "svc";}
else continue;
if (!(val = cStrm.GetWord()) || !val[0])
{cerr <<"Config "<<lName<<"lib path not specified."<<endl; NoGo=1;}
else {if (*lDest) free(*lDest);
*lDest = strdup(val);
}
}
// Now check if any errors occured during file i/o
//
if ((retc = cStrm.LastError()))
{cerr <<"Config " <<XrdSysE2T(-retc) <<" reading " <<cFN <<endl;
NoGo = 1;
}
cStrm.Close();
// If we don't have a loglib then revert to using svclib
//
if (!logPath) {logPath = svcPath; svcPath = 0; lName = "svclib";}
else lName = "loglib";
// Check if we have a logPath (we must)
//
if (!NoGo && !logPath)
{cerr <<"Config neither ssi.loglib nor ssi.svclib directive specified in "
<<cFN <<endl;
return;
}
// Create a plugin object
//
if (!(myLib = new XrdSysPlugin(eBuff, sizeof(eBuff), logPath, lName,
&myVersion)))
{cerr <<"Config " <<eBuff <<endl;
return;
}
// Now get the entry point of the message callback function if the dynamic
// initialization of the plugin library hasn't already set it.
//
if (!msgCB)
{theCB = (XrdSsiLogger::MCB_t **)(myLib->getPlugin("XrdSsiLoggerMCB"));
if (!msgCB && !theCB) cerr <<"Config " <<eBuff <<endl;
else {if (!msgCB) msgCB = *theCB;
myLib->Persist();
}
}
else myLib->Persist();
// All done
//
delete myLib;
}
}
/******************************************************************************/
/* X r d S y s L o g P I n i t */
/******************************************************************************/
extern "C"
{
XrdSysLogPI_t XrdSysLogPInit(const char *cfgfn, char **argv, int argc)
{if (cfgfn && *cfgfn) ConfigLog(cfgfn);
if (!msgCB)
cerr <<"Config '-l@' requires a logmsg callback function "
<<"but it was found!" <<endl;
return msgCB;
}
}
XrdVERSIONINFO(XrdSysLogPInit,XrdSsiLPI);