29 #include "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> 67 : m_nfd(configFile, m_nfdKeyChain)
68 , m_configFile(configFile)
72 m_terminationSignalSet.add(SIGINT);
73 m_terminationSignalSet.add(SIGTERM);
76 m_reloadSignalSet.add(SIGHUP);
81 printUsage(std::ostream& os,
const std::string& programName)
84 <<
" " << programName <<
" [options]\n" 86 <<
"Run NFD forwarding daemon\n" 89 <<
" [--help] - print this help message\n" 90 <<
" [--version] - print version and exit\n" 91 <<
" [--modules] - list available logging modules\n" 92 <<
" [--config /path/to/nfd.conf] - path to configuration file " 93 <<
"(default: " << DEFAULT_CONFIG_FILE <<
")\n" 100 os <<
"Available logging modules: \n";
102 for (
const auto& module : LoggerFactory::getInstance().getModules()) {
103 os << module <<
"\n";
120 std::atomic_int retval(0);
123 boost::asio::io_service* nrdIo =
nullptr;
130 std::condition_variable cv;
132 std::string configFile = this->m_configFile;
133 boost::thread nrdThread([configFile, &retval, &nrdIo, mainIo, &cv, &m] {
135 std::lock_guard<std::mutex> lock(m);
137 BOOST_ASSERT(nrdIo != mainIo);
144 rib::Nrd nrd(configFile, nrdKeyChain);
148 catch (
const std::exception& e) {
155 std::lock_guard<std::mutex> lock(m);
163 std::unique_lock<std::mutex> lock(m);
164 cv.wait(lock, [&nrdIo] {
return nrdIo !=
nullptr; });
170 catch (
const std::exception& e) {
181 std::lock_guard<std::mutex> lock(m);
182 if (nrdIo !=
nullptr) {
193 terminate(
const boost::system::error_code& error,
int signalNo)
198 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', exiting...");
203 reload(
const boost::system::error_code& error,
int signalNo)
208 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', reloading...");
217 std::string m_configFile;
219 boost::asio::signal_set m_terminationSignalSet;
220 boost::asio::signal_set m_reloadSignalSet;
230 namespace po = boost::program_options;
232 po::options_description description;
234 std::string configFile = DEFAULT_CONFIG_FILE;
235 description.add_options()
236 (
"help,h",
"print this help message")
237 (
"version,V",
"print version and exit")
238 (
"modules,m",
"list available logging modules")
239 (
"config,c", po::value<std::string>(&configFile),
"path to configuration file")
242 po::variables_map vm;
244 po::store(po::command_line_parser(argc, argv).options(description).
run(), vm);
247 catch (
const std::exception& e) {
250 std::cerr <<
"ERROR: " << e.what() << std::endl;
255 if (vm.count(
"help") > 0) {
260 if (vm.count(
"version") > 0) {
261 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
265 if (vm.count(
"modules") > 0) {
275 catch (
const boost::filesystem::filesystem_error& e) {
276 if (e.code() == boost::system::errc::permission_denied) {
277 NFD_LOG_FATAL(
"Permissions denied for " << e.path1() <<
". " <<
278 argv[0] <<
" should be run as superuser");
286 catch (
const std::exception& e) {
static void printUsage(std::ostream &os, const std::string &programName)
std::string getExtendedErrorMessage(const E &exception)
represents a serious seteuid/gid failure
int main(int argc, char **argv)
static void printModules(std::ostream &os)
The packet signing interface.
detail::SimulatorIo & getGlobalIoService()
NfdRunner(const std::string &configFile)
Class representing NRD (NFD RIB Manager) instance This class can be used to initialize all components...
void reload(const boost::system::error_code &error, int signalNo)
#define NFD_LOG_INFO(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 ...
#define NFD_LOG_INIT(name)
Executes NFD with RIB manager.
void initialize()
Perform initialization of NFD instance After initialization, NFD instance can be started by invoking ...
const char * what() const
#define NFD_LOG_FATAL(expression)
void terminate(const boost::system::error_code &error, int signalNo)