XrdCnsLog.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                          X r d C n s L o 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: XrdCnsLog.cc 30949 2009-11-02 16:37:58Z ganis $
00012 
00013 const char *XrdCnsLogCVSID = "$Id: XrdCnsLog.cc 30949 2009-11-02 16:37:58Z ganis $";
00014   
00015 #include <errno.h>
00016 #include <unistd.h>
00017 #include <fcntl.h>
00018 #include <string.h>
00019 #include <sys/types.h>
00020 #include <sys/stat.h>
00021 
00022 #include "XrdCns/XrdCnsLog.hh"
00023 #include "XrdCns/XrdCnsLogRec.hh"
00024 #include "XrdNet/XrdNetDNS.hh"
00025 #include "XrdOuc/XrdOucTList.hh"
00026 
00027 /******************************************************************************/
00028 /*                        G l o b a l   O b j e c t s                         */
00029 /******************************************************************************/
00030 
00031        const char  *XrdCnsLog::invFNa = "inv.log";
00032        const char  *XrdCnsLog::invFNt = "inventory";
00033        const char  *XrdCnsLog::invFNz = "Inventory";
00034   
00035 namespace XrdCns
00036 {
00037 extern XrdSysError  MLog;
00038 }
00039 
00040 using namespace XrdCns;
00041   
00042 /******************************************************************************/
00043 /*                                  D i r s                                   */
00044 /******************************************************************************/
00045   
00046 XrdOucTList *XrdCnsLog::Dirs(const char *Path, int &rc)
00047 {
00048    XrdOucNSWalk lDir(&MLog, Path, 0, XrdOucNSWalk::retDir
00049                                     |XrdOucNSWalk::Recurse);
00050    XrdOucNSWalk::NSEnt *nsP, *ntP;
00051    XrdOucTList *dList = 0;
00052    const char *fnP;
00053 
00054 // Convert this to a file
00055 //
00056    if ((fnP = rindex(Path, '/'))) fnP++;
00057       else fnP = Path;
00058 
00059 // If the incomming path is an endpoint then just return it
00060 //
00061    if (isEP(fnP)) return new XrdOucTList(Path, fnP-Path);
00062 
00063 // Now get all of the directories
00064 //
00065    while((nsP = lDir.Index(rc)))
00066         do {if (isEP(nsP->File))
00067                dList = new XrdOucTList(nsP->Path,nsP->File-nsP->Path,dList);
00068             ntP = nsP; nsP = nsP->Next; delete ntP;
00069            } while(nsP);
00070 
00071 // All done
00072 //
00073    return dList;
00074 }
00075 
00076 /******************************************************************************/
00077 /*                                  L i s t                                   */
00078 /******************************************************************************/
00079   
00080 XrdOucNSWalk::NSEnt *XrdCnsLog::List(const char *logDir,
00081                                      XrdOucNSWalk::NSEnt **Base,
00082                                      int isEP)
00083 {
00084    XrdOucNSWalk lDir(&MLog, logDir, 0, XrdOucNSWalk::retFile
00085                                       |XrdOucNSWalk::retStat);
00086    XrdOucNSWalk::NSEnt *nInv = 0, *nFirst = 0, *sP, *psP, *nsP, *ntP;
00087    const char *msg, *iFN = (isEP ? invFNz : invFNt);
00088    int rc;
00089 
00090 // Now get all of the files in the directory
00091 //
00092    nsP = lDir.Index(rc);
00093    if (rc) return 0;
00094 
00095 // Construct list of pending log files
00096 //
00097    while((ntP = nsP))
00098         {nsP = nsP->Next;
00099          if (isEP && *(ntP->File) == '.') {delete ntP; continue;}
00100          if (!strcmp(iFN, ntP->File) && !nInv && ntP->Stat.st_size)
00101             {nInv = ntP; continue;}
00102          rc = atoi(ntP->File+8);
00103          if (ntP->Stat.st_size == 0
00104          ||  strncmp("cns.log.", ntP->File, 8)
00105          ||  rc < 0 || rc >= XrdCnsLogRec::maxClients || *(ntP->File+9) != '.')
00106             {if (!isEP)
00107                 {msg = (ntP->Stat.st_size ? "Removing improper log file"
00108                                           : "Removing empty log file");
00109                  MLog.Emsg("List", msg, ntP->Path);
00110                  unlink(ntP->Path);
00111                 }
00112              delete ntP; continue;
00113             }
00114          sP = nFirst; psP = 0; ntP->Next = 0; ntP->Stat.st_nlink = rc;
00115          while(sP && sP->Stat.st_ctime < ntP->Stat.st_ctime)
00116               {psP = sP; sP = sP->Next;}
00117          ntP->Next = sP;
00118          if (psP) psP->Next = ntP;
00119             else  nFirst    = ntP;
00120         }
00121 
00122 // Return whatever information we have
00123 //
00124    *Base = nInv;
00125    return nFirst;
00126 }
00127 
00128 /******************************************************************************/
00129 /*                       P r i v a t e   M e t h o d s                        */
00130 /******************************************************************************/
00131 /******************************************************************************/
00132 /*                                  i s E P                                   */
00133 /******************************************************************************/
00134   
00135 int XrdCnsLog::isEP(const char *File)
00136 {
00137    struct sockaddr InetAddr;
00138    const char *dotP;
00139 
00140 // An endpoint must be a valid host name
00141 //
00142    if (!(dotP = index(File,'.')) || dotP == rindex(File,'.')) return 0;
00143    return XrdNetDNS::getHostAddr(File, InetAddr);
00144 }

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