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

#include <XrdXrootdPrepare.hh>

+ Inheritance diagram for XrdXrootdPrepare:
+ Collaboration diagram for XrdXrootdPrepare:

Public Member Functions

 XrdXrootdPrepare (XrdSysError *lp, XrdScheduler *sp, bool nomsg)
 
 ~XrdXrootdPrepare ()
 
void DoIt ()
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 
virtual void DoIt ()=0
 

Static Public Member Functions

static int Close (int fd)
 
static int List (XrdXrootdPrepArgs &pargs, char *resp, int resplen)
 
static void Log (XrdXrootdPrepArgs &pargs)
 
static void Logdel (char *reqid)
 
static int Open (const char *reqid, int &fsz)
 
static void Scrub ()
 
static int setParms (char *ldir)
 
static int setParms (int stime, int skeep)
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 83 of file XrdXrootdPrepare.hh.

Constructor & Destructor Documentation

◆ XrdXrootdPrepare()

XrdXrootdPrepare::XrdXrootdPrepare ( XrdSysError lp,
XrdScheduler sp,
bool  nomsg 
)

Definition at line 79 of file XrdXrootdPrepare.cc.

80 : XrdJob("Prep log scrubber")
81{eDest = errp;
82 SchedP = sp;
83 if (LogDir) SchedP->Schedule((XrdJob *)this, scrubtime+time(0));
84// else if (!nomsg) eDest->Say("Config warning: 'xrootd.prepare logdir' "
85// "not specified; prepare tracking disabled.");
86}
void Schedule(XrdJob *jp)

References XrdScheduler::Schedule().

+ Here is the call graph for this function:

◆ ~XrdXrootdPrepare()

XrdXrootdPrepare::~XrdXrootdPrepare ( )
inline

Definition at line 108 of file XrdXrootdPrepare.hh.

108{} // Never gets deleted

Member Function Documentation

◆ Close()

static int XrdXrootdPrepare::Close ( int  fd)
inlinestatic

Definition at line 87 of file XrdXrootdPrepare.hh.

87{return close(fd);}
#define close(a)
Definition XrdPosix.hh:43

References close.

◆ DoIt()

void XrdXrootdPrepare::DoIt ( )
inlinevirtual

Implements XrdJob.

Definition at line 89 of file XrdXrootdPrepare.hh.

89 {Scrub();
90 SchedP->Schedule((XrdJob *)this, scrubtime+time(0));
91 }

References XrdScheduler::Schedule(), and Scrub().

+ Here is the call graph for this function:

◆ List()

int XrdXrootdPrepare::List ( XrdXrootdPrepArgs pargs,
char *  resp,
int  resplen 
)
static

Definition at line 92 of file XrdXrootdPrepare.cc.

93{
94 char *up, path[2048];
95 struct dirent *dp;
96 struct stat buf;
97 int rc;
98
99// If logging is not supported, return eof
100//
101 if (!LogDir) return -1;
102
103// Check if this is the first call
104//
105 if (!pargs.dirP)
106 {if (!(pargs.dirP = opendir((const char *)LogDir)))
107 {eDest->Emsg("List", errno, "open prep log directory", LogDir);
108 return -1;
109 }
110 if (pargs.reqid) pargs.reqlen = strlen(pargs.reqid);
111 if (pargs.user) pargs.usrlen = strlen(pargs.user);
112 }
113
114// Find the next entry that satisfies the search criteria
115//
116 errno = 0;
117 while((dp = readdir(pargs.dirP)))
118 {if (!(up = (char *) index((const char *)dp->d_name, '_'))) continue;
119 if (pargs.reqlen && strncmp(dp->d_name, pargs.reqid, pargs.reqlen))
120 continue;
121 if (pargs.usrlen)
122 if (!up || strcmp((const char *)up+1,(const char *)pargs.user))
123 continue;
124 strcpy(path, (const char *)LogDir);
125 strcpy(path+LogDirLen, (const char *)dp->d_name);
126 if (stat((const char *)path, &buf)) continue;
127 *up = ' ';
128 if ((up = (char *) index((const char *)(up+1), (int)'_'))) *up = ' ';
129 else continue;
130 if ((up = (char *) index((const char *)(up+1), (int)'_'))) *up = ' ';
131 else continue;
132 return snprintf(resp, resplen-1, "%s %lld",
133 dp->d_name, (long long) buf.st_mtime);
134 }
135
136// Completed
137//
138 if ((rc = errno))
139 eDest->Emsg("List", errno, "read prep log directory", LogDir);
140 closedir(pargs.dirP);
141 pargs.dirP = 0;
142 return (rc ? -1 : 0);
143}
static XrdSysError eDest(0,"crypto_")
#define opendir(a)
Definition XrdPosix.hh:73
#define closedir(a)
Definition XrdPosix.hh:45
#define stat(a, b)
Definition XrdPosix.hh:96
#define readdir(a)
Definition XrdPosix.hh:81
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

References closedir, eDest, XrdSysError::Emsg(), opendir, readdir, XrdXrootdPrepArgs::reqid, stat, and XrdXrootdPrepArgs::user.

+ Here is the call graph for this function:

◆ Log()

void XrdXrootdPrepare::Log ( XrdXrootdPrepArgs pargs)
static

Definition at line 149 of file XrdXrootdPrepare.cc.

150{
151 int rc, pnum = 0, xfd;
152 XrdOucTList *tp = pargs.paths;
153 char buff[2048], blink[2048];
154 struct iovec iovec[2];
155
156// If logging not enabled, return
157//
158 if (!LogDir) return;
159
160// Count number of paths in the list
161//
162 while(tp) {pnum++; tp = tp->next;}
163
164// Construct the file name: <reqid>_<user>_<prty>_<numpaths>
165//
166 snprintf(buff, sizeof(buff)-1, "%s%s_%s_%d_%d", LogDir,
167 pargs.reqid, pargs.user, pargs.prty, pnum);
168
169// Create the file
170//
171 if ((xfd = open(buff, O_WRONLY|O_CREAT|O_TRUNC,0644)) < 0)
172 {eDest->Emsg("Log", errno, "open prep log file", buff);
173 return;
174 }
175
176// Write all the paths into the file, separating each by a space
177//
178 iovec[1].iov_base = (char *)" ";
179 iovec[1].iov_len = 1;
180 tp = pargs.paths;
181 while(tp)
182 {if (tp->next == 0) iovec[1].iov_base = (char *)"\n";
183 iovec[0].iov_base = tp->text;
184 iovec[0].iov_len = strlen(tp->text);
185 do {rc = writev(xfd, (const struct iovec *)iovec, 2);}
186 while(rc < 0 && errno == EINTR);
187 if (rc < 0)
188 {eDest->Emsg("Log", errno, "write prep log file", buff);
189 close(xfd);
190 return;
191 }
192 tp = tp->next;
193 }
194
195// Create a symlink to the file
196//
197 close(xfd);
198 strcpy(blink, LogDir);
199 strlcpy(blink+LogDirLen, pargs.reqid, sizeof(blink)-1);
200 if (symlink((const char *)buff, (const char *)blink))
201 {eDest->Emsg("Log", errno, "create symlink to prep log file", buff);
202 return;
203 }
204}
#define open
Definition XrdPosix.hh:71
#define writev(a, b, c)
Definition XrdPosix.hh:112
size_t strlcpy(char *dst, const char *src, size_t sz)
XrdOucTList * next

References close, eDest, XrdSysError::Emsg(), XrdOucTList::next, open, XrdXrootdPrepArgs::paths, XrdXrootdPrepArgs::prty, XrdXrootdPrepArgs::reqid, strlcpy(), XrdOucTList::text, XrdXrootdPrepArgs::user, and writev.

+ Here is the call graph for this function:

◆ Logdel()

void XrdXrootdPrepare::Logdel ( char *  reqid)
static

Definition at line 210 of file XrdXrootdPrepare.cc.

211{
212 int rc;
213 char path[MAXPATHLEN+256], buff[MAXPATHLEN+1];
214
215// If logging not enabled, return
216//
217 if (!LogDir || strlen(reqid) > 255) return;
218
219// Construct the file name of the symlink
220//
221 strcpy(path, (const char *)LogDir);
222 strcpy(&path[LogDirLen], (const char *)reqid);
223
224// Read the symlink contents for this request
225//
226 if ((rc = readlink((const char *)path, buff, sizeof(buff)-1)) < 0)
227 {if (errno != ENOENT) eDest->Emsg("Logdel",errno,"read symlink",path);
228 return;
229 }
230
231// Delete the file, then the symlink
232//
233 buff[rc] = '\0';
234 if (unlink((const char *)buff)
235 && errno != ENOENT) eDest->Emsg("Logdel",errno,"remove",buff);
236 else TRACE(DEBUG, "Logdel removed " <<buff);
237 if (unlink((const char *)path)
238 && errno != ENOENT) eDest->Emsg("Logdel", errno, "remove", path);
239 else TRACE(DEBUG, "Logdel removed " <<path);
240}
#define DEBUG(x)
#define unlink(a)
Definition XrdPosix.hh:108
#define TRACE(act, x)
Definition XrdTrace.hh:63

References DEBUG, eDest, XrdSysError::Emsg(), TRACE, and unlink.

+ Here is the call graph for this function:

◆ Open()

int XrdXrootdPrepare::Open ( const char *  reqid,
int &  fsz 
)
static

Definition at line 246 of file XrdXrootdPrepare.cc.

247{
248 int fd;
249 char path[MAXPATHLEN+264];
250 struct stat buf;
251
252// If logging is not supported, indicate so
253//
254 if (!LogDir) return -ENOTSUP;
255
256// Construct the file name
257//
258 strcpy(path, (const char *)LogDir);
259 strcpy(path+LogDirLen, reqid);
260
261// Get the file size
262//
263 if (stat((const char *)path, &buf)) return -errno;
264 fsz = buf.st_size;
265
266// Open the file and return the file descriptor
267//
268 if ((fd = open((const char *)path, O_RDONLY)) < 0) return -errno;
269 return fd;
270}

References open, and stat.

◆ Scrub()

void XrdXrootdPrepare::Scrub ( )
static

Definition at line 276 of file XrdXrootdPrepare.cc.

277{
278 DIR *prepD;
279 time_t stale = time(0) - scrubkeep;
280 char *up, path[2048], *fn = path+LogDirLen;
281 struct dirent *dp;
282 struct stat buf;
283
284// If logging is not supported, return eof
285//
286 if (!LogDir) return;
287
288// Open the log directory
289//
290 if (!(prepD = opendir((const char *)LogDir)))
291 {eDest->Emsg("Scrub", errno, "open prep log directory", LogDir);
292 return;
293 }
294 strcpy(path, (const char *)LogDir);
295
296// Delete all stale entries
297//
298 errno = 0;
299 while((dp = readdir(prepD)))
300 {if (!(up = (char *) index((const char *)dp->d_name, '_'))) continue;
301 strcpy(fn, (const char *)dp->d_name);
302 if (stat((const char *)path, &buf)) continue;
303 if (buf.st_mtime <= stale)
304 {TRACE(DEBUG, "Scrub removed stale prep log " <<path);
305 unlink((const char *)path);
306 *(fn+(up-dp->d_name)) = '\0';
307 unlink((const char *)path);
308 errno = 0;
309 }
310 }
311
312// All done
313//
314 if (errno)
315 eDest->Emsg("List", errno, "read prep log directory", LogDir);
316 closedir(prepD);
317}

References closedir, DEBUG, eDest, XrdSysError::Emsg(), opendir, readdir, stat, TRACE, and unlink.

Referenced by DoIt().

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

◆ setParms() [1/2]

int XrdXrootdPrepare::setParms ( char *  ldir)
static

Definition at line 329 of file XrdXrootdPrepare.cc.

330{
331 char path[2048];
332 struct stat buf;
333 int plen;
334
335// If parm not supplied, ignore call
336//
337 if (!ldir) return 0;
338
339// Make sure we have appropriate permissions for this directory
340//
341 if (access((const char *)ldir, X_OK | W_OK | R_OK) || stat(ldir, &buf))
342 return -errno;
343 if ((buf.st_mode & S_IFMT) != S_IFDIR) return -ENOTDIR;
344
345// Create the path name
346//
347 if (LogDir) free(LogDir);
348 LogDir = 0;
349 plen = strlen(ldir);
350 strcpy(path, ldir);
351 if (path[plen-1] != '/') path[plen++] = '/';
352 path[plen] = '\0';
353
354// Save the path and return
355//
356 LogDir = strdup(path);
357 LogDirLen = strlen(LogDir);
358 return 0;
359}
#define access(a, b)
Definition XrdPosix.hh:39

References access, and stat.

◆ setParms() [2/2]

int XrdXrootdPrepare::setParms ( int  stime,
int  skeep 
)
static

Definition at line 323 of file XrdXrootdPrepare.cc.

324{if (stime > 0) scrubtime = stime;
325 if (keep > 0) scrubkeep = keep;
326 return 0;
327}

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