Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 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 | * The University of Memphis. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 11 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 12 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 13 | * |
| 14 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, |
| 16 | * either version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 20 | * PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along with |
| 23 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Steve DiBenedetto | 3a4f83d | 2014-06-02 14:58:54 -0600 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 2aa3962 | 2014-01-22 11:51:11 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 26 | #include "nfd.hpp" |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 27 | #include "rib/service.hpp" |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 28 | |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 29 | #include "core/version.hpp" |
Junxiao Shi | 98e29f4 | 2014-03-31 10:27:26 -0700 | [diff] [blame] | 30 | #include "core/global-io.hpp" |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 31 | #include "core/logger.hpp" |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 32 | #include "core/privilege-helper.hpp" |
Spyridon Mastorakis | d374c40 | 2015-09-09 15:07:00 -0700 | [diff] [blame] | 33 | #include "core/extended-error-message.hpp" |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 34 | |
| 35 | #include <string.h> |
| 36 | |
| 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> |
Alexander Afanasyev | c78b141 | 2014-02-19 14:08:26 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 42 | // boost::thread is used instead of std::thread to guarantee proper cleanup of thread local storage, |
Davide Pesavento | cafae24 | 2016-04-22 02:21:35 +0200 | [diff] [blame] | 43 | // see http://www.boost.org/doc/libs/1_54_0/doc/html/thread/thread_local_storage.html |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 44 | #include <boost/thread.hpp> |
| 45 | |
| 46 | #include <atomic> |
| 47 | #include <condition_variable> |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame^] | 48 | #include <iostream> |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 49 | |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 50 | namespace nfd { |
| 51 | |
Alexander Afanasyev | 89cf5e0 | 2014-04-17 12:08:57 -0700 | [diff] [blame] | 52 | NFD_LOG_INIT("NFD"); |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 54 | /** \brief Executes NFD with RIB manager |
| 55 | * |
| 56 | * NFD (main forwarding procedure) and RIB manager execute in two different threads. |
Junxiao Shi | 71d1214 | 2016-07-23 20:10:18 +0000 | [diff] [blame] | 57 | * Each thread has its own instances of global io_service and global scheduler. |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 58 | * |
| 59 | * When either of the daemons fails, execution of non-failed daemon will be terminated as |
| 60 | * well. In other words, when NFD fails, RIB manager will be terminated; when RIB manager |
| 61 | * fails, NFD will be terminated. |
| 62 | */ |
Alexander Afanasyev | 3136792 | 2015-02-09 20:51:10 -0800 | [diff] [blame] | 63 | class NfdRunner : noncopyable |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 64 | { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 65 | public: |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 66 | explicit |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 67 | NfdRunner(const std::string& configFile) |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 68 | : m_nfd(configFile, m_nfdKeyChain) |
| 69 | , m_configFile(configFile) |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 70 | , m_terminationSignalSet(getGlobalIoService()) |
| 71 | , m_reloadSignalSet(getGlobalIoService()) |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 72 | { |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 73 | m_terminationSignalSet.add(SIGINT); |
| 74 | m_terminationSignalSet.add(SIGTERM); |
| 75 | m_terminationSignalSet.async_wait(bind(&NfdRunner::terminate, this, _1, _2)); |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 76 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 77 | m_reloadSignalSet.add(SIGHUP); |
| 78 | m_reloadSignalSet.async_wait(bind(&NfdRunner::reload, this, _1, _2)); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 81 | static void |
| 82 | printUsage(std::ostream& os, const std::string& programName) |
| 83 | { |
| 84 | os << "Usage: \n" |
| 85 | << " " << programName << " [options]\n" |
| 86 | << "\n" |
| 87 | << "Run NFD forwarding daemon\n" |
| 88 | << "\n" |
| 89 | << "Options:\n" |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 90 | << " [--help] - print this help message\n" |
| 91 | << " [--version] - print version and exit\n" |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 92 | << " [--modules] - list available logging modules\n" |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 93 | << " [--config /path/to/nfd.conf] - path to configuration file " |
| 94 | << "(default: " << DEFAULT_CONFIG_FILE << ")\n" |
| 95 | ; |
| 96 | } |
| 97 | |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 98 | static void |
| 99 | printModules(std::ostream& os) |
| 100 | { |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 101 | os << "Available logging modules: \n"; |
| 102 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 103 | for (const auto& module : LoggerFactory::getInstance().getModules()) { |
| 104 | os << module << "\n"; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 105 | } |
| 106 | } |
Steve DiBenedetto | 2c2b889 | 2014-02-27 11:46:48 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 108 | void |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 109 | initialize() |
| 110 | { |
| 111 | m_nfd.initialize(); |
| 112 | } |
| 113 | |
| 114 | int |
| 115 | run() |
| 116 | { |
| 117 | /** \brief return value |
| 118 | * A non-zero value is assigned when either NFD or RIB manager (running in a separate |
| 119 | * thread) fails. |
| 120 | */ |
| 121 | std::atomic_int retval(0); |
| 122 | |
| 123 | boost::asio::io_service* const mainIo = &getGlobalIoService(); |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 124 | boost::asio::io_service* ribIo = nullptr; |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 125 | |
| 126 | // Mutex and conditional variable to implement synchronization between main and RIB manager |
| 127 | // threads: |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 128 | // - to block main thread until RIB manager thread starts and initializes ribIo (to allow |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 129 | // stopping it later) |
| 130 | std::mutex m; |
| 131 | std::condition_variable cv; |
| 132 | |
| 133 | std::string configFile = this->m_configFile; // c++11 lambda cannot capture member variables |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 134 | boost::thread ribThread([configFile, &retval, &ribIo, mainIo, &cv, &m] { |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 135 | { |
| 136 | std::lock_guard<std::mutex> lock(m); |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 137 | ribIo = &getGlobalIoService(); |
| 138 | BOOST_ASSERT(ribIo != mainIo); |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 139 | } |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 140 | cv.notify_all(); // notify that ribIo has been assigned |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 141 | |
| 142 | try { |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 143 | ndn::KeyChain ribKeyChain; |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 144 | // must be created inside a separate thread |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 145 | rib::Service ribService(configFile, ribKeyChain); |
| 146 | ribService.initialize(); |
| 147 | getGlobalIoService().run(); // ribIo is not thread-safe to use here |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 148 | } |
| 149 | catch (const std::exception& e) { |
| 150 | NFD_LOG_FATAL(e.what()); |
| 151 | retval = 6; |
| 152 | mainIo->stop(); |
| 153 | } |
| 154 | |
| 155 | { |
| 156 | std::lock_guard<std::mutex> lock(m); |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 157 | ribIo = nullptr; |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 158 | } |
| 159 | }); |
| 160 | |
| 161 | { |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 162 | // Wait to guarantee that ribIo is properly initialized, so it can be used to terminate |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 163 | // RIB manager thread. |
| 164 | std::unique_lock<std::mutex> lock(m); |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 165 | cv.wait(lock, [&ribIo] { return ribIo != nullptr; }); |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | try { |
| 169 | mainIo->run(); |
| 170 | } |
| 171 | catch (const std::exception& e) { |
Junxiao Shi | 71d1214 | 2016-07-23 20:10:18 +0000 | [diff] [blame] | 172 | NFD_LOG_FATAL(getExtendedErrorMessage(e)); |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 173 | retval = 4; |
| 174 | } |
| 175 | catch (const PrivilegeHelper::Error& e) { |
| 176 | NFD_LOG_FATAL(e.what()); |
| 177 | retval = 5; |
| 178 | } |
| 179 | |
| 180 | { |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 181 | // ribIo is guaranteed to be alive at this point |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 182 | std::lock_guard<std::mutex> lock(m); |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 183 | if (ribIo != nullptr) { |
| 184 | ribIo->stop(); |
| 185 | ribIo = nullptr; |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
Junxiao Shi | b260017 | 2016-07-11 08:53:53 +0000 | [diff] [blame] | 188 | ribThread.join(); |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 189 | |
| 190 | return retval; |
| 191 | } |
| 192 | |
| 193 | void |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 194 | terminate(const boost::system::error_code& error, int signalNo) |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 195 | { |
| 196 | if (error) |
| 197 | return; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 199 | NFD_LOG_INFO("Caught signal '" << ::strsignal(signalNo) << "', exiting..."); |
| 200 | getGlobalIoService().stop(); |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 201 | } |
Steve DiBenedetto | 84da5bf | 2014-03-11 14:51:29 -0600 | [diff] [blame] | 202 | |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 203 | void |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 204 | reload(const boost::system::error_code& error, int signalNo) |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 205 | { |
| 206 | if (error) |
| 207 | return; |
| 208 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 209 | NFD_LOG_INFO("Caught signal '" << ::strsignal(signalNo) << "', reloading..."); |
| 210 | m_nfd.reloadConfigFile(); |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 211 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 212 | m_reloadSignalSet.async_wait(bind(&NfdRunner::reload, this, _1, _2)); |
Alexander Afanasyev | 5959b01 | 2014-06-02 19:18:12 +0300 | [diff] [blame] | 213 | } |
| 214 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 215 | private: |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 216 | ndn::KeyChain m_nfdKeyChain; |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 217 | Nfd m_nfd; |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 218 | std::string m_configFile; |
| 219 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 220 | boost::asio::signal_set m_terminationSignalSet; |
| 221 | boost::asio::signal_set m_reloadSignalSet; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 222 | }; |
Junxiao Shi | 09bf7c4 | 2014-01-31 11:10:25 -0700 | [diff] [blame] | 223 | |
| 224 | } // namespace nfd |
| 225 | |
| 226 | int |
| 227 | main(int argc, char** argv) |
| 228 | { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 229 | using namespace nfd; |
Junxiao Shi | ea48d8b | 2014-03-16 13:53:47 -0700 | [diff] [blame] | 230 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 231 | namespace po = boost::program_options; |
| 232 | |
| 233 | po::options_description description; |
| 234 | |
| 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") |
| 241 | ; |
| 242 | |
| 243 | po::variables_map vm; |
| 244 | try { |
Spyridon Mastorakis | 149e02c | 2015-07-27 13:22:22 -0700 | [diff] [blame] | 245 | po::store(po::command_line_parser(argc, argv).options(description).run(), vm); |
| 246 | po::notify(vm); |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 247 | } |
| 248 | catch (const std::exception& e) { |
Spyridon Mastorakis | 149e02c | 2015-07-27 13:22:22 -0700 | [diff] [blame] | 249 | // avoid NFD_LOG_FATAL to ensure that errors related to command-line parsing always appear on the |
| 250 | // terminal and are not littered with timestamps and other things added by the logging subsystem |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 251 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 252 | NfdRunner::printUsage(std::cerr, argv[0]); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 253 | return 1; |
| 254 | } |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 255 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 256 | if (vm.count("help") > 0) { |
| 257 | NfdRunner::printUsage(std::cout, argv[0]); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 261 | if (vm.count("version") > 0) { |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 262 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 263 | return 0; |
| 264 | } |
| 265 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 266 | if (vm.count("modules") > 0) { |
| 267 | NfdRunner::printModules(std::cout); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 271 | NfdRunner runner(configFile); |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 272 | |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 273 | try { |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 274 | runner.initialize(); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 275 | } |
Alexander Afanasyev | 31c781e | 2015-02-09 17:39:59 -0800 | [diff] [blame] | 276 | catch (const boost::filesystem::filesystem_error& e) { |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 277 | if (e.code() == boost::system::errc::permission_denied) { |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 278 | NFD_LOG_FATAL("Permissions denied for " << e.path1() << ". " << |
| 279 | argv[0] << " should be run as superuser"); |
Spyridon Mastorakis | 149e02c | 2015-07-27 13:22:22 -0700 | [diff] [blame] | 280 | return 3; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 281 | } |
| 282 | else { |
Spyridon Mastorakis | d374c40 | 2015-09-09 15:07:00 -0700 | [diff] [blame] | 283 | NFD_LOG_FATAL(getExtendedErrorMessage(e)); |
Spyridon Mastorakis | 149e02c | 2015-07-27 13:22:22 -0700 | [diff] [blame] | 284 | return 2; |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 285 | } |
Steve DiBenedetto | bf6a93d | 2014-03-21 14:03:02 -0600 | [diff] [blame] | 286 | } |
| 287 | catch (const std::exception& e) { |
Spyridon Mastorakis | d374c40 | 2015-09-09 15:07:00 -0700 | [diff] [blame] | 288 | NFD_LOG_FATAL(getExtendedErrorMessage(e)); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 289 | return 2; |
| 290 | } |
Steve DiBenedetto | 24b9a64 | 2014-04-07 15:45:39 -0600 | [diff] [blame] | 291 | catch (const PrivilegeHelper::Error& e) { |
| 292 | // PrivilegeHelper::Errors do not inherit from std::exception |
| 293 | // and represent seteuid/gid failures |
| 294 | |
| 295 | NFD_LOG_FATAL(e.what()); |
| 296 | return 3; |
| 297 | } |
| 298 | |
Alexander Afanasyev | f08a737 | 2015-02-09 21:28:19 -0800 | [diff] [blame] | 299 | return runner.run(); |
Alexander Afanasyev | 5a4388a | 2014-03-27 18:02:55 -0700 | [diff] [blame] | 300 | } |