XrdCnsSsiMain.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                      X r d C n s S s i 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. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //           $Id: XrdCnsSsiMain.cc 30949 2009-11-02 16:37:58Z ganis $
00012 
00013 const char *XrdCnsSsiMainCVSID = "$Id: XrdCnsSsiMain.cc 30949 2009-11-02 16:37:58Z ganis $";
00014 
00015 /* This is the Cluster Name Space utility. The syntax is:
00016 
00017    cns_ssi {diff | list | updt} [options] <path>
00018 
00019    options: [-f] [-h] [-m] [-n] [-p] [-s] [-S] [-v] [-l <lfile>]
00020 
00021 Where:
00022 
00023    <path> The archive (i.e., backup) path to use. All sub-directories in
00024           <path> of the form "<path>/cns/<host>" are considered.
00025 
00026    -l     list: Equivalent to specifying '-h -m -n -p -s'.
00027 
00028    -m     list: Displays the file mode.
00029 
00030    -n     list: Displays the space name.
00031 
00032    -p     list: Displays the physical location.
00033 
00034    -s     list: Displays the file size.
00035 
00036    -S     list: Same as -s but displays size in k, m, g, or t.
00037 
00038    -l     updt: Specifies location of the log file. This may also come from the
00039           XRDLOGDIR environmental variable. By default, messages go to stderr.
00040 
00041    -v     updt: Increases the verbosity of messages.
00042 */
00043 
00044 /******************************************************************************/
00045 /*                         i n c l u d e   f i l e s                          */
00046 /******************************************************************************/
00047   
00048 #include <unistd.h>
00049 #include <ctype.h>
00050 #include <errno.h>
00051 #include <signal.h>
00052 #include <stdlib.h>
00053 #include <string.h>
00054 #include <strings.h>
00055 #include <stdio.h>
00056 #include <sys/param.h>
00057 
00058 #include "XrdCns/XrdCnsSsi.hh"
00059 #include "XrdCns/XrdCnsSsiCfg.hh"
00060 #include "XrdCns/XrdCnsSsiSay.hh"
00061 
00062 #include "XrdOuc/XrdOucTList.hh"
00063 
00064 #include "XrdSys/XrdSysError.hh"
00065 #include "XrdSys/XrdSysLogger.hh"
00066 #include "XrdSys/XrdSysPthread.hh"
00067 #include "XrdSys/XrdSysTimer.hh"
00068 
00069 /******************************************************************************/
00070 /*                      G l o b a l   V a r i a b l e s                       */
00071 /******************************************************************************/
00072 
00073 namespace XrdCns
00074 {
00075 extern XrdCnsSsiCfg       Config;
00076 
00077        XrdSysError        MLog(0,"Cns_");
00078 
00079        XrdCnsSsiSay       Say(&MLog);
00080 }
00081 
00082 /******************************************************************************/
00083 /*            E x t e r n a l   T h r e a d   I n t e r f a c e s             */
00084 /******************************************************************************/
00085 
00086 namespace XrdCns
00087 {
00088 void *MLogWorker(void *parg)
00089 {
00090    time_t midnite = XrdSysTimer::Midnight() + 86400;
00091 
00092 // Just blab out the midnight herald
00093 //
00094    while(1)
00095         {XrdSysTimer::Wait(midnite - time(0));
00096          MLog.Say(0, "XrdCnsd - Cluster Name Space Daemon");
00097          midnite += 86400;
00098         }
00099    return (void *)0;
00100 }
00101 }
00102 using namespace XrdCns;
00103 
00104 /******************************************************************************/
00105 /*                                  m a i n                                   */
00106 /******************************************************************************/
00107   
00108 int main(int argc, char *argv[])
00109 {
00110    XrdSysLogger MLogger;
00111    XrdOucTList *tP;
00112    sigset_t myset;
00113    char *hP;
00114    int rc = 0;
00115 
00116 // Establish message routing
00117 //
00118    MLog.logger(&MLogger);
00119 
00120 // Turn off sigpipe and host a variety of others before we start any threads
00121 //
00122    signal(SIGPIPE, SIG_IGN);  // Solaris optimization
00123    sigemptyset(&myset);
00124    sigaddset(&myset, SIGPIPE);
00125    sigaddset(&myset, SIGCHLD);
00126    pthread_sigmask(SIG_BLOCK, &myset, NULL);
00127 
00128 // Set the default stack size here
00129 //
00130    if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576);
00131       else               XrdSysThread::setStackSize((size_t)786432);
00132 
00133 // Process the options and arguments
00134 //
00135    if (!Config.Configure(argc, argv)) exit(1);
00136    Say.setV(Config.Verbose);
00137 
00138 // Construct the logfile path and bind it (command line only)
00139 //
00140    if (!Config.logFN && (Config.logFN = getenv("XRDLOGDIR")))
00141       {pthread_t tid;
00142        char buff[2048];
00143        int retc;
00144        strcpy(buff, Config.logFN); strcat(buff, "cnsssilog");
00145        MLogger.Bind(buff, 24*60*60);
00146        MLog.logger(&MLogger);
00147        if ((retc = XrdSysThread::Run(&tid, MLogWorker, (void *)0,
00148                                  XRDSYSTHREAD_BIND, "Midnight runner")))
00149           MLog.Emsg("Main", retc, "create midnight runner");
00150       }
00151 
00152 // Process the request
00153 //
00154    while((tP = Config.dirList))
00155         {hP = tP->text + tP->val;
00156          if (Config.Xeq == 'l') rc |= XrdCnsSsi::List(hP, tP->text);
00157             else {int i = XrdCnsSsi::Updt(hP, tP->text);
00158                   if (i) Say.M("Unable to update ", hP, " inventory.");
00159                   rc |= i;
00160                  }
00161          Config.dirList = tP->next;
00162          delete tP;
00163         }
00164 
00165 // All done
00166 //
00167    exit(rc);
00168 }

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