29 #include "core/version.hpp" 37 #include <boost/filesystem.hpp> 38 #include <boost/program_options/options_description.hpp> 39 #include <boost/program_options/variables_map.hpp> 40 #include <boost/program_options/parsers.hpp> 44 #include <boost/thread.hpp> 47 #include <condition_variable> 68 : m_nfd(configFile, m_nfdKeyChain)
69 , m_configFile(configFile)
73 m_terminationSignalSet.add(SIGINT);
74 m_terminationSignalSet.add(SIGTERM);
77 m_reloadSignalSet.add(SIGHUP);
82 printUsage(std::ostream& os,
const std::string& programName)
85 <<
" " << programName <<
" [options]\n" 87 <<
"Run NFD forwarding daemon\n" 90 <<
" [--help] - print this help message\n" 91 <<
" [--version] - print version and exit\n" 92 <<
" [--modules] - list available logging modules\n" 93 <<
" [--config /path/to/nfd.conf] - path to configuration file " 94 <<
"(default: " << DEFAULT_CONFIG_FILE <<
")\n" 101 os <<
"Available logging modules: \n";
103 for (
const auto& module : LoggerFactory::getInstance().getModules()) {
104 os << module <<
"\n";
121 std::atomic_int retval(0);
124 boost::asio::io_service* ribIo =
nullptr;
131 std::condition_variable cv;
133 std::string configFile = this->m_configFile;
134 boost::thread ribThread([configFile, &retval, &ribIo, mainIo, &cv, &m] {
136 std::lock_guard<std::mutex> lock(m);
138 BOOST_ASSERT(ribIo != mainIo);
149 catch (
const std::exception& e) {
156 std::lock_guard<std::mutex> lock(m);
164 std::unique_lock<std::mutex> lock(m);
165 cv.wait(lock, [&ribIo] {
return ribIo !=
nullptr; });
171 catch (
const std::exception& e) {
182 std::lock_guard<std::mutex> lock(m);
183 if (ribIo !=
nullptr) {
194 terminate(
const boost::system::error_code& error,
int signalNo)
199 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', exiting...");
204 reload(
const boost::system::error_code& error,
int signalNo)
209 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', reloading...");
218 std::string m_configFile;
220 boost::asio::signal_set m_terminationSignalSet;
221 boost::asio::signal_set m_reloadSignalSet;
231 namespace po = boost::program_options;
233 po::options_description description;
235 std::string configFile = DEFAULT_CONFIG_FILE;
236 description.add_options()
237 (
"help,h",
"print this help message")
238 (
"version,V",
"print version and exit")
239 (
"modules,m",
"list available logging modules")
240 (
"config,c", po::value<std::string>(&configFile),
"path to configuration file")
243 po::variables_map vm;
245 po::store(po::command_line_parser(argc, argv).options(description).
run(), vm);
248 catch (
const std::exception& e) {
251 std::cerr <<
"ERROR: " << e.what() << std::endl;
256 if (vm.count(
"help") > 0) {
261 if (vm.count(
"version") > 0) {
262 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
266 if (vm.count(
"modules") > 0) {
276 catch (
const boost::filesystem::filesystem_error& e) {
277 if (e.code() == boost::system::errc::permission_denied) {
278 NFD_LOG_FATAL(
"Permissions denied for " << e.path1() <<
". " <<
279 argv[0] <<
" should be run as superuser");
287 catch (
const std::exception& e) {
static void printUsage(std::ostream &os, const std::string &programName)
std::string getExtendedErrorMessage(const E &exception)
initializes and executes NFD-RIB service thread
represents a serious seteuid/gid failure
int main(int argc, char **argv)
static void printModules(std::ostream &os)
detail::SimulatorIo & getGlobalIoService()
void initialize()
Perform initialization of NFD-RIB instance.
NfdRunner(const std::string &configFile)
#define NFD_LOG_INFO(expression)
void reload(const boost::system::error_code &error, int signalNo)
#define NFD_LOG_FATAL(expression)
void reloadConfigFile()
Reload configuration file and apply update (if any)
Class representing NFD instance This class can be used to initialize all components of NFD...
Copyright (c) 2011-2015 Regents of the University of California.
void initialize()
Perform initialization of NFD instance After initialization, NFD instance can be started by invoking ...
Executes NFD with RIB manager.
#define NFD_LOG_INIT(name)
const char * what() const
void terminate(const boost::system::error_code &error, int signalNo)