daemon.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <config.h>
  15. #include <dhcpsrv/cfgmgr.h>
  16. #include <dhcpsrv/daemon.h>
  17. #include <exceptions/exceptions.h>
  18. #include <cc/data.h>
  19. #include <boost/bind.hpp>
  20. #include <logging.h>
  21. #include <log/logger_name.h>
  22. #include <log/logger_support.h>
  23. #include <errno.h>
  24. /// @brief provides default implementation for basic daemon operations
  25. ///
  26. /// This file provides stub implementations that are expected to be redefined
  27. /// in derived classes (e.g. ControlledDhcpv6Srv)
  28. namespace isc {
  29. namespace dhcp {
  30. // This is an initial config file location.
  31. std::string Daemon::config_file_ = "";
  32. Daemon::Daemon()
  33. : signal_set_(), signal_handler_() {
  34. }
  35. Daemon::~Daemon() {
  36. }
  37. void Daemon::init(const std::string& config_file) {
  38. config_file_ = config_file;
  39. }
  40. void Daemon::cleanup() {
  41. }
  42. void Daemon::shutdown() {
  43. }
  44. void Daemon::handleSignal() {
  45. if (signal_set_ && signal_handler_) {
  46. signal_set_->handleNext(boost::bind(signal_handler_, _1));
  47. }
  48. }
  49. void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
  50. const SrvConfigPtr& storage) {
  51. if (log_config) {
  52. isc::data::ConstElementPtr loggers = log_config->get("loggers");
  53. if (loggers) {
  54. LogConfigParser parser(storage);
  55. parser.parseConfiguration(loggers, CfgMgr::instance().isVerbose());
  56. }
  57. }
  58. }
  59. void
  60. Daemon::setVerbose(bool verbose) {
  61. CfgMgr::instance().setVerbose(verbose);
  62. }
  63. bool
  64. Daemon::getVerbose() const {
  65. return (CfgMgr::instance().isVerbose());
  66. }
  67. void Daemon::loggerInit(const char* name, bool verbose) {
  68. setenv("KEA_LOGGER_DESTINATION", "stdout", 0);
  69. // Initialize logger system
  70. isc::log::initLogger(name, isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL,
  71. NULL);
  72. // Apply default configuration (log INFO or DEBUG to stdout)
  73. isc::log::setDefaultLoggingOutput(verbose);
  74. }
  75. };
  76. };