XRootD
Loading...
Searching...
No Matches
XrdMain.cc File Reference
#include <unistd.h>
#include <cctype>
#include <cerrno>
#include <cstdint>
#include <signal.h>
#include <cstdlib>
#include <cstring>
#include <strings.h>
#include <cstdio>
#include <sys/param.h>
#include "Xrd/XrdConfig.hh"
#include "Xrd/XrdInet.hh"
#include "Xrd/XrdLink.hh"
#include "Xrd/XrdProtLoad.hh"
#include "Xrd/XrdScheduler.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysPthread.hh"
#include "XrdSys/XrdSysUtils.hh"
Include dependency graph for XrdMain.cc:

Go to the source code of this file.

Classes

class  XrdMain

Functions

int main (int argc, char *argv[])
void * mainAccept (void *parg)
void * mainAdmin (void *parg)

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 161 of file XrdMain.cc.

162{
163 XrdMain Main;
164 pthread_t tid;
165 char buff[128];
166 int i, retc;
167
168// Set TZ environment variable to read the system timezone from /etc/localtime
169// if it is not already set, to avoid race conditions between localtime_r() and
170// mktime() during the multi-threaded phase of the initialization.
171
172 if (access("/etc/localtime", R_OK) == 0)
173 setenv("TZ", ":/etc/localtime", /* overwrite */ false);
174
175// Call tzset() early to ensure thread-safety of localtime_r() and mktime().
176 tzset();
177
178// Turn off sigpipe and host a variety of others before we start any threads
179//
181
182// Set the default stack size here. Note that on modern Linux the default
183// stack size is set at about 8MB. We force a lower limit to not have a huge
184// virtual address space mostly for core file debugging purposes.
185//
186 if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)2097152, true);
187 else XrdSysThread::setStackSize((size_t)1048576, true);
188
189// Process configuration file
190//
191 if (Main.Config.Configure(argc, argv)) _exit(1);
192
193// Start the admin thread if an admin network is defined
194//
195 if (Main.Config.NetADM && (retc = XrdSysThread::Run(&tid, mainAdmin,
196 (void *)new XrdMain(Main.Config.NetADM),
197 XRDSYSTHREAD_BIND, "Admin handler")))
198 {Main.Config.ProtInfo.eDest->Emsg("main", retc, "create admin thread");
199 _exit(3);
200 }
201
202// At this point we should be able to accept new connections. Spawn a
203// thread for each network except the first. The main thread will handle
204// that network as some implementations require a main active thread.
205//
206 for (i = 1; i < (int)Main.Config.NetTCP.size(); i++)
207 if (Main.Config.NetTCP[i])
208 {XrdMain *Parms = new XrdMain(Main.Config.NetTCP[i]);
209 sprintf(buff, "Port %d handler", Parms->thePort);
210//??? if (Parms->theNet == Main.Config.NetTCP[XrdProtLoad::ProtoMax])
211// Parms->thePort = -(Parms->thePort);
212 if ((retc = XrdSysThread::Run(&tid, mainAccept, (void *)Parms,
213 XRDSYSTHREAD_BIND, strdup(buff))))
214 {Main.Config.ProtInfo.eDest->Emsg("main", retc, "create", buff);
215 _exit(3);
216 }
217 }
218
219// Finally, start accepting connections on the main port
220//
221 Main.theNet = Main.Config.NetTCP[0];
222 Main.thePort = Main.Config.NetTCP[0]->Port();
223 mainAccept((void *)&Main);
224
225// We should never get here
226//
227 pthread_exit(0);
228}
void * mainAdmin(void *parg)
Definition XrdMain.cc:139
void * mainAccept(void *parg)
Definition XrdMain.cc:115
#define access(a, b)
Definition XrdPosix.hh:44
#define XRDSYSTHREAD_BIND
XrdProtocol_Config ProtInfo
Definition XrdConfig.hh:58
XrdInet * NetADM
Definition XrdConfig.hh:59
std::vector< XrdInet * > NetTCP
Definition XrdConfig.hh:60
int Configure(int argc, char **argv)
Definition XrdConfig.cc:325
XrdInet * theNet
Definition XrdMain.cc:93
int thePort
Definition XrdMain.cc:94
static XrdConfig Config
Definition XrdMain.cc:95
XrdSysError * eDest
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void setStackSize(size_t stsz, bool force=false)
static bool SigBlock()

References access, XrdMain::Config, XrdConfig::Configure(), XrdProtocol_Config::eDest, XrdSysError::Emsg(), mainAccept(), mainAdmin(), XrdConfig::NetADM, XrdConfig::NetTCP, XrdConfig::ProtInfo, XrdSysThread::Run(), XrdSysThread::setStackSize(), XrdSysUtils::SigBlock(), XrdMain::theNet, XrdMain::thePort, and XRDSYSTHREAD_BIND.

Here is the call graph for this function:

◆ mainAccept()

void * mainAccept ( void * parg)

Definition at line 115 of file XrdMain.cc.

116{ XrdMain *Parms = (XrdMain *)parg;
117 XrdScheduler *mySched = Parms->Config.ProtInfo.Sched;
118 XrdProtLoad ProtSelect(Parms->thePort);
119 XrdSysSemaphore accepted(0);
120
121// Complete the parms
122//
123 Parms->theSem = &accepted;
124 Parms->theProt = (XrdProtocol *)&ProtSelect;
125
126// Simply schedule new accepts
127//
128 while(1) {mySched->Schedule((XrdJob *)Parms);
129 accepted.Wait();
130 }
131
132 return (void *)0;
133}
XrdSysSemaphore * theSem
Definition XrdMain.cc:91
XrdProtocol * theProt
Definition XrdMain.cc:92
XrdScheduler * Sched
void Schedule(XrdJob *jp)

References XrdMain::Config, XrdConfig::ProtInfo, XrdProtocol_Config::Sched, XrdScheduler::Schedule(), XrdMain::thePort, XrdMain::theProt, XrdMain::theSem, and XrdSysSemaphore::Wait().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mainAdmin()

void * mainAdmin ( void * parg)

Definition at line 139 of file XrdMain.cc.

140{ XrdMain *Parms = (XrdMain *)parg;
141 XrdInet *NetADM = Parms->theNet;
142 XrdLink *newlink;
143// static XrdProtocol_Admin ProtAdmin;
144 int ProtAdmin;
145
146// At this point we should be able to accept new connections. Noe that we don't
147// support admin connections as of yet so the following code is superflous.
148//
149 while(1) if ((newlink = NetADM->Accept()))
150 {newlink->setProtocol((XrdProtocol *)&ProtAdmin);
151 newlink->setProtName("xrdadmin");
152 Parms->Config.ProtInfo.Sched->Schedule((XrdJob *)newlink);
153 }
154 return (void *)0;
155}
XrdLink * Accept(int opts=0, int timeout=-1, XrdSysSemaphore *theSem=0)
Definition XrdInet.cc:72

References XrdInet::Accept(), XrdMain::Config, XrdConfig::ProtInfo, XrdProtocol_Config::Sched, XrdScheduler::Schedule(), XrdLink::setProtName(), XrdLink::setProtocol(), and XrdMain::theNet.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function: