XRootD
XrdPfcPrint.cc File Reference
#include <iostream>
#include <fcntl.h>
#include <vector>
#include "XrdPfcPrint.hh"
#include "XrdPfcInfo.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucArgs.hh"
#include "XrdOuc/XrdOucJson.hh"
#include "XrdSys/XrdSysTrace.hh"
#include "XrdOfs/XrdOfsConfigPI.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdOss/XrdOss.hh"
+ Include dependency graph for XrdPfcPrint.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 307 of file XrdPfcPrint.cc.

308 {
309  static const char* usage = "Usage: pfc_print [-h] [-c config_file] [-u B|kB|MB] [-v] [-j] [-i indent] path ...\n";
310  char unit = 'k';
311  bool verbose = false;
312  bool json = false;
313  int indent = -1;
314  const char* cfgn = 0;
315 
316  XrdOucEnv myEnv;
317 
318  XrdSysLogger log;
319  XrdSysError err(&log);
320 
321  XrdOucStream Config(&err, getenv("XRDINSTANCE"), &myEnv, "=====> ");
322  XrdOucArgs Spec(&err, "xrdpfc_print: ", "",
323  "help", 1, "h",
324  "config", 1, "c:",
325  "unit", 1, "u:",
326  "verbose", 1, "v",
327  "json", 1, "j",
328  "indent", 1, "i:",
329  (const char *) 0);
330 
331  Spec.Set(argc-1, &argv[1]);
332  char theOpt;
333 
334  while ((theOpt = Spec.getopt()) != (char)-1)
335  {
336  // printf("GETOPT %c -- arg=%s\n", theOpt, Spec.argval);
337  switch (theOpt)
338  {
339  case 'c': {
340  cfgn = Spec.argval;
341  int fd = open(cfgn, O_RDONLY, 0);
342  Config.Attach(fd);
343  break;
344  }
345  case 'u': {
346  if (strcmp(Spec.argval,"B") && strcmp(Spec.argval,"kB") && strcmp(Spec.argval,"MB")) {
347  printf("%s Error: -unit argument can only be B, kB or MB\n", usage);
348  exit(1);
349  }
350  unit = Spec.argval[0];
351  break;
352  }
353  case 'v': {
354  verbose = true;
355  break;
356  }
357  case 'j': {
358  json = true;
359  break;
360  }
361  case 'i': {
362  indent = std::stoi(Spec.argval);
363  break;
364  }
365  case 'h':
366  default: {
367  printf("%s", usage);
368  exit(1);
369  }
370  }
371  }
372 
373  // suppress oss init messages
374  int efs = open("/dev/null",O_RDWR, 0);
375  XrdSysLogger ossLog(efs);
376  XrdSysError ossErr(&ossLog, "print");
377  XrdOss *oss;
378  XrdOfsConfigPI *ofsCfg = XrdOfsConfigPI::New(cfgn,&Config,&ossErr);
379  bool ossSucc = ofsCfg->Load(XrdOfsConfigPI::theOssLib);
380  if ( ! ossSucc)
381  {
382  printf("can't load oss\n");
383  exit(1);
384  }
385  ofsCfg->Plugin(oss);
386 
387  const char* path;
388  while ((path = Spec.getarg()))
389  {
390  if ( ! path)
391  {
392  printf("%s", usage);
393  exit(1);
394  }
395 
396  // append oss.localroot if path starts with 'root://'
397  if ( ! strncmp(&path[0], "root:/", 6))
398  {
399  if (Config.FDNum() < 0)
400  {
401  printf("Configuration file not specified.\n");
402  exit(1);
403  }
404  char *var;
405  while((var = Config.GetFirstWord()))
406  {
407  // printf("var %s \n", var);
408  if ( ! strncmp(var,"oss.localroot", strlen("oss.localroot")))
409  {
410  std::string tmp = Config.GetWord();
411  tmp += &path[6];
412  // printf("Absolute path %s \n", tmp.c_str());
413  XrdPfc::Print p(oss, unit, verbose, json, indent, tmp.c_str());
414  }
415  }
416  }
417  else
418  {
419  XrdPfc::Print p(oss, unit, verbose, json, indent, path);
420  }
421  }
422 
423  return 0;
424 }
void usage()
nlohmann::json json
int open(const char *path, int oflag,...)
bool Plugin(XrdAccAuthorize *&piP)
Get Authorization plugin.
static XrdOfsConfigPI * New(const char *cfn, XrdOucStream *cfgP, XrdSysError *errP, XrdVersionInfo *verP=0, XrdSfsFileSystem *sfsP=0)
bool Load(int what, XrdOucEnv *envP=0)
@ theOssLib
Oss plugin.
XrdCmsConfig Config

References XrdOucArgs::argval, XrdCms::Config, XrdOucArgs::getarg(), XrdOucArgs::getopt(), XrdOfsConfigPI::Load(), XrdOfsConfigPI::New(), open(), XrdOfsConfigPI::Plugin(), XrdOucArgs::Set(), XrdOfsConfigPI::theOssLib, and usage().

+ Here is the call graph for this function: