GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/receiver/receiver.cc Lines: 0 50 0.0 %
Date: 2019-02-03 02:48:13 Branches: 0 30 0.0 %

Line Branch Exec Source
1
/**
2
 * This file is part of the CernVM File System.
3
 */
4
5
#include <string>
6
7
#include "cvmfs_config.h"
8
9
#include "../logging.h"
10
#include "../swissknife.h"
11
12
#include "reactor.h"
13
14
swissknife::ParameterList MakeParameterList() {
15
  swissknife::ParameterList params;
16
  params.push_back(
17
      swissknife::Parameter::Optional('i', "File descriptor to use for input"));
18
  params.push_back(swissknife::Parameter::Optional(
19
      'o', "File descriptor to use for output"));
20
  return params;
21
}
22
23
bool ReadCmdLineArguments(int argc, char** argv,
24
                          const swissknife::ParameterList& params,
25
                          swissknife::ArgumentList* arguments) {
26
  // parse the command line arguments for the Command
27
  optind = 1;
28
  std::string option_string = "";
29
30
  for (unsigned j = 0; j < params.size(); ++j) {
31
    option_string.push_back(params[j].key());
32
    if (!params[j].switch_only()) option_string.push_back(':');
33
  }
34
35
  int c;
36
  while ((c = getopt(argc, argv, option_string.c_str())) != -1) {
37
    bool valid_option = false;
38
    for (unsigned j = 0; j < params.size(); ++j) {
39
      if (c == params[j].key()) {
40
        valid_option = true;
41
        (*arguments)[c].Reset();
42
        if (!params[j].switch_only()) {
43
          (*arguments)[c].Reset(new std::string(optarg));
44
        }
45
        break;
46
      }
47
    }
48
49
    if (!valid_option) {
50
      LogCvmfs(kLogReceiver, kLogSyslog,
51
               "CVMFS gateway services receiver component. Usage:");
52
      for (size_t i = 0; i < params.size(); ++i) {
53
        LogCvmfs(kLogReceiver, kLogSyslog, "  \"%c\" - %s", params[i].key(),
54
                 params[i].description().c_str());
55
      }
56
      return false;
57
    }
58
  }
59
60
  for (size_t j = 0; j < params.size(); ++j) {
61
    if (!params[j].optional()) {
62
      if (arguments->find(params[j].key()) == arguments->end()) {
63
        LogCvmfs(kLogReceiver, kLogSyslogErr, "parameter -%c missing",
64
                 params[j].key());
65
        return false;
66
      }
67
    }
68
  }
69
70
  return true;
71
}
72
73
int main(int argc, char** argv) {
74
  swissknife::ArgumentList arguments;
75
  if (!ReadCmdLineArguments(argc, argv, MakeParameterList(), &arguments)) {
76
    return 1;
77
  }
78
79
  SetLogSyslogFacility(1);
80
  SetLogSyslogShowPID(true);
81
82
  int fdin = 0;
83
  int fdout = 1;
84
  if (arguments.find('i') != arguments.end()) {
85
    fdin = std::atoi(arguments.find('i')->second->c_str());
86
  }
87
  if (arguments.find('o') != arguments.end()) {
88
    fdout = std::atoi(arguments.find('o')->second->c_str());
89
  }
90
91
  LogCvmfs(kLogReceiver, kLogSyslog, "CVMFS receiver started");
92
93
  receiver::Reactor reactor(fdin, fdout);
94
95
  if (!reactor.Run()) {
96
    LogCvmfs(kLogReceiver, kLogSyslogErr,
97
             "Error running CVMFS Receiver event loop");
98
    return 1;
99
  }
100
101
  LogCvmfs(kLogReceiver, kLogSyslog, "CVMFS receiver finished");
102
103
  return 0;
104
}