Commit 599e087c authored by Seblu's avatar Seblu
Browse files

Ajout d'options par defaut

Ajout d'une option retry delay
parent 3361d522
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -22,7 +22,15 @@
SLDaemon *SLDaemon::instance_ = 0;

SLDaemon::SLDaemon() : socket_fs_(0) {
  char buf[128];

// set default options
  if (gethostname(buf, 128) == 0) {
    options_.login = buf;
  }
  options_.port = 18136;
  options_.conffile = "/etc/sldrc";
  options_.retrydelay = 60;
}

SLDaemon &SLDaemon::Instance() {
@@ -35,16 +43,17 @@ void SLDaemon::usage(const char *argv0) const {
  std::cerr << "usage: "
	    << argv0
	    << " [-f conffile] [-d scriptdir] [-h] [-v] [-l login]"
	    << "[-p pass] [-H host] [-P port] [-V]"
	    << "[-p pass] [-H host] [-P port] [-r] [-V]"
	    << std::endl
	    << "  -f conffile  : read and load conf file (def: /etc/sldrc)." << std::endl
	    << "  -d scriptdir : Scripts directory." << std::endl
	    << "  -h           : Print this usage." << std::endl
	    << "  -v           : Verbose mode." << std::endl
	    << "  -l host      : Set login to host." << std::endl
	    << "  -l host      : Set login to host. (def: check hostname)" << std::endl
	    << "  -p secret    : Set pass to secret." << std::endl
	    << "  -H name      : Set server host to name." << std::endl
	    << "  -P number    : Set server port to number." << std::endl
	    << "  -P number    : Set server port to number. (def: 18136)" << std::endl
	    << "  -r val       : Set retry delay to val in seconds (def: 60)" << std::endl
	    << "  -V           : Print version and exit." << std::endl;
}

@@ -146,24 +155,16 @@ SLDaemon::Options *SLDaemon::getoptions(const string file) const {
void SLDaemon::applyoptions(const Options *opt) {
  assert(opt);
  if (opt->server != "") options_.server = opt->server;
  if (opt->port != 0) options_.port = opt->port;
  if (opt->port >= 0) options_.port = opt->port;
  if (opt->login != "") options_.login = opt->login;
  if (opt->pass != "") options_.pass = opt->pass;
  if (opt->verbose != 3) options_.verbose = opt->verbose;
  if (opt->verbose >= 0) options_.verbose = opt->verbose;
  if (opt->conffile != "") options_.conffile = opt->conffile;
  if (opt->scriptdir != "") options_.scriptdir = opt->scriptdir;
  if (opt->retrydelay >= 0) options_.retrydelay = opt->retrydelay;
}

void SLDaemon::check_options() const {
  // print info in verbose mode
  if (verbose()) {
    std::cout << "Server host is : " << options_.server << "." << std::endl;
    std::cout << "Server port is : " << options_.port << "." << std::endl;
    std::cout << "Daemon login is : " << options_.login << "." << std::endl;
    std::cout << "Daemon pass is : " << options_.pass << "." << std::endl;
    std::cout << "Daemon scripts directory is : " << options_.scriptdir << "." << std::endl;
    std::cout << "Verbose mode : " << verbose() << "." << std::endl;
  }

  // Check validy of arguement
  if (options_.server == "")
@@ -186,6 +187,8 @@ void SLDaemon::check_options() const {
void SLDaemon::run() {
  char *line;

  if (verbose())
    options_.print();
  check_options();
  clean_dir(options_.scriptdir);
  connect();
@@ -758,8 +761,9 @@ void SLDaemon::clean_dir(const string &dir) const {
//******************************************************************************

SLDaemon::Options::Options() {
  this->port = 0;
  this->verbose = 3;
  port = -1;
  verbose = -1;
  retrydelay = -1;
}

void SLDaemon::Options::print() {
@@ -769,6 +773,7 @@ void SLDaemon::Options::print() {
  std::cout << "host pass: " << pass << std::endl;
  std::cout << "script directory: " << scriptdir << std::endl;
  std::cout << "configuration file: " << conffile << std::endl;
  std::cout << "retry delay: " << retrydelay << std::endl;
  std::cout << "verbose level: " << verbose << std::endl;
}

+3 −2
Original line number Diff line number Diff line
@@ -22,12 +22,13 @@ public:
    Options();
    void print();
    string server;
    int port;
    int port; //-1 undef
    string login;
    string pass;
    int verbose; //0=false, 1=true, 3=undef
    int verbose; //0=false, 1=true, -1=undef
    string scriptdir;
    string conffile;
    int retrydelay; //-1 undef
  };

  struct Job {