XRootD
Loading...
Searching...
No Matches
XrdFrcUtils Class Reference

#include <XrdFrcUtils.hh>

+ Collaboration diagram for XrdFrcUtils:

Public Member Functions

 XrdFrcUtils ()
 
 ~XrdFrcUtils ()
 

Static Public Member Functions

static char Ask (char dflt, const char *Msg1, const char *Msg2="", const char *Msg3="")
 
static int chkURL (const char *Url)
 
static char * makePath (const char *iName, const char *Path, int Mode)
 
static char * makeQDir (const char *Path, int Mode)
 
static int MapM2O (const char *Nop, const char *Pop)
 
static int MapR2Q (char Opc, int *Flags=0)
 
static int MapV2I (const char *Opc, XrdFrcRequest::Item &ICode)
 
static int Unique (const char *lkfn, const char *myProg)
 
static int updtCpy (const char *Pfn, int Adj)
 
static int Utime (const char *Path, time_t tVal)
 

Detailed Description

Definition at line 40 of file XrdFrcUtils.hh.

Constructor & Destructor Documentation

◆ XrdFrcUtils()

XrdFrcUtils::XrdFrcUtils ( )
inline

Definition at line 65 of file XrdFrcUtils.hh.

65{}

◆ ~XrdFrcUtils()

XrdFrcUtils::~XrdFrcUtils ( )
inline

Definition at line 66 of file XrdFrcUtils.hh.

66{}

Member Function Documentation

◆ Ask()

char XrdFrcUtils::Ask ( char dflt,
const char * Msg1,
const char * Msg2 = "",
const char * Msg3 = "" )
static

Definition at line 56 of file XrdFrcUtils.cc.

58{
59 const char *Hint;
60 char Answer[8];
61 int n;
62
63 Hint = (dflt == 'y' ? " (y | n | a): " : " (n | y | a): ");
64
65 do {std::cerr <<"frm_admin: " <<Msg1 <<Msg2 <<Msg3 <<Hint;
66 std::cin.getline(Answer, sizeof(Answer));
67 if (!*Answer) return dflt;
68
69 n = strlen(Answer);
70 if (!strncmp("yes", Answer, n)) return 'y';
71 if (!strncmp("no", Answer, n)) return 'n';
72 if (!strncmp("abort",Answer, n)) return 'a';
73 } while(1);
74 return 'a';
75}

◆ chkURL()

int XrdFrcUtils::chkURL ( const char * Url)
static

Definition at line 81 of file XrdFrcUtils.cc.

82{
83 const char *Elem;
84
85// Verify that this is a valid url and return offset to the lfn
86//
87 if (!(Elem = index(Url, ':'))) return 0;
88 if (Elem[1] != '/' || Elem[2] != '/') return 0;
89 if (!(Elem = index(Elem+3, '/')) || Elem[1] != '/') return 0;
90 Elem++;
91
92// At this point ignore all leading slashes but one
93//
94 while(Elem[1] == '/') Elem++;
95 return Elem - Url;
96}

Referenced by XrdFrcProxy::Add().

+ Here is the caller graph for this function:

◆ makePath()

char * XrdFrcUtils::makePath ( const char * iName,
const char * Path,
int Mode )
static

Definition at line 102 of file XrdFrcUtils.cc.

103{
104 char *bPath;
105 int rc;
106
107// Generate an frm-specific admin path
108//
109 bPath = XrdOucUtils::genPath(Path, iName, "frm");
110
111// Create the admin directory if it does not exists and a mode supplied
112//
113 if (Mode > 0 && (rc = XrdOucUtils::makePath(bPath, Mode)))
114 {Say.Emsg("makePath", rc, "create directory", bPath);
115 return 0;
116 }
117
118// Return the actual adminpath we are to use (this has been strduped).
119//
120 return bPath;
121}
XrdOucPup XrdCmsParser::Pup & Say
int Mode
XrdOucString Path
static char * genPath(const char *path, const char *inst, const char *psfx=0)
static int makePath(char *path, mode_t mode, bool reset=false)

References XrdOucUtils::genPath(), XrdOucUtils::makePath(), Mode, Path, and Say.

Referenced by XrdFrcProxy::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeQDir()

char * XrdFrcUtils::makeQDir ( const char * Path,
int Mode )
static

Definition at line 127 of file XrdFrcUtils.cc.

128{
129 char qPath[1040], qLink[1032];
130 int n, lksz, rc;
131
132// Generate an frm-specific queue path
133//
134 strcpy(qPath, Path);
135 n = strlen(qPath);
136 if (qPath[n-1] != '/') qPath[n++] = '/';
137 strcpy(qPath+n, "Queues/");
138
139// If the target is a symlink, optimize the path
140//
141 if ((lksz = readlink(qPath, qLink, sizeof(qLink)-1)) > 0)
142 {qLink[lksz] = '\0';
143 if (qLink[lksz-1] != '/') {qLink[lksz++] = '/'; qLink[lksz++] = '\0';}
144 if (*qLink == '/') strcpy(qPath, qLink);
145 else strcpy(qPath+n, qLink);
146 }
147
148// Create the queue directory if it does not exists
149//
150 if (Mode > 0 && (rc = XrdOucUtils::makePath(qPath, Mode)))
151 {Say.Emsg("makeQDir", rc, "create directory", qPath);
152 return 0;
153 }
154
155// Return the actual adminpath we are to use
156//
157 return strdup(qPath);
158}

References XrdOucUtils::makePath(), Mode, Path, and Say.

Referenced by XrdFrcReqAgent::Start(), and XrdFrmReqBoss::Start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapM2O()

int XrdFrcUtils::MapM2O ( const char * Nop,
const char * Pop )
static

Definition at line 164 of file XrdFrcUtils.cc.

165{
166 int Options = 0;
167
168// Map processing options to request options
169//
170 if (index(Pop, 'w')) Options |= XrdFrcRequest::makeRW;
171 if (*Nop != '-')
172 {if (index(Pop, 's') || index(Pop, 'n'))
173 Options |= XrdFrcRequest::msgSucc;
174 if (index(Pop, 'f') || !index(Pop, 'q'))
175 Options |= XrdFrcRequest::msgFail;
176 }
177
178// All done
179//
180 return Options;
181}
static const int msgFail
static const int makeRW
static const int msgSucc

References XrdFrcRequest::makeRW, XrdFrcRequest::msgFail, and XrdFrcRequest::msgSucc.

Referenced by XrdFrcProxy::Add().

+ Here is the caller graph for this function:

◆ MapR2Q()

int XrdFrcUtils::MapR2Q ( char Opc,
int * Flags = 0 )
static

Definition at line 187 of file XrdFrcUtils.cc.

188{
189
190// Simply map the request code to the relevant queue
191//
192 switch(Opc)
193 {case 0 :
194 case '+': return XrdFrcRequest::stgQ;
195 case '^': if (Flags) *Flags = XrdFrcRequest::Purge;
196 return XrdFrcRequest::migQ;
197 case '&': return XrdFrcRequest::migQ;
198 case '<': return XrdFrcRequest::getQ;
199 case '=': if (Flags) *Flags |= XrdFrcRequest::Purge;
200 return XrdFrcRequest::putQ;
201 case '>': return XrdFrcRequest::putQ;
202 default: break;
203 }
204 return XrdFrcRequest::nilQ;
205}
static const int stgQ
static const int getQ
static const int migQ
static const int putQ
static const int Purge
static const int nilQ

References XrdFrcRequest::getQ, XrdFrcRequest::migQ, XrdFrcRequest::nilQ, XrdFrcRequest::Purge, XrdFrcRequest::putQ, and XrdFrcRequest::stgQ.

Referenced by XrdFrcProxy::Add(), and XrdFrcProxy::Del().

+ Here is the caller graph for this function:

◆ MapV2I()

int XrdFrcUtils::MapV2I ( const char * Opc,
XrdFrcRequest::Item & ICode )
static

Definition at line 211 of file XrdFrcUtils.cc.

212{
213 static struct ITypes {const char *IName; XrdFrcRequest::Item ICode;}
214 ITList[] = {{"lfn", XrdFrcRequest::getLFN},
215 {"lfncgi", XrdFrcRequest::getLFNCGI},
216 {"mode", XrdFrcRequest::getMODE},
217 {"obj", XrdFrcRequest::getOBJ},
218 {"objcgi", XrdFrcRequest::getOBJCGI},
219 {"op", XrdFrcRequest::getOP},
220 {"prty", XrdFrcRequest::getPRTY},
221 {"qwt", XrdFrcRequest::getQWT},
222 {"rid", XrdFrcRequest::getRID},
223 {"tod", XrdFrcRequest::getTOD},
224 {"note", XrdFrcRequest::getNOTE},
225 {"tid", XrdFrcRequest::getUSER}};
226 static const int ITNum = sizeof(ITList)/sizeof(struct ITypes);
227 int i;
228
229// Simply map the variable name to the item code
230//
231 for (i = 0; i < ITNum; i++)
232 if (!strcmp(vName, ITList[i].IName))
233 {ICode = ITList[i].ICode; return 1;}
234 return 0;
235}

References XrdFrcRequest::getLFN, XrdFrcRequest::getLFNCGI, XrdFrcRequest::getMODE, XrdFrcRequest::getNOTE, XrdFrcRequest::getOBJ, XrdFrcRequest::getOBJCGI, XrdFrcRequest::getOP, XrdFrcRequest::getPRTY, XrdFrcRequest::getQWT, XrdFrcRequest::getRID, XrdFrcRequest::getTOD, and XrdFrcRequest::getUSER.

◆ Unique()

int XrdFrcUtils::Unique ( const char * lkfn,
const char * myProg )
static

Definition at line 241 of file XrdFrcUtils.cc.

242{
243 static const int Mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH;
244 FLOCK_t lock_args;
245 int myFD, rc;
246
247// Open the lock file first in r/w mode
248//
249 if ((myFD = open(lkfn, O_RDWR|O_CREAT, Mode)) < 0)
250 {Say.Emsg("Unique",errno,"open",lkfn); return 0;}
251
252// Establish locking options
253//
254 bzero(&lock_args, sizeof(lock_args));
255 lock_args.l_type = F_WRLCK;
256
257// Perform action.
258//
259 do {rc = fcntl(myFD,F_SETLK,&lock_args);}
260 while(rc < 0 && errno == EINTR);
261 if (rc < 0)
262 {Say.Emsg("Unique", errno, "obtain the run lock on", lkfn);
263 Say.Emsg("Unique", "Another", myProg, "may already be running!");
264 close(myFD);
265 return 0;
266 }
267
268// All done
269//
270 return 1;
271}
int fcntl(int fd, int cmd,...)
#define close(a)
Definition XrdPosix.hh:43
#define open
Definition XrdPosix.hh:71
#define FLOCK_t

References close, fcntl(), FLOCK_t, Mode, open, and Say.

Referenced by XrdFrmXfrDaemon::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updtCpy()

int XrdFrcUtils::updtCpy ( const char * Pfn,
int Adj )
static

Definition at line 277 of file XrdFrcUtils.cc.

278{
279 XrdOucXAttr<XrdFrcXAttrCpy> cpyInfo;
280 struct stat Stat;
281
282// Make sure the base file exists
283//
284 if (stat(Pfn, &Stat)) {Say.Emsg("updCpy", errno,"stat pfn ",Pfn); return 0;}
285
286// Set correct copy time based on need
287//
288 cpyInfo.Attr.cpyTime = static_cast<long long>(Stat.st_mtime + Adj);
289 return cpyInfo.Set(Pfn) == 0;
290}
struct stat Stat
Definition XrdCks.cc:49
#define stat(a, b)
Definition XrdPosix.hh:96
int Set(const char *Path, int fd=-1)

References XrdOucXAttr< T >::Attr, Say, XrdOucXAttr< T >::Set(), Stat, and stat.

+ Here is the call graph for this function:

◆ Utime()

int XrdFrcUtils::Utime ( const char * Path,
time_t tVal )
static

Definition at line 296 of file XrdFrcUtils.cc.

297{
298 struct utimbuf tbuf = {tVal, tVal};
299 int rc;
300
301// Set the time
302//
303 do {rc = utime(Path, &tbuf);} while(rc && errno == EINTR);
304 if (rc) Say.Emsg("Utils", errno, "set utime for pfn", Path);
305
306// All done
307//
308 return rc == 0;
309}

References Path, and Say.


The documentation for this class was generated from the following files: