]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[148-lib-process-servers-without-arguments] Bug fixed - need tests
authorFrancis Dupont <fdupont@isc.org>
Wed, 17 Oct 2018 14:03:05 +0000 (16:03 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 19 Oct 2018 21:35:35 +0000 (23:35 +0200)
src/lib/process/d_controller.cc
src/lib/process/daemon.cc
src/lib/process/daemon.h
src/lib/process/tests/daemon_unittest.cc

index 6af2106db58a60983500137efacb0e16da669f98..9e388f0d3d3c411a4ea5031550f98613085229de 100644 (file)
@@ -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) {
index 6e76eeb45393297f5fd2e04e8b8267c6bb277fa2..4cd280d2c81d37ab2c9d5d59fbc12a58db2186ec 100644 (file)
@@ -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;
index 2570ba9b67c554ea81266b1109db7601d04016d6..d779464814d850e237967b3c4736412334f01a2e 100644 (file)
@@ -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.
index c5bb7fdc65a69854b6f75ed068c64c1bbc3fa71f..dd63011d5e75ec6ccc74bef4f552ef6e1c3b64c3 100644 (file)
@@ -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