XRootD
Loading...
Searching...
No Matches
XrdFrmPurgMain.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d F r m P u r g M a i n . c c */
4/* */
5/* (c) 2009 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31/* This is the "main" part of the frm_purge command. Syntax is:
32*/
33static const char *XrdFrmOpts = ":bc:dfhk:l:n:O:s:S:Tvz";
34static const char *XrdFrmUsage =
35
36 " [-b] [-c <cfgfile>] [-d] [-f] [-k {num|sz{k|m|g}|sig] [-l [=]<fn>] [-n name]"
37 " [-O free[,hold]] [-s pidfile] [-S site] [-T] [-v] [-z] [<spaces>] [<paths>]\n";
38/*
39Where:
40
41 -b Run as a true daemon process in the background.
42
43 -c The configuration file. The default is '/opt/xrootd/etc/xrootd.cf'
44
45 -d Turns on debugging mode.
46
47 -f Fix orphaned files (i.e., lock and pin) by removing them.
48
49 -k Keeps num log files or no more that sz log files.
50
51 -l Specifies location of the log file. This may also come from the
52 XrdOucLOGFILE environmental variable.
53 By default, error messages go to standard error.
54
55 -n The instance name.
56
57 -O Run this one time only as a command. The parms are:
58 {free% | sz{k|m|g}[,hold]
59
60 -s The pidfile name.
61
62 -S The site name.
63
64 -T Runs in test mode (no actual purge will occur).
65
66 -v Verbose mode, typically prints each file purged and other details.
67
68 o-t-a The one-time-args run this as a command only once. The args direct
69 the purging process. These may only be specified when -O specified.
70
71 Syntax is: [space] path | space [path]
72*/
73
74/******************************************************************************/
75/* i n c l u d e f i l e s */
76/******************************************************************************/
77
78#include <unistd.h>
79#include <cctype>
80#include <cerrno>
81#include <cstdlib>
82#include <cstring>
83#include <strings.h>
84#include <cstdio>
85#include <sys/param.h>
86
87#include "XrdFrc/XrdFrcTrace.hh"
89#include "XrdFrm/XrdFrmPurge.hh"
90#include "XrdNet/XrdNetOpts.hh"
92#include "XrdOuc/XrdOucUtils.hh"
93#include "XrdSys/XrdSysError.hh"
97#include "XrdSys/XrdSysTimer.hh"
98#include "XrdSys/XrdSysUtils.hh"
99
100using namespace XrdFrc;
101using namespace XrdFrm;
102
103/******************************************************************************/
104/* G l o b a l V a r i a b l e s */
105/******************************************************************************/
106
109
110// The following is needed to resolve symbols for objects included from xrootd
111//
114 XrdOucTrace XrdTrace(&Say);
115
116/******************************************************************************/
117/* T h r e a d I n t e r f a c e s */
118/******************************************************************************/
119
120void *mainServer(void *parg)
121{
122// int udpFD = *static_cast<int *>(parg);
123// XrdFrmPurge::Server(udpFD);
124 return (void *)0;
125}
126
127/******************************************************************************/
128/* m a i n */
129/******************************************************************************/
130
131int main(int argc, char *argv[])
132{
134 extern int mainConfig();
135
136// Turn off sigpipe and host a variety of others before we start any threads
137//
139
140// Set the default stack size here
141//
142 if (sizeof(long) > 4) XrdSysThread::setStackSize((size_t)1048576);
143 else XrdSysThread::setStackSize((size_t)786432);
144
145// Perform configuration
146//
147 Say.logger(&Logger);
149 if (!Config.Configure(argc, argv, &mainConfig)) exit(4);
150
151// Fill out the dummy symbol to avoid crashes
152//
154
155// Display configuration (deferred because mum might have been in effect)
156//
158
159// Now simply poke the server every so often
160//
162 else do {if (Config.StopPurge)
163 {int n = 0;
164 struct stat buf;
165 while(!stat(Config.StopPurge, &buf))
166 {if (!n--)
167 {Say.Emsg("PurgMain", Config.StopPurge,
168 "exists; purging suspended."); n = 12;}
170 }
171 }
174 } while(1);
175
176// All done
177//
178 exit(0);
179}
180
181/******************************************************************************/
182/* m a i n C o n f i g */
183/******************************************************************************/
184
186{
189 XrdNetSocket *udpSock;
190 pthread_t tid;
191 int retc, udpFD;
192
193// If test is in effect, remove the fix flag
194//
195 if (Config.Test) Config.Fix = 0;
196
197// Go through the policy list and add each policy
198//
199 while((pP = Config.dfltPolicy.Next))
200 {if (!XrdFrmPurge::Policy(pP->Sname))
202 pP->Hold, pP->Ext);
204 delete pP;
205 }
206
207// Make sure we have a public policy
208//
209 if (!XrdFrmPurge::Policy("public"))
214
215// Now add any missing policies (we need one for every space)
216//
217 while(vP)
218 {if (!XrdFrmPurge::Policy(vP->Name))
223 vP = vP->Next;
224 }
225
226// Enable the appropriate spaces and over-ride config value
227//
229 return 1;
230
231// We are done if this is a one-time-only call
232//
233 if (Config.isOTO) return 0;
234
235// Get a UDP socket for the server
236//
237 if (!(udpSock = XrdNetSocket::Create(&Say, Config.AdminPath,
238 "purg.udp", Config.AdminMode, XRDNET_UDPSOCKET))) return 1;
239 else {udpFD = udpSock->Detach(); delete udpSock;}
240
241// Start the Server thread
242//
243 if ((retc = XrdSysThread::Run(&tid, mainServer, (void *)&udpFD,
244 XRDSYSTHREAD_BIND, "Server")))
245 {Say.Emsg("main", retc, "create server thread"); return 1;}
246
247// All done
248//
249 return 0;
250}
static XrdSysLogger Logger
int main(int argc, char *argv[])
XrdOucTrace * XrdXrootdTrace
XrdSysError XrdLog(0, "")
int mainConfig()
void * mainServer(void *parg)
static const char * XrdFrmUsage
static const char * XrdFrmOpts
#define XRDNET_UDPSOCKET
Definition XrdNetOpts.hh:79
#define stat(a, b)
Definition XrdPosix.hh:101
#define XRDSYSTHREAD_BIND
struct XrdFrmConfig::VPInfo * VPList
XrdOucTList * spacList
long long cmdFree
int Configure(int argc, char **argv, int(*ppf)())
static void Purge()
static XrdFrmPurge * Policy(const char *sname)
static void Display()
static int Init(XrdOucTList *sP=0, long long minV=-1, int hVal=-1)
static XrdNetSocket * Create(XrdSysError *Say, const char *path, const char *fn, mode_t mode, int isudp=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
static void setStackSize(size_t stsz, bool force=false)
static void Snooze(int seconds)
static bool SigBlock()
XrdSysError Say
XrdFrmConfig Config
char Sname[XrdOssSpace::minSNbsz]