XrdMain.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                            X r d M a i n . c c                             */
00004 /*                                                                            */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //           $Id: XrdMain.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 const char *XrdMainCVSID = "$Id: XrdMain.cc 24468 2008-06-22 16:47:03Z ganis $";
00014 
00015 /* This is the XRootd server. The syntax is:
00016 
00017    xrootd [options]
00018 
00019    options: [-b] [-c <fname>] [-d] [-h] [-l <fname>] [-p <port>] [<oth>]
00020 
00021 Where:
00022    -b     forces background execution.
00023 
00024    -c     specifies the configuration file. This may also come from the
00025           XrdCONFIGFN environmental variable.
00026 
00027    -d     Turns on debugging mode (equivalent to xrd.trace all)
00028 
00029    -h     Displays usage line and exits.
00030 
00031    -l     Specifies location of the log file. This may also come from the
00032           XrdOucLOGFILE environmental variable or from the oofs layer. By
00033           By default, error messages go to standard error.
00034 
00035    -p     Is the port to use either as a service name or an actual port number.
00036           The default port is 1094.
00037 
00038    <oth>  Are other protocol specific options.
00039 
00040 */
00041 
00042 /******************************************************************************/
00043 /*                         i n c l u d e   f i l e s                          */
00044 /******************************************************************************/
00045   
00046 #include <unistd.h>
00047 #include <ctype.h>
00048 #include <errno.h>
00049 #include <signal.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #include <strings.h>
00053 #include <stdio.h>
00054 #include <sys/param.h>
00055 
00056 #include "Xrd/XrdBuffer.hh"
00057 #include "Xrd/XrdConfig.hh"
00058 #include "Xrd/XrdInet.hh"
00059 #include "Xrd/XrdLink.hh"
00060 #include "Xrd/XrdProtLoad.hh"
00061 #include "Xrd/XrdScheduler.hh"
00062 #define  TRACELINK newlink
00063 #include "Xrd/XrdTrace.hh"
00064 
00065 #include "XrdSys/XrdSysError.hh"
00066 #include "XrdSys/XrdSysHeaders.hh"
00067 #include "XrdSys/XrdSysLogger.hh"
00068 #include "XrdSys/XrdSysPthread.hh"
00069   
00070 /******************************************************************************/
00071 /*                      G l o b a l   V a r i a b l e s                       */
00072 /******************************************************************************/
00073 
00074        XrdConfig          XrdConf;
00075 
00076 extern int                XrdNetTCPlep;   // Defined by config
00077 extern XrdInet           *XrdNetTCP[];    // Defined by config
00078        XrdInet           *XrdNetADM = 0;
00079 
00080        XrdScheduler       XrdSched;
00081 
00082        XrdSysLogger       XrdLogger;
00083 
00084        XrdSysError        XrdLog(&XrdLogger, "Xrd");
00085 
00086        XrdSysThread      *XrdThread;
00087 
00088        XrdOucTrace        XrdTrace(&XrdLog);
00089 
00090 /******************************************************************************/
00091 /*            E x t e r n a l   T h r e a d   I n t e r f a c e s             */
00092 /******************************************************************************/
00093   
00094 void *mainAccept(void *parg)
00095 {  XrdInet *myNet = (XrdInet *)parg;
00096    int myPort = (myNet == XrdNetTCP[XrdProtLoad::ProtoMax]
00097                        ?  -(myNet->Port()) : myNet->Port());
00098    XrdProtLoad ProtSelect(myPort);
00099    XrdLink *newlink;
00100 
00101    while(1) if ((newlink = myNet->Accept(XRDNET_NODNTRIM)))
00102                {newlink->setProtocol((XrdProtocol *)&ProtSelect);
00103                 XrdSched.Schedule((XrdJob *)newlink);
00104                }
00105 
00106    return (void *)0;
00107 }
00108 
00109 /******************************************************************************/
00110 /*                             m a i n A d m i n                              */
00111 /******************************************************************************/
00112   
00113 void *mainAdmin(void *parg)
00114 {
00115    XrdLink *newlink;
00116 // static XrdProtocol_Admin  ProtAdmin;
00117    int ProtAdmin;
00118 
00119 // At this point we should be able to accept new connections
00120 //
00121    while(1) if ((newlink = XrdNetADM->Accept()))
00122                {newlink->setProtocol((XrdProtocol *)&ProtAdmin);
00123                 XrdSched.Schedule((XrdJob *)newlink);
00124                }
00125    return (void *)0;
00126 }
00127 
00128 /******************************************************************************/
00129 /*                                  m a i n                                   */
00130 /******************************************************************************/
00131   
00132 int main(int argc, char *argv[])
00133 {
00134    sigset_t myset;
00135    pthread_t tid;
00136    char buff[128];
00137    int i, retc;
00138 
00139 // Turn off sigpipe and host a variety of others before we start any threads
00140 //
00141    signal(SIGPIPE, SIG_IGN);  // Solaris optimization
00142    sigemptyset(&myset);
00143    sigaddset(&myset, SIGPIPE);
00144    sigaddset(&myset, SIGUSR1);
00145    sigaddset(&myset, SIGUSR2);
00146 #ifdef SIGRTMAX
00147    sigaddset(&myset, SIGRTMAX);
00148    sigaddset(&myset, SIGRTMAX-1);
00149 #endif
00150    sigaddset(&myset, SIGCHLD);
00151    pthread_sigmask(SIG_BLOCK, &myset, NULL);
00152 
00153 // Set the default stack size here
00154 //
00155    if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576);
00156       else               XrdSysThread::setStackSize((size_t)786432);
00157 
00158 // Process configuration file
00159 //
00160    if (XrdConf.Configure(argc, argv)) _exit(1);
00161 
00162 // Start the admin thread if an admin network is defined
00163 //
00164    if (XrdNetADM && (retc = XrdSysThread::Run(&tid, mainAdmin, (void *)0,
00165                             XRDSYSTHREAD_BIND, "Admin handler")))
00166       {XrdLog.Emsg("main", retc, "create admin thread"); _exit(3);}
00167 
00168 // At this point we should be able to accept new connections. Spawn a
00169 // thread for each network except the first. The main thread will handle
00170 // that network as some implementations require a main active thread.
00171 //
00172    for (i = 1; i <= XrdProtLoad::ProtoMax; i++)
00173        if (XrdNetTCP[i])
00174           {sprintf(buff, "Port %d handler", XrdNetTCP[i]->Port());
00175            if ((retc = XrdSysThread::Run(&tid, mainAccept,
00176                                          (void *)XrdNetTCP[i],
00177                                          XRDSYSTHREAD_BIND, strdup(buff))))
00178               {sprintf(buff, "create port %d handler", XrdNetTCP[i]->Port());
00179                XrdLog.Emsg("main", retc, buff);
00180                _exit(3);
00181               }
00182           }
00183 
00184 // Finally, start accepting connections on the main port
00185 //
00186    mainAccept((void *)XrdNetTCP[0]);
00187 
00188 // We should never get here
00189 //
00190    pthread_exit(0);
00191 }

Generated on Tue Jul 5 14:46:14 2011 for ROOT_528-00b_version by  doxygen 1.5.1