XrdFrmPurgMain.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                     X r d F r m P u r g M a i n . c c                      */
00004 /*                                                                            */
00005 /* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //           $Id: XrdFrmPurgMain.cc 35287 2010-09-14 21:19:35Z ganis $
00012 
00013 const char *XrdFrmPurgMainCVSID = "$Id: XrdFrmPurgMain.cc 35287 2010-09-14 21:19:35Z ganis $";
00014 
00015 /* This is the "main" part of the frm_purge command. Syntax is:
00016 */
00017 static const char *XrdFrmOpts  = ":bc:dfhk:l:n:O:Tv";
00018 static const char *XrdFrmUsage =
00019 
00020   " [-b] [-c <cfgfile>] [-d] [-f] [-k {num | sz{k|m|g}] [-l <lfile>] [-n name]"
00021   " [-O free[,hold]] [-T] [-v] [<spaces>] [<paths>]\n";
00022 /*
00023 Where:
00024 
00025    -b     Run as a true daemon process in the background.
00026 
00027    -c     The configuration file. The default is '/opt/xrootd/etc/xrootd.cf'
00028 
00029    -d     Turns on debugging mode.
00030 
00031    -f     Fix orphaned files (i.e., lock and pin) by removing them.
00032 
00033    -k     Keeps num log files or no more that sz log files.
00034 
00035    -l     Specifies location of the log file. This may also come from the
00036           XrdOucLOGFILE environmental variable.
00037           By default, error messages go to standard error.
00038 
00039    -n     The instance name.
00040 
00041    -O     Run this one time only as a command. The parms are:
00042           {free% | sz{k|m|g}[,hold]
00043 
00044    -T     Runs in test mode (no actual purge will occur).
00045 
00046    -v     Verbose mode, typically prints each file purged and other details.
00047 
00048    o-t-a  The one-time-args run this as a command only once. The args direct
00049           the purging process. These may only be specified when -O specified.
00050 
00051           Syntax is: [space] path | space [path]
00052 */
00053 
00054 /******************************************************************************/
00055 /*                         i n c l u d e   f i l e s                          */
00056 /******************************************************************************/
00057   
00058 #include <unistd.h>
00059 #include <ctype.h>
00060 #include <errno.h>
00061 #include <signal.h>
00062 #include <stdlib.h>
00063 #include <string.h>
00064 #include <strings.h>
00065 #include <stdio.h>
00066 #include <sys/param.h>
00067 
00068 #include "XrdFrm/XrdFrmConfig.hh"
00069 #include "XrdFrm/XrdFrmPurge.hh"
00070 #include "XrdFrm/XrdFrmTrace.hh"
00071 #include "XrdNet/XrdNetOpts.hh"
00072 #include "XrdNet/XrdNetSocket.hh"
00073 #include "XrdOuc/XrdOucUtils.hh"
00074 #include "XrdSys/XrdSysError.hh"
00075 #include "XrdSys/XrdSysHeaders.hh"
00076 #include "XrdSys/XrdSysLogger.hh"
00077 #include "XrdSys/XrdSysPthread.hh"
00078 #include "XrdSys/XrdSysTimer.hh"
00079 
00080 using namespace XrdFrm;
00081   
00082 /******************************************************************************/
00083 /*                      G l o b a l   V a r i a b l e s                       */
00084 /******************************************************************************/
00085 
00086        XrdFrmConfig       XrdFrm::Config(XrdFrmConfig::ssPurg,
00087                                          XrdFrmOpts, XrdFrmUsage);
00088 
00089 // The following is needed to resolve symbols for objects included from xrootd
00090 //
00091        XrdOucTrace       *XrdXrootdTrace;
00092        XrdSysError        XrdLog(0, "");
00093        XrdOucTrace        XrdTrace(&Say);
00094 
00095 /******************************************************************************/
00096 /*                     T h r e a d   I n t e r f a c e s                      */
00097 /******************************************************************************/
00098   
00099 void *mainServer(void *parg)
00100 {
00101 //  int udpFD = *static_cast<int *>(parg);
00102 //  XrdFrmPurge::Server(udpFD);
00103     return (void *)0;
00104 }
00105 
00106 /******************************************************************************/
00107 /*                                  m a i n                                   */
00108 /******************************************************************************/
00109   
00110 int main(int argc, char *argv[])
00111 {
00112    XrdSysLogger Logger;
00113    extern int mainConfig();
00114    sigset_t myset;
00115 
00116 // Turn off sigpipe and host a variety of others before we start any threads
00117 //
00118    signal(SIGPIPE, SIG_IGN);  // Solaris optimization
00119    sigemptyset(&myset);
00120    sigaddset(&myset, SIGPIPE);
00121    sigaddset(&myset, SIGCHLD);
00122    pthread_sigmask(SIG_BLOCK, &myset, NULL);
00123 
00124 // Set the default stack size here
00125 //
00126    if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576);
00127       else               XrdSysThread::setStackSize((size_t)786432);
00128 
00129 // Perform configuration
00130 //
00131    Say.logger(&Logger);
00132    XrdLog.logger(&Logger);
00133    if (!Config.Configure(argc, argv, &mainConfig)) exit(4);
00134 
00135 // Fill out the dummy symbol to avoid crashes
00136 //
00137    XrdXrootdTrace = new XrdOucTrace(&Say);
00138 
00139 // Display configuration (defered because mum might have been in effect)
00140 //
00141    if (!Config.isOTO || Config.Verbose) XrdFrmPurge::Display();
00142 
00143 // Now simply poke the server every so often
00144 //
00145    if (Config.isOTO) XrdFrmPurge::Purge();
00146       else do {if (Config.StopPurge)
00147                   {int n = 0;
00148                    struct stat buf;
00149                    while(!stat(Config.StopPurge, &buf))
00150                         {if (!n--)
00151                             {Say.Emsg("PurgMain", Config.StopPurge,
00152                                       "exists; purging suspended."); n = 12;}
00153                          XrdSysTimer::Snooze(5);
00154                         }
00155                   }
00156                XrdFrmPurge::Purge();
00157                XrdSysTimer::Snooze(Config.WaitPurge);
00158               } while(1);
00159 
00160 // All done
00161 //
00162    exit(0);
00163 }
00164 
00165 /******************************************************************************/
00166 /*                            m a i n C o n f i g                             */
00167 /******************************************************************************/
00168   
00169 int mainConfig()
00170 {
00171    XrdFrmConfig::Policy *pP = Config.dfltPolicy.Next;
00172    XrdFrmConfig::VPInfo *vP = Config.VPList;
00173    XrdNetSocket *udpSock;
00174    pthread_t tid;
00175    int retc, udpFD;
00176 
00177 // If test is in effect, remove the fix flag
00178 //
00179    if (Config.Test) Config.Fix = 0;
00180 
00181 // Go through the policy list and add each policy
00182 //
00183    while((pP = Config.dfltPolicy.Next))
00184         {if (!XrdFrmPurge::Policy(pP->Sname))
00185             XrdFrmPurge::Policy(pP->Sname, pP->minFree, pP->maxFree,
00186                                 pP->Hold,  pP->Ext);
00187          Config.dfltPolicy.Next = pP->Next;
00188          delete pP;
00189         }
00190 
00191 // Make sure we have a public policy
00192 //
00193    if (!XrdFrmPurge::Policy("public"))
00194        XrdFrmPurge::Policy("public", Config.dfltPolicy.minFree,
00195                                Config.dfltPolicy.maxFree,
00196                                Config.dfltPolicy.Hold,
00197                                Config.dfltPolicy.Ext);
00198 
00199 // Now add any missing policies (we need one for every space)
00200 //
00201    while(vP)
00202       {if (!XrdFrmPurge::Policy(vP->Name))
00203           XrdFrmPurge::Policy(vP->Name, Config.dfltPolicy.minFree,
00204                                   Config.dfltPolicy.maxFree,
00205                                   Config.dfltPolicy.Hold,
00206                                   Config.dfltPolicy.Ext);
00207        vP = vP->Next;
00208       }
00209 
00210 // Enable the appropriate spaces and over-ride config value
00211 //
00212    if (!XrdFrmPurge::Init(Config.spacList, Config.cmdFree, Config.cmdHold))
00213       return 1;
00214 
00215 // We are done if this is a one-time-only call
00216 //
00217    if (Config.isOTO) return 0;
00218 
00219 // Get a UDP socket for the server
00220 //
00221    if (!(udpSock = XrdNetSocket::Create(&Say, Config.AdminPath,
00222                    "purg.udp", Config.AdminMode, XRDNET_UDPSOCKET))) return 1;
00223       else {udpFD = udpSock->Detach(); delete udpSock;}
00224 
00225 // Start the Server thread
00226 //
00227    if ((retc = XrdSysThread::Run(&tid, mainServer, (void *)&udpFD,
00228                                   XRDSYSTHREAD_BIND, "Server")))
00229       {Say.Emsg("main", retc, "create server thread"); return 1;}
00230 
00231 // All done
00232 //
00233    return 0;
00234 }

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