32 #include "core/logger-factory.hpp" 34 #include "core/version.hpp" 38 #include <boost/filesystem.hpp> 39 #include <boost/program_options/options_description.hpp> 40 #include <boost/program_options/parsers.hpp> 41 #include <boost/program_options/variables_map.hpp> 45 #include <boost/thread.hpp> 48 #include <condition_variable> 51 namespace po = boost::program_options;
71 : m_nfd(configFile, m_nfdKeyChain)
72 , m_configFile(configFile)
76 m_terminationSignalSet.add(SIGINT);
77 m_terminationSignalSet.add(SIGTERM);
80 m_reloadSignalSet.add(SIGHUP);
95 std::atomic_int retval(0);
98 boost::asio::io_service* ribIo =
nullptr;
105 std::condition_variable cv;
107 std::string configFile = this->m_configFile;
108 boost::thread ribThread([configFile, &retval, &ribIo, mainIo, &cv, &m] {
110 std::lock_guard<std::mutex> lock(m);
112 BOOST_ASSERT(ribIo != mainIo);
123 catch (
const std::exception& e) {
130 std::lock_guard<std::mutex> lock(m);
138 std::unique_lock<std::mutex> lock(m);
139 cv.wait(lock, [&ribIo] {
return ribIo !=
nullptr; });
145 catch (
const std::exception& e) {
156 std::lock_guard<std::mutex> lock(m);
157 if (ribIo !=
nullptr) {
168 terminate(
const boost::system::error_code& error,
int signalNo)
173 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', exiting...");
178 reload(
const boost::system::error_code& error,
int signalNo)
183 NFD_LOG_INFO(
"Caught signal '" << ::strsignal(signalNo) <<
"', reloading...");
192 std::string m_configFile;
194 boost::asio::signal_set m_terminationSignalSet;
195 boost::asio::signal_set m_reloadSignalSet;
200 const po::options_description& opts)
202 os <<
"Usage: " << programName <<
" [options]\n" 203 <<
"Run the NDN Forwarding Daemon (NFD)\n" 211 const auto& factory = LoggerFactory::getInstance();
212 for (
const auto& module : factory.getModules()) {
213 os << module <<
"\n";
224 std::string configFile = DEFAULT_CONFIG_FILE;
226 po::options_description description(
"Options");
227 description.add_options()
228 (
"help,h",
"print this message and exit")
229 (
"version,V",
"show version information and exit")
230 (
"config,c", po::value<std::string>(&configFile),
231 "path to configuration file (default: " DEFAULT_CONFIG_FILE
")")
232 (
"modules,m",
"list available logging modules")
235 po::variables_map vm;
237 po::store(po::parse_command_line(argc, argv, description), vm);
240 catch (
const std::exception& e) {
243 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
248 if (vm.count(
"help") > 0) {
253 if (vm.count(
"version") > 0) {
254 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
258 if (vm.count(
"modules") > 0) {
263 NFD_LOG_INFO(
"Version " NFD_VERSION_BUILD_STRING
" starting");
269 catch (
const boost::filesystem::filesystem_error& e) {
270 if (e.code() == boost::system::errc::permission_denied) {
272 ". This program should be run as superuser");
280 catch (
const std::exception& e) {
std::string getExtendedErrorMessage(const E &exception)
static void printLogModules(std::ostream &os)
The interface of signing key management.
initializes and executes NFD-RIB service thread
represents a serious seteuid/gid failure
int main(int argc, char **argv)
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.
static void printUsage(std::ostream &os, const char *programName, const po::options_description &opts)
const char * what() const
#define NFD_LOG_INIT(name)
void terminate(const boost::system::error_code &error, int signalNo)