]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3513] Added the code for -W, now working on the doc
authorFrancis Dupont <fdupont@isc.org>
Wed, 10 Jun 2015 14:01:08 +0000 (16:01 +0200)
committerFrancis Dupont <fdupont@isc.org>
Wed, 10 Jun 2015 14:01:08 +0000 (16:01 +0200)
src/bin/cfgrpt/Makefile.am
src/bin/cfgrpt/cfgrpt.cc [new file with mode: 0644]
src/bin/cfgrpt/config_report.h
src/bin/d2/d_controller.cc
src/bin/dhcp4/main.cc
src/bin/dhcp6/main.cc

index b075c9f07f8fb36c4f1b2c61faeaeff5a96a971e..7897e28ff17a81130c1ba0f27c7d50c68e89be9e 100644 (file)
@@ -1,3 +1,5 @@
+AM_CPPFLAGS = -I$(top_srcdir)/src/bin -I$(top_builddir)/src/bin
+
 # Get rid of generated message files on a clean
 CLEANFILES = *.gcno *.gcda
 
@@ -7,4 +9,4 @@ DISTCLEANFILES = config_report.cc
 # convenience archive
 noinst_LTLIBRARIES = libcfgrpt.la
 
-libcfgrpt_la_SOURCES = config_report.h config_report.cc
+libcfgrpt_la_SOURCES = config_report.h config_report.cc cfgrpt.cc
diff --git a/src/bin/cfgrpt/cfgrpt.cc b/src/bin/cfgrpt/cfgrpt.cc
new file mode 100644 (file)
index 0000000..1de8387
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 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
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <sstream>
+
+#include <cfgrpt/config_report.h>
+
+namespace isc {
+namespace detail {
+
+// The config_report array finished by an empty line ("")
+// Each line before this final one begins by four semicolons (;;;;)
+// in order to be easy to extract from binaries.
+std::string
+getConfigReport() {
+    std::stringstream tmp;
+
+    size_t linenum = 0;
+    for (;;) {
+        const char* const line = config_report[linenum++];
+        if (line[0] == '\0')
+            break;
+        tmp << line + 4 << std::endl;
+    }
+    return (tmp.str());
+}
+
+}
+}
index 17ce0163e67b614eba0118fb41f5a49f4ab74a87..a081caf561e56f71bf24d79b2ee6cbd66c56b92b 100644 (file)
@@ -20,6 +20,11 @@ namespace detail {
 
 extern const char* const config_report[];
 
+// The config_report array finished by an empty line ("")
+// Each line before this final one begins by four semicolons (;;;;)
+// in order to be easy to extract from binaries.
+std::string getConfigReport();
+
 }
 }
 
index 11d0e3efcb5af2d63ad51b1d8c768c7a2609eede..494a8ec9cfc8e70523b019e04a92acd5714af5c0 100644 (file)
@@ -134,7 +134,7 @@ DControllerBase::parseArgs(int argc, char* argv[])
     int ch;
     opterr = 0;
     optind = 1;
-    std::string opts("dvVc:" + getCustomOpts());
+    std::string opts("dvVWc:" + getCustomOpts());
     while ((ch = getopt(argc, argv, opts.c_str())) != -1) {
         switch (ch) {
         case 'd':
@@ -154,6 +154,12 @@ DControllerBase::parseArgs(int argc, char* argv[])
             isc_throw(VersionMessage, getVersion(true));
             break;
             
+        case 'W':
+            // gather Kea config report and throw so main() can catch and
+            // return rather than calling exit() here which disrupts gtest.
+            isc_throw(VersionMessage, isc::detail::getConfigReport());
+            break;
+
         case 'c':
             // config file name
             if (optarg == NULL) {
@@ -435,6 +441,8 @@ DControllerBase::usage(const std::string & text)
               << "  -d: optional, verbose output " << std::endl
               << "  -v: print version number and exit" << std::endl
               << "  -V: print extended version information and exit"
+              << std::endl
+              << "  -W: display the configuration report and exit"
               << std::endl;
 
     // add any derivation specific usage
index bf6ce7b8905842d23ab64922e0f624426bb5d1ac..d9a6c4fd3ed8de77f7d7361b177da025d91a8a93 100644 (file)
@@ -19,6 +19,7 @@
 #include <dhcpsrv/cfgmgr.h>
 #include <log/logger_support.h>
 #include <log/logger_manager.h>
+#include <cfgrpt/config_report.h>
 
 #include <boost/lexical_cast.hpp>
 
@@ -48,13 +49,14 @@ usage() {
     cerr << "Kea DHCPv4 server, version " << VERSION << endl;
     cerr << endl;
     cerr << "Usage: " << DHCP4_NAME
-         << " [-v] [-V] [-d] [-p number] [-c file]" << endl;
+         << " -[v|V|W] [-d] [-p number] [-c file]" << endl;
     cerr << "  -c file: specify configuration file" << endl;
     cerr << "  -d: debug mode with extra verbosity (former -v)" << endl;
     cerr << "  -p number: specify non-standard port number 1-65535 "
          << "(useful for testing only)" << endl;
     cerr << "  -v: print version number and exit" << endl;
     cerr << "  -V: print extended version and exit" << endl;
+    cerr << "  -W: display the configuration report and exit" << endl;
     exit(EXIT_FAILURE);
 }
 } // end of anonymous namespace
@@ -69,7 +71,7 @@ main(int argc, char* argv[]) {
     // The standard config file
     std::string config_file("");
 
-    while ((ch = getopt(argc, argv, "dvVp:c:")) != -1) {
+    while ((ch = getopt(argc, argv, "dvVWp:c:")) != -1) {
         switch (ch) {
         case 'd':
             verbose_mode = true;
@@ -83,6 +85,10 @@ main(int argc, char* argv[]) {
             cout << Daemon::getVersion(true) << endl;
             return (EXIT_SUCCESS);
 
+        case 'W':
+            cout << isc::detail::getConfigReport() << endl;
+            return (EXIT_SUCCESS);
+
         case 'p':
             try {
                 port_number = boost::lexical_cast<int>(optarg);
index 9c74921f9ad52ac313a999ac5a5fd447d8382ef2..29294dac9133398c8a0692b25d50740af3636d45 100644 (file)
@@ -20,6 +20,7 @@
 #include <log/logger_support.h>
 #include <log/logger_manager.h>
 #include <exceptions/exceptions.h>
+#include <cfgrpt/config_report.h>
 
 #include <boost/lexical_cast.hpp>
 
@@ -50,10 +51,11 @@ usage() {
     cerr << "Kea DHCPv6 server, version " << VERSION << endl;
     cerr << endl;
     cerr << "Usage: " << DHCP6_NAME
-         << " [-c cfgfile] [-v] [-V] [-d] [-p port_number]" << endl;
+         << " [-c cfgfile] -[v|V|W] [-d] [-p port_number]" << endl;
     cerr << "  -c file: specify configuration file" << endl;
     cerr << "  -v: print version number and exit." << endl;
     cerr << "  -V: print extended version and exit" << endl;
+    cerr << "  -W: display the configuration report and exit" << endl;
     cerr << "  -d: debug mode with extra verbosity (former -v)" << endl;
     cerr << "  -p number: specify non-standard port number 1-65535 "
          << "(useful for testing only)" << endl;
@@ -71,7 +73,7 @@ main(int argc, char* argv[]) {
     // The standard config file
     std::string config_file("");
 
-    while ((ch = getopt(argc, argv, "dvVp:c:")) != -1) {
+    while ((ch = getopt(argc, argv, "dvVWp:c:")) != -1) {
         switch (ch) {
         case 'd':
             verbose_mode = true;
@@ -85,6 +87,10 @@ main(int argc, char* argv[]) {
             cout << Daemon::getVersion(true) << endl;
             return (EXIT_SUCCESS);
 
+        case 'W':
+            cout << isc::detail::getConfigReport() << endl;
+            return (EXIT_SUCCESS);
+
         case 'p': // port number
             try {
                 port_number = boost::lexical_cast<int>(optarg);