]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[trac3616] applied patch and cleaned up
authorFrancis Dupont <fdupont@isc.org>
Fri, 16 Jan 2015 13:02:21 +0000 (14:02 +0100)
committerFrancis Dupont <fdupont@isc.org>
Fri, 16 Jan 2015 13:02:21 +0000 (14:02 +0100)
src/bin/d2/d_controller.cc
src/bin/d2/d_controller.h
src/bin/d2/main.cc

index 71c188f0144961230e2fa37d201e31ac6a06c232..9c20ce18d9604bfc65decc0a2944c94a5d2cff37 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -140,14 +140,16 @@ DControllerBase::parseArgs(int argc, char* argv[])
             break;
 
         case 'v':
-            // Print just Kea version and exit
-            std::cout << getVersion(false) << std::endl;
-            exit(EXIT_SUCCESS);
+            // gather Kea version and throw so main() can catch and return
+            // rather than calling exit() here which disrupts gtest.
+            isc_throw(VersionMessage, getVersion(false));
+            break;
 
         case 'V':
-            // Print extended Kea version and exit
-            std::cout << getVersion(true) << std::endl;
-            exit(EXIT_SUCCESS);
+            // gather Kea version and throw so main() can catch and return
+            // rather than calling exit() here which disrupts gtest.
+            isc_throw(VersionMessage, getVersion(true));
+            break;
             
         case 'c':
             // config file name
index c1e35c9e0ddc397013f43827da5ab4238fdbe5a7..a4d69860fe758cced32ae19b6be9fa41ed7b7e9c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -39,6 +39,18 @@ public:
         isc::Exception(file, line, what) { };
 };
 
+/// @brief Exception used to convey version info upwards.
+/// Since command line argument parsing is done as part of
+/// DControllerBase::launch(), it uses this exception to propagate
+/// version information up to main(), when command line argument
+/// -v or -V is given.
+class VersionMessage : public isc::Exception {
+public:
+    VersionMessage(const char* file, size_t line, const char* what) :
+        isc::Exception(file, line, what) { };
+};
+
+
 /// @brief Exception thrown when the application process fails.
 class ProcessInitError: public isc::Exception {
 public:
@@ -366,7 +378,8 @@ protected:
     /// @param argc  is the number of command line arguments supplied
     /// @param argv  is the array of string (char *) command line arguments
     ///
-    /// @throw throws InvalidUsage when there are usage errors.
+    /// @throw InvalidUsage when there are usage errors.
+    /// @throw VersionMessage if the -v or -V arguments is given.
     void parseArgs(int argc, char* argv[]);
 
     /// @brief Instantiates the application process and then initializes it.
index aea38eb72947502c6d05cdc28d4eaeea6121f253..53ae02eb9be732fb77db2eec257e0bdc816b1fd9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013, 2015  Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -40,6 +40,8 @@ int main(int argc, char* argv[]) {
     try  {
         // 'false' value disables test mode.
         controller->launch(argc, argv, false);
+    } catch (const VersionMessage& ex) {
+        std::cout << ex.what() << std::endl;
     } catch (const isc::Exception& ex) {
         std::cerr << "Service failed:" << ex.what() << std::endl;
         ret = EXIT_FAILURE;