Commit af5c3aa8 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Merge branch '14-urd-aborts-if-unrecognized-options-are-passed-in-command-line' into 'master'

Resolve "Urd aborts if unrecognized options are passed in command line"

Closes #14 and #9

See merge request !6
parents 6d3ff22b c59a956f
Loading
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -218,6 +218,7 @@ config/defaults.cpp: Makefile
	   echo "    const char* progname             = \"urd\";"; \
	   echo "    const bool daemonize             = true;"; \
	   echo "    const bool use_syslog            = false;"; \
	   echo "    const bool use_console           = false;"; \
	   echo "    const bfs::path log_file         = boost::filesystem::path();"; \
	   echo "    const uint32_t log_file_max_size = static_cast<uint32_t>(16*1024*1024);"; \
	   echo ""; \
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#ifndef __NORNS_CONFIG_HPP__
#define __NORNS_CONFIG_HPP__

#include "config.h"
#include "config/defaults.hpp"
#include "config/settings.hpp"

+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ namespace defaults {
    extern const char*      progname;
    extern const bool       daemonize;
    extern const bool       use_syslog;
    extern const bool       use_console;
    extern const bfs::path  log_file;
    extern const uint32_t   log_file_max_size;
    extern const bool       dry_run;
+23 −6
Original line number Diff line number Diff line
@@ -45,17 +45,27 @@ namespace norns {
namespace config {

settings::settings() { }
settings::settings(const std::string& progname, bool daemonize, bool use_syslog,
                   const bfs::path& log_file, const uint32_t log_file_max_size,
                   bool dry_run, uint32_t dry_run_duration, 

settings::settings(const std::string& progname, 
                   bool daemonize, 
                   bool use_syslog,
                   bool use_console,
                   const bfs::path& log_file, 
                   const uint32_t log_file_max_size,
                   bool dry_run, 
                   uint32_t dry_run_duration, 
                   const bfs::path& global_socket, 
                   const bfs::path& control_socket, uint32_t remote_port,
                   const bfs::path& pidfile, uint32_t workers, 
                   uint32_t backlog_size, const bfs::path& cfgfile, 
                   const bfs::path& control_socket, 
                   uint32_t remote_port,
                   const bfs::path& pidfile, 
                   uint32_t workers,
                   uint32_t backlog_size, 
                   const bfs::path& cfgfile, 
                   const std::list<namespace_def>& defns) :
    m_progname(progname),
    m_daemonize(daemonize),
    m_use_syslog(use_syslog),
    m_use_console(use_console),
    m_log_file(log_file),
    m_log_file_max_size(log_file_max_size),
    m_dry_run(dry_run),
@@ -73,6 +83,7 @@ void settings::load_defaults() {
    m_progname = defaults::progname;
    m_daemonize = defaults::daemonize;
    m_use_syslog = defaults::use_syslog;
    m_use_console = defaults::use_console;
    m_log_file = defaults::log_file;
    m_log_file_max_size = defaults::log_file_max_size;
    m_dry_run = defaults::dry_run;
@@ -98,6 +109,7 @@ void settings::load_from_file(const bfs::path& filename) {

    m_progname = defaults::progname;
    m_use_syslog = gsettings.get_as<bool>(keywords::use_syslog);
    m_use_console = defaults::use_console;

    if(gsettings.has(keywords::log_file)) {
        m_log_file = gsettings.get_as<bfs::path>(keywords::log_file);
@@ -137,6 +149,7 @@ std::string settings::to_string() const {
           "  m_progname: "          + m_progname + ",\n" +
           "  m_daemonize: "         + (m_daemonize ? "true" : "false") + ",\n" +
           "  m_use_syslog: "        + (m_use_syslog ? "true" : "false") +  ",\n" +
           "  m_use_console: "       + (m_use_console ? "true" : "false") +  ",\n" +
           "  m_log_file: "          + m_log_file.string() + ",\n" +
           "  m_log_file_max_size: " + std::to_string(m_log_file_max_size) + ",\n" +
           "  m_dry_run: "           + (m_dry_run ? "true" : "false") +  ",\n" +
@@ -165,6 +178,10 @@ bool& settings::use_syslog() {
    return m_use_syslog;
}

bool& settings::use_console() {
    return m_use_console;
}

bfs::path& settings::log_file() {
    return m_log_file;
}
+23 −10
Original line number Diff line number Diff line
@@ -39,9 +39,12 @@ namespace config {

struct namespace_def {

    namespace_def(const std::string& nsid, bool track, 
                  const bfs::path& mountpoint, const std::string& alias, 
                  const uint64_t capacity, const std::string& visibility) :
    namespace_def(const std::string& nsid,
                  bool track,
                  const bfs::path& mountpoint,
                  const std::string& alias,
                  const uint64_t capacity,
                  const std::string& visibility) :
        m_nsid(nsid),
        m_track(track),
        m_mountpoint(mountpoint),
@@ -84,13 +87,21 @@ struct namespace_def {
struct settings {

    settings();
    settings(const std::string& progname, bool daemonize, bool use_syslog,
             const bfs::path& log_file, const uint32_t log_file_max_size,
             bool dry_run, uint32_t dry_run_duration,
    settings(const std::string& progname,
             bool daemonize,
             bool use_syslog,
             bool use_console,
             const bfs::path& log_file,
             const uint32_t log_file_max_size,
             bool dry_run,
             uint32_t dry_run_duration,
             const bfs::path& global_socket,
             const bfs::path& control_socket, uint32_t remote_port,
             const bfs::path& pidfile, uint32_t workers, 
             uint32_t backlog_size, const bfs::path& cfgfile, 
             const bfs::path& control_socket,
             uint32_t remote_port,
             const bfs::path& pidfile,
             uint32_t workers,
             uint32_t backlog_size,
             const bfs::path& cfgfile,
             const std::list<namespace_def>& defns);
    void load_defaults();
    void load_from_file(const bfs::path& filename);
@@ -99,6 +110,7 @@ struct settings {
    std::string& progname();
    bool& daemonize();
    bool& use_syslog();
    bool& use_console();
    bfs::path& log_file();
    uint32_t& log_file_max_size();
    bool& dry_run();
@@ -115,6 +127,7 @@ struct settings {
    std::string m_progname = defaults::progname;
    bool        m_daemonize = defaults::daemonize;
    bool        m_use_syslog = defaults::use_syslog;
    bool        m_use_console = defaults::use_console;
    bfs::path   m_log_file = defaults::log_file;
    uint32_t    m_log_file_max_size = defaults::log_file_max_size;
    bool        m_dry_run = defaults::dry_run;
Loading