daemon.cc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/daemon.h>
  16. #include <exceptions/exceptions.h>
  17. #include <cc/data.h>
  18. #include <boost/bind.hpp>
  19. #include <logging.h>
  20. #include <log/logger_name.h>
  21. #include <log/logger_support.h>
  22. #include <errno.h>
  23. /// @brief provides default implementation for basic daemon operations
  24. ///
  25. /// This file provides stub implementations that are expected to be redefined
  26. /// in derived classes (e.g. ControlledDhcpv6Srv)
  27. namespace isc {
  28. namespace dhcp {
  29. // This is an initial config file location.
  30. std::string Daemon::config_file_ = "";
  31. Daemon::Daemon()
  32. : signal_set_(), signal_handler_(), verbose_(false) {
  33. }
  34. Daemon::~Daemon() {
  35. }
  36. void Daemon::init(const std::string& config_file) {
  37. config_file_ = config_file;
  38. }
  39. void Daemon::cleanup() {
  40. }
  41. void Daemon::shutdown() {
  42. }
  43. void Daemon::handleSignal() {
  44. if (signal_set_ && signal_handler_) {
  45. signal_set_->handleNext(boost::bind(signal_handler_, _1));
  46. }
  47. }
  48. void Daemon::configureLogger(const isc::data::ConstElementPtr& log_config,
  49. const ConfigurationPtr& storage,
  50. bool verbose) {
  51. // This is utility class that translates JSON structures into formats
  52. // understandable by log4cplus.
  53. LogConfigParser parser(storage);
  54. if (!log_config) {
  55. // There was no logger configuration. Let's clear any config
  56. // and revert to the default.
  57. parser.applyDefaultConfiguration(verbose); // Set up default logging
  58. return;
  59. }
  60. isc::data::ConstElementPtr loggers;
  61. loggers = log_config->get("loggers");
  62. if (!loggers) {
  63. // There is Logging structure, but it doesn't have loggers
  64. // array in it. Let's clear any old logging configuration
  65. // we may have and revert to the default.
  66. parser.applyDefaultConfiguration(verbose); // Set up default logging
  67. return;
  68. }
  69. // Translate JSON structures into log4cplus formats
  70. parser.parseConfiguration(loggers, verbose);
  71. // Apply the configuration
  72. /// @todo: Once configuration unrolling is implemented,
  73. /// this call will be moved to a separate method.
  74. parser.applyConfiguration();
  75. }
  76. void Daemon::loggerInit(const char* name, bool verbose) {
  77. // Initialize logger system
  78. isc::log::initLogger(name, isc::log::DEBUG, isc::log::MAX_DEBUG_LEVEL,
  79. NULL);
  80. // Apply default configuration (log INFO or DEBUG to stdout)
  81. LogConfigParser::applyDefaultConfiguration(verbose);
  82. }
  83. };
  84. };