From: Francis Dupont Date: Wed, 17 Oct 2018 14:03:05 +0000 (+0200) Subject: [148-lib-process-servers-without-arguments] Bug fixed - need tests X-Git-Tag: 130-all-keys-sample_base~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48845f58efb2fc6c9bc35410945941ab5e51ee0c;p=thirdparty%2Fkea.git [148-lib-process-servers-without-arguments] Bug fixed - need tests --- diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index 6af2106db5..9e388f0d3d 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -100,6 +100,14 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) { Daemon::loggerInit(bin_name_.c_str(), verbose_); } + try { + checkConfigFile(); + } catch (const std::exception& ex) { + LOG_FATAL(dctl_logger, DCTL_CONFIG_FILE_LOAD_FAIL) + .arg(app_name_).arg(ex.what()); + isc_throw (LaunchError, "Launch Failed: " << ex.what()); + } + try { createPIDFile(); } catch (const DaemonPIDExists& ex) { diff --git a/src/lib/process/daemon.cc b/src/lib/process/daemon.cc index 6e76eeb453..4cd280d2c8 100644 --- a/src/lib/process/daemon.cc +++ b/src/lib/process/daemon.cc @@ -111,6 +111,21 @@ Daemon::setConfigFile(const std::string& config_file) { config_file_ = config_file; } +void +Daemon::checkConfigFile() const { + if (config_file_.empty()) { + isc_throw(isc::BadValue, "config file name is not set"); + } + + // Create Filename instance from the config_file_ pathname, and + // check the file name component. + isc::util::Filename file(config_file_); + if (file.name().empty()) { + isc_throw(isc::BadValue, "config file:" << config_file_ + << " is missing file name"); + } +} + std::string Daemon::getProcName() const { return (proc_name_); @@ -162,11 +177,6 @@ Daemon::makePIDFileName() const { "Daemon::makePIDFileName config file name is not set"); } - if (proc_name_.empty()) { - isc_throw(isc::InvalidOperation, - "Daemon::makePIDFileName process name is not set"); - } - // Create Filename instance from the config_file_ pathname, so we can // extract the fname component. isc::util::Filename file(config_file_); @@ -175,6 +185,11 @@ Daemon::makePIDFileName() const { << config_file_ << " is missing file name"); } + if (proc_name_.empty()) { + isc_throw(isc::InvalidOperation, + "Daemon::makePIDFileName process name is not set"); + } + // Make the pathname for the PID file from the runtime directory, // configuration name and process name. std::ostringstream stream; diff --git a/src/lib/process/daemon.h b/src/lib/process/daemon.h index 2570ba9b67..d779464814 100644 --- a/src/lib/process/daemon.h +++ b/src/lib/process/daemon.h @@ -136,6 +136,10 @@ public: /// @param config_file pathname of the configuration file void setConfigFile(const std::string& config_file); + /// @brief Checks the configuration file name. + /// @throw BadValue when the configuration file name is bad. + void checkConfigFile() const; + /// @brief Writes current configuration to specified file /// /// This method writes the current configuration to specified file. diff --git a/src/lib/process/tests/daemon_unittest.cc b/src/lib/process/tests/daemon_unittest.cc index c5bb7fdc65..dd63011d5e 100644 --- a/src/lib/process/tests/daemon_unittest.cc +++ b/src/lib/process/tests/daemon_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -213,7 +213,7 @@ TEST_F(DaemonTest, createPIDFileOverwrite) { if (pid == 0) { // This is the child, die right away. Tragic, no? - exit (0); + _exit (0); } // Back in the parent test, we need to wait for the child to die