Commit 48845f58 authored by Francis Dupont's avatar Francis Dupont

[148-lib-process-servers-without-arguments] Bug fixed - need tests

parent 005602d0
// 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) {
......
......@@ -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;
......
......@@ -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.
......
// 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment