Skip to content
sld.cc 1.25 KiB
Newer Older
Seblu's avatar
Seblu committed

#include <signal.h>
Seblu's avatar
Seblu committed
#include <unistd.h>
#include <string>
Seblu's avatar
Seblu committed
#include "sld.hh"

Seblu's avatar
Seblu committed
string binpath;

Seblu's avatar
Seblu committed
int main(int argc, char *argv[])
{
  SLDaemon &daemon = SLDaemon::Instance();
  SLDaemon::Options *lineopt;
  SLDaemon::Options *fileopt = NULL;
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
  try {
    //parse arg line options
    lineopt = daemon.getoptions(argc, argv);
Seblu's avatar
Seblu committed
    assert(lineopt);
    if (lineopt->conffile != "") {
      //parse conf file options
      fileopt = daemon.getoptions(lineopt->conffile);
    }
  }
  catch (const Error &e) {
    e.print();
    return e.code();
  }
  try {
    //apply config file option
    if (fileopt)
      daemon.applyoptions(fileopt);
Seblu's avatar
Seblu committed

Seblu's avatar
Seblu committed
    //apply parsed option
    daemon.applyoptions(lineopt);
Seblu's avatar
Seblu committed

    // register sigchild handler
    if (signal(SIGCHLD, sigchild) == SIG_ERR) {
      perror("sld: error");
      return ERR_UNKNOWN;
    }

Seblu's avatar
Seblu committed
    //execute receive command
    daemon.run();
  }
  catch (const Error &e) {
    std::cerr <<"sld: error: " << e.message() << std::endl;
    return e.code();
  }
Seblu's avatar
Seblu committed
  return ERR_UNKNOWN;
Seblu's avatar
Seblu committed
}
Seblu's avatar
Seblu committed

string getbinpath(const char *argv0) {
  // check if is absolute pathname
  if (*argv0 == '/')
    return string(argv0);

  //contatence current dir with argv0
  char buf[PATH_MAX];
  getcwd(buf, PATH_MAX);
  return (string) buf + "/" + argv0;
}