From: Francis Dupont Date: Wed, 10 Jun 2015 14:01:08 +0000 (+0200) Subject: [3513] Added the code for -W, now working on the doc X-Git-Tag: trac3882a_base~3^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=322403fe52a6696f0c822cc34419865047fefcc7;p=thirdparty%2Fkea.git [3513] Added the code for -W, now working on the doc --- diff --git a/src/bin/cfgrpt/Makefile.am b/src/bin/cfgrpt/Makefile.am index b075c9f07f..7897e28ff1 100644 --- a/src/bin/cfgrpt/Makefile.am +++ b/src/bin/cfgrpt/Makefile.am @@ -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 index 0000000000..1de838742b --- /dev/null +++ b/src/bin/cfgrpt/cfgrpt.cc @@ -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 + +#include + +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()); +} + +} +} diff --git a/src/bin/cfgrpt/config_report.h b/src/bin/cfgrpt/config_report.h index 17ce0163e6..a081caf561 100644 --- a/src/bin/cfgrpt/config_report.h +++ b/src/bin/cfgrpt/config_report.h @@ -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(); + } } diff --git a/src/bin/d2/d_controller.cc b/src/bin/d2/d_controller.cc index 11d0e3efcb..494a8ec9cf 100644 --- a/src/bin/d2/d_controller.cc +++ b/src/bin/d2/d_controller.cc @@ -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 diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index bf6ce7b890..d9a6c4fd3e 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -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(optarg); diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc index 9c74921f9a..29294dac91 100644 --- a/src/bin/dhcp6/main.cc +++ b/src/bin/dhcp6/main.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -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(optarg);