XrdCnsSsiCfg.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                       X r d C n s S s i C f g . 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: XrdCnsSsiCfg.cc 32231 2010-02-05 18:24:46Z ganis $
00012 
00013 const char *XrdCnsSsiCfgCVSID = "$Id: XrdCnsSsiCfg.cc 32231 2010-02-05 18:24:46Z ganis $";
00014 
00015 #include <unistd.h>
00016 #include <string.h>
00017 #include <stdio.h>
00018 #include <sys/types.h>
00019 
00020 #include "XrdOuc/XrdOuca2x.hh"
00021 #include "XrdOuc/XrdOucArgs.hh"
00022 #include "XrdOuc/XrdOucTList.hh"
00023 #include "XrdOuc/XrdOucUtils.hh"
00024 
00025 #include "XrdSys/XrdSysError.hh"
00026 #include "XrdSys/XrdSysLogger.hh"
00027 
00028 #include "XrdCns/XrdCnsLog.hh"
00029 #include "XrdCns/XrdCnsSsiCfg.hh"
00030 #include "XrdCns/XrdCnsSsiSay.hh"
00031 
00032 /******************************************************************************/
00033 /*           G l o b a l   C o n f i g u r a t i o n   O b j e c t            */
00034 /******************************************************************************/
00035 
00036 namespace XrdCns
00037 {
00038        XrdCnsSsiCfg      Config;
00039 
00040 extern XrdSysError       MLog;
00041 
00042 extern XrdCnsSsiSay      Say;
00043 }
00044 
00045 using namespace XrdCns;
00046   
00047 /******************************************************************************/
00048 /*                             C o n f i g u r e                              */
00049 /******************************************************************************/
00050 
00051 int XrdCnsSsiCfg::Configure(int argc, char **argv)
00052 {
00053    const char *Opts = 0;
00054 
00055 // Determine the function and configure for that
00056 //
00057         if (argc <= 1) Usage("Function not specified.");
00058    else if (!strcmp("diff", argv[1])) {Xeq = 'd'; Opts = "fFhmnps";
00059            Say.M("The diff function is not yet implemented.");
00060            return 0;
00061           }
00062    else if (!strcmp("list", argv[1])) {Xeq = 'l'; Opts = "fhlmnpsS";}
00063    else if (!strcmp("updt", argv[1])) {Xeq = 'u'; Opts = "v";}
00064    else Usage("Invalid function - ", argv[1]);
00065 
00066    Func = strdup(argv[1]);
00067    return Configure(argc-1, argv+1, Opts);
00068 }
00069 
00070 /******************************************************************************/
00071 
00072 int XrdCnsSsiCfg::Configure(int argc, char **argv, const char *Opts)
00073 {
00074 /*
00075   Function: Establish configuration at start up time via arglist.
00076 
00077   Input:    None.
00078 
00079   Output:   1 upon success or 0 otherwise.
00080 */
00081 
00082    XrdOucArgs Spec(&MLog, "cns_ssi: ", Opts);
00083    struct stat Stat;
00084    char buff[2048], *dP;
00085    char theOpt, *theArg;
00086    int n, NoGo = 0;
00087 
00088 // Setup the arguments
00089 //
00090    Spec.Set(argc-1, argv+1);
00091 
00092 // Parse the options
00093 //
00094    while((theOpt = Spec.getopt()) != -1) 
00095      {switch(theOpt)
00096        {
00097        case 'h': Lopt |= Lhost;
00098                  break;
00099        case 'l': if (Xeq == 'l') Lopt |= Lfull;
00100                     else logFN = Spec.argval;
00101                  break;
00102        case 'm': Lopt |= Lmode;
00103                  break;
00104        case 'n': Lopt |= Lname;
00105                  break;
00106        case 'p': Lopt |= Lmount;
00107                  break;
00108        case 's': Lopt |= Lsize;
00109                  break;
00110        case 'S': Lopt |= Lsize | Lfmts;
00111                  break;
00112        case 'v': Verbose = 1;
00113                  break;
00114        default:  NoGo = 1;
00115        }
00116      }
00117 
00118 // Get the destination for the name space
00119 //
00120    if ((theArg = Spec.getarg())) bPath = strdup(theArg);
00121       else Usage("Inventory directory not specified.");
00122 
00123 // Verify that the target directory exists and is a directory
00124 //
00125         if (stat(bPath, &Stat)) n = errno;
00126    else if ((Stat.st_mode & S_IFMT) != S_IFDIR) n = ENOTDIR;
00127    else n = 0;
00128    if (n) {Say.M("Unable to process '",bPath,"'; ",
00129            XrdOucUtils::eText(n, buff, sizeof(buff)));
00130            return 0;
00131           }
00132 
00133 // Strip trailing slashes from the path
00134 //
00135    dP = bPath + strlen(bPath) - 1;
00136    while(*dP == '/') {*dP = '\0'; dP--;}
00137 
00138 // Make sure we have some host entries
00139 //
00140    if (!(dirList = XrdCnsLog::Dirs(bPath, n)))
00141       {Say.M("No server inventories found in '",bPath,"'."); return 0;}
00142 
00143 // Issue warning if errors occurred
00144 //
00145    if (n) Say.M("Errors encountered; ",Func, " may be incomplete!");
00146 
00147 // All done here
00148 //
00149    return !NoGo;
00150 }
00151 
00152 /******************************************************************************/
00153 /*                                 U s a g e                                  */
00154 /******************************************************************************/
00155   
00156 void XrdCnsSsiCfg::Usage(const char *T1, const char *T2)
00157 {
00158    const char *What=
00159    "cns_ssi {diff npath | list [lopts] | updt [uopts]} <dirpath>\n\n"
00160    "lopts: [-h] [-l] [-m] [-n] [-p] [-s] [-S]\n"
00161    "uopts: [-l <lfile>] [-v]";
00162 
00163    MLog.Say("cns_ssi: ", T1, T2);
00164    MLog.Say("\nUsage: ", What);
00165    exit(4);
00166 }

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