Commit e15f75d1 authored by Seblu's avatar Seblu
Browse files

Add daemon code

Add log file printing
parent 0119af1d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -47,7 +47,10 @@ void Database::open(const string &path) {
  load_users_();
  load_scripts_();
  load_aliases_();
}

bool Database::opened() const {
  return !!db_;
}

void Database::close() {
+56 −1
Original line number Diff line number Diff line
@@ -19,16 +19,71 @@
#ifndef DATABASE_HH
# define DATABASE_HH

# include <list>
# include <sqlite3.h>
# include "sls.hh"

// Data container
// -----------------------------------------------------------------------------
// Classes
// -----------------------------------------------------------------------------

// Host

struct Host {
  string login;
  string pass;
  string ipv4;
  int level;
};

typedef std::list<Host> Hosts;

// Group

struct Group {
  string name;
  Hosts hosts;
};

typedef std::list<Group> Groups;

// User
struct User {
  string login;
  string pass;
  int level;
  bool priv;
};

typedef std::list<User> Users;

// Script

struct Script {
  string name;
  string path;
  int level;
};

typedef std::list<Script> Scripts;

// Alias

struct Alias {
  string name;
  string val;
};

typedef std::list<Alias> Aliases;


// Data container
class Database {
public:
  Database();

  void open(const string &path);
  bool opened() const;
  void close();

protected:
+12 −6
Original line number Diff line number Diff line
@@ -29,9 +29,10 @@ Option::Option() {
  verbose = false;
  database = "/var/db/sls.db";
  port = 18136;
  maxthread = 200;
  daemon = true;
  closefd = true;
  logfile = "/var/log/syslog/sls";
  logfile = "/var/log/sls";
  pidfile = "/var/lock/sls.pid";
}

@@ -42,12 +43,13 @@ void Option::usage(const char *name, ostream &out) const {
  out << "usage: " << name
      << " [-h|--help] [-d|--database file] [-v|--verbose] [-p port]" << std::endl
      << "-h | --help           : Print this help." << std::endl
      << "-d | --database dir   : Define database directory." << std::endl
      << "-d | --database file  : Define database (def: /var/db/sls.db)." << std::endl
      << "-v | --verbose        : Set verbose mode." << std::endl
      << "-V | --version        : Print version and exit." << std::endl
      << "-p | --port p         : sls listen on port p." << std::endl
      << "-P | --pid-file       : Path to pid file." << std::endl
      << "-l | --log-file       : Path to log file." << std::endl
      << "-p | --port p         : sls listen on port p (def: 18136)." << std::endl
      << "-t | --max-thread p   : Maximun number of thread (def: 200)." << std::endl
      << "-P | --pid-file       : Path to pid file (def: /var/lock/sls.pid)." << std::endl
      << "-l | --log-file       : Path to log file (def: /var/log/sls)." << std::endl
      << "-D | --debug          : Run with verbose and not in daemon mode." << std::endl
      << "-n | --no-close       : Don't close stdin,stdout and stderr." << std::endl;
}
@@ -67,6 +69,7 @@ Option &Option::load(int argc, char *argv[]) {
    {"verbose", 0, 0, 'v'},
    {"version", 0, 0, 'V'},
    {"port", 0, 0, 'p'},
    {"max-thread", 0, 0, 't'},
    {"pid-file", 0, 0, 'P'},
    {"log-file", 0, 0, 'l'},
    {"debug", 0, 0, 'D'},
@@ -75,7 +78,7 @@ Option &Option::load(int argc, char *argv[]) {
  };
  int option;

  while ((option = getopt_long(argc, argv, "hvnVDd:p:P:l:", lopt, 0)) != -1) {
  while ((option = getopt_long(argc, argv, "hvnVDd:p:P:l:t:", lopt, 0)) != -1) {
    switch (option) {
    case 'h':
      usage(*argv, std::cout);
@@ -83,6 +86,9 @@ Option &Option::load(int argc, char *argv[]) {
    case 'p':
      port = atoi(optarg);
      break;
    case 't':
      maxthread = atoi(optarg);
      break;
    case 'd':
      database = optarg;
      break;
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ struct Option {

  // socket option
  int port;
  size_t maxthread;

  // daemon options
  bool daemon;
+33 −0
Original line number Diff line number Diff line
@@ -18,3 +18,36 @@

#include "sls.hh"
#include "server.hh"

/*!
 * Constructor
 */
Server::Server() : socket_(0) {}

/*!
 * Start server. Creating socket
 */
void Server::start() {

}

/*!
 * @return if server is started or not
 */
bool Server::started() const {
  return socket_ != 0;
}

/*!
 * Start server. Destroy socket
 */
void Server::stop() {

}

/*!
 * Server listen routine. This create new thead.
 */
void Server::listen(size_t max_thread) {
  assert(max_thread > 0);
}
Loading