Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology |
| 9 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 24 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 25 | #include <getopt.h> |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 26 | #include <boost/filesystem.hpp> |
| 27 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 28 | #include "version.hpp" |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 29 | #include "core/logger.hpp" |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 30 | #include "core/global-io.hpp" |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 31 | #include "core/privilege-helper.hpp" |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 32 | #include "fw/forwarder.hpp" |
| 33 | #include "mgmt/internal-face.hpp" |
Steve DiBenedetto | 214563c | 2014-02-03 19:20:36 -0700 | [diff] [blame] | 34 | #include "mgmt/fib-manager.hpp" |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 35 | #include "mgmt/face-manager.hpp" |
Steve DiBenedetto | 5330e0d | 2014-03-05 21:52:51 -0700 | [diff] [blame] | 36 | #include "mgmt/strategy-choice-manager.hpp" |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 37 | #include "mgmt/status-server.hpp" |
Alexander Afanasyev | 613e2a9 | 2014-04-15 13:36:58 -0700 | [diff] [blame] | 38 | #include "core/config-file.hpp" |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 39 | #include "mgmt/general-config-section.hpp" |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 40 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 41 | namespace nfd { |
| 42 | |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 43 | NFD_LOG_INIT("NFD"); |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 44 | |
| 45 | struct ProgramOptions |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 46 | { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 47 | bool showUsage; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 48 | bool showVersion; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 49 | bool showModules; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 50 | std::string config; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 53 | class Nfd : noncopyable |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 54 | { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 55 | public: |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 56 | |
| 57 | void |
| 58 | initialize(const std::string& configFile) |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 59 | { |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 60 | initializeLogging(configFile); |
| 61 | |
| 62 | m_forwarder = make_shared<Forwarder>(); |
| 63 | |
| 64 | initializeManagement(configFile); |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 65 | |
| 66 | PrivilegeHelper::drop(); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | void |
| 71 | initializeLogging(const std::string& configFile) |
| 72 | { |
Steve DiBenedetto | 34c95f7 | 2014-04-17 20:56:00 -0600 | [diff] [blame] | 73 | ConfigFile config(&ConfigFile::ignoreUnknownSection); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 74 | LoggerFactory::getInstance().setConfigFile(config); |
| 75 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 76 | config.parse(configFile, true); |
| 77 | config.parse(configFile, false); |
| 78 | } |
| 79 | |
Steve DiBenedetto | 34c95f7 | 2014-04-17 20:56:00 -0600 | [diff] [blame] | 80 | class IgnoreRibAndLogSections |
| 81 | { |
| 82 | public: |
| 83 | void |
| 84 | operator()(const std::string& filename, |
| 85 | const std::string& sectionName, |
| 86 | const ConfigSection& section, |
| 87 | bool isDryRun) |
| 88 | |
| 89 | { |
| 90 | // Ignore "log" and sections beginning with "rib_" (intended for rib manager), |
| 91 | // but raise an error if we're missing a handler for an NFD section. |
| 92 | |
Yingdi Yu | e5224e9 | 2014-04-29 18:04:02 -0700 | [diff] [blame] | 93 | if (sectionName.find("rib") == 0 || sectionName == "log") |
Steve DiBenedetto | 34c95f7 | 2014-04-17 20:56:00 -0600 | [diff] [blame] | 94 | { |
| 95 | // do nothing |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | // missing NFD section |
| 100 | ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun); |
| 101 | } |
| 102 | } |
| 103 | }; |
| 104 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 105 | void |
| 106 | initializeManagement(const std::string& configFile) |
| 107 | { |
| 108 | m_internalFace = make_shared<InternalFace>(); |
| 109 | |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 110 | m_fibManager = make_shared<FibManager>(ref(m_forwarder->getFib()), |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 111 | bind(&Forwarder::getFace, m_forwarder.get(), _1), |
| 112 | m_internalFace); |
| 113 | |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 114 | m_faceManager = make_shared<FaceManager>(ref(m_forwarder->getFaceTable()), |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 115 | m_internalFace); |
| 116 | |
| 117 | m_strategyChoiceManager = |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 118 | make_shared<StrategyChoiceManager>(ref(m_forwarder->getStrategyChoice()), |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 119 | m_internalFace); |
| 120 | |
| 121 | m_statusServer = make_shared<StatusServer>(m_internalFace, |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 122 | ref(*m_forwarder)); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 123 | |
Steve DiBenedetto | 34c95f7 | 2014-04-17 20:56:00 -0600 | [diff] [blame] | 124 | ConfigFile config((IgnoreRibAndLogSections())); |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 125 | |
| 126 | general::setConfigFile(config); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 127 | m_internalFace->getValidator().setConfigFile(config); |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 128 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 129 | m_forwarder->addFace(m_internalFace); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 130 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 131 | m_faceManager->setConfigFile(config); |
| 132 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 133 | // parse config file |
| 134 | config.parse(configFile, true); |
| 135 | config.parse(configFile, false); |
| 136 | |
| 137 | // add FIB entry for NFD Management Protocol |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 138 | shared_ptr<fib::Entry> entry = m_forwarder->getFib().insert("/localhost/nfd").first; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 139 | entry->addNextHop(m_internalFace, 0); |
| 140 | } |
| 141 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 142 | static void |
| 143 | printUsage(std::ostream& os, const std::string& programName) |
| 144 | { |
| 145 | os << "Usage: \n" |
| 146 | << " " << programName << " [options]\n" |
| 147 | << "\n" |
| 148 | << "Run NFD forwarding daemon\n" |
| 149 | << "\n" |
| 150 | << "Options:\n" |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 151 | << " [--help] - print this help message\n" |
| 152 | << " [--version] - print version and exit\n" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 153 | << " [--modules] - list available logging modules\n" |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 154 | << " [--config /path/to/nfd.conf] - path to configuration file " |
| 155 | << "(default: " << DEFAULT_CONFIG_FILE << ")\n" |
| 156 | ; |
| 157 | } |
| 158 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 159 | static void |
| 160 | printModules(std::ostream& os) |
| 161 | { |
| 162 | using namespace std; |
| 163 | |
| 164 | os << "Available logging modules: \n"; |
| 165 | |
| 166 | list<string> modules(LoggerFactory::getInstance().getModules()); |
| 167 | for (list<string>::const_iterator i = modules.begin(); i != modules.end(); ++i) |
| 168 | { |
| 169 | os << *i << "\n"; |
| 170 | } |
| 171 | } |
| 172 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 173 | static bool |
| 174 | parseCommandLine(int argc, char** argv, ProgramOptions& options) |
| 175 | { |
| 176 | options.showUsage = false; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 177 | options.showVersion = false; |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 178 | options.showModules = false; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 179 | options.config = DEFAULT_CONFIG_FILE; |
| 180 | |
| 181 | while (true) { |
| 182 | int optionIndex = 0; |
| 183 | static ::option longOptions[] = { |
| 184 | { "help" , no_argument , 0, 0 }, |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 185 | { "modules", no_argument , 0, 0 }, |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 186 | { "config" , required_argument, 0, 0 }, |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 187 | { "version", no_argument , 0, 0 }, |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 188 | { 0 , 0 , 0, 0 } |
| 189 | }; |
| 190 | int c = getopt_long_only(argc, argv, "", longOptions, &optionIndex); |
| 191 | if (c == -1) |
| 192 | break; |
| 193 | |
| 194 | switch (c) { |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 195 | case 0: |
| 196 | switch (optionIndex) { |
| 197 | case 0: // help |
| 198 | options.showUsage = true; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 199 | break; |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 200 | case 1: // modules |
| 201 | options.showModules = true; |
| 202 | break; |
| 203 | case 2: // config |
| 204 | options.config = ::optarg; |
| 205 | break; |
| 206 | case 3: // version |
| 207 | options.showVersion = true; |
| 208 | break; |
| 209 | default: |
| 210 | return false; |
| 211 | } |
| 212 | break; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 213 | } |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 214 | } |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 215 | return true; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 216 | } |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 217 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 218 | void |
| 219 | terminate(const boost::system::error_code& error, |
| 220 | int signalNo, |
| 221 | boost::asio::signal_set& signalSet) |
| 222 | { |
| 223 | if (error) |
| 224 | return; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 225 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 226 | if (signalNo == SIGINT || |
| 227 | signalNo == SIGTERM) |
| 228 | { |
| 229 | getGlobalIoService().stop(); |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 230 | NFD_LOG_INFO("Caught signal '" << strsignal(signalNo) << "', exiting..."); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 231 | } |
| 232 | else |
| 233 | { |
| 234 | /// \todo May be try to reload config file (at least security section) |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 235 | signalSet.async_wait(bind(&Nfd::terminate, this, _1, _2, ref(signalSet))); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 236 | } |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 237 | } |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 238 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 239 | private: |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 240 | shared_ptr<Forwarder> m_forwarder; |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 241 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 242 | shared_ptr<InternalFace> m_internalFace; |
| 243 | shared_ptr<FibManager> m_fibManager; |
| 244 | shared_ptr<FaceManager> m_faceManager; |
| 245 | shared_ptr<StrategyChoiceManager> m_strategyChoiceManager; |
| 246 | shared_ptr<StatusServer> m_statusServer; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 247 | }; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 248 | |
| 249 | } // namespace nfd |
| 250 | |
| 251 | int |
| 252 | main(int argc, char** argv) |
| 253 | { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 254 | using namespace nfd; |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 255 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 256 | ProgramOptions options; |
| 257 | bool isCommandLineValid = Nfd::parseCommandLine(argc, argv, options); |
| 258 | if (!isCommandLineValid) { |
| 259 | Nfd::printUsage(std::cerr, argv[0]); |
| 260 | return 1; |
| 261 | } |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 262 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 263 | if (options.showUsage) { |
| 264 | Nfd::printUsage(std::cout, argv[0]); |
| 265 | return 0; |
| 266 | } |
| 267 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 268 | if (options.showVersion) { |
| 269 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 270 | return 0; |
| 271 | } |
| 272 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 273 | if (options.showModules) { |
| 274 | Nfd::printModules(std::cout); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | Nfd nfdInstance; |
| 279 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 280 | try { |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 281 | nfdInstance.initialize(options.config); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 282 | } |
| 283 | catch (boost::filesystem::filesystem_error& e) { |
| 284 | if (e.code() == boost::system::errc::permission_denied) { |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 285 | NFD_LOG_FATAL("Permissions denied for " << e.path1() << ". " << |
| 286 | argv[0] << " should be run as superuser"); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 287 | } |
| 288 | else { |
| 289 | NFD_LOG_FATAL(e.what()); |
| 290 | } |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 291 | return 1; |
| 292 | } |
| 293 | catch (const std::exception& e) { |
| 294 | NFD_LOG_FATAL(e.what()); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 295 | return 2; |
| 296 | } |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 297 | catch (const PrivilegeHelper::Error& e) { |
| 298 | // PrivilegeHelper::Errors do not inherit from std::exception |
| 299 | // and represent seteuid/gid failures |
| 300 | |
| 301 | NFD_LOG_FATAL(e.what()); |
| 302 | return 3; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 307 | |
| 308 | boost::asio::signal_set signalSet(getGlobalIoService()); |
| 309 | signalSet.add(SIGINT); |
| 310 | signalSet.add(SIGTERM); |
| 311 | signalSet.add(SIGHUP); |
| 312 | signalSet.add(SIGUSR1); |
| 313 | signalSet.add(SIGUSR2); |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 314 | signalSet.async_wait(bind(&Nfd::terminate, &nfdInstance, _1, _2, ref(signalSet))); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 315 | |
| 316 | try { |
| 317 | getGlobalIoService().run(); |
| 318 | } |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 319 | catch (const std::exception& e) { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 320 | NFD_LOG_FATAL(e.what()); |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 321 | return 4; |
| 322 | } |
| 323 | catch (const PrivilegeHelper::Error& e) { |
| 324 | NFD_LOG_FATAL(e.what()); |
| 325 | return 5; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | return 0; |
| 329 | } |