From: Tomek Mrugalski Date: Mon, 11 Aug 2014 14:59:26 +0000 (+0200) Subject: [3508] version reporting added to Kea4,Kea6,D2 X-Git-Tag: trac3482_base~46^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ea8006b3fd82794facec49e0adaa3a799e53936;p=thirdparty%2Fkea.git [3508] version reporting added to Kea4,Kea6,D2 --- diff --git a/src/bin/d2/d2_messages.mes b/src/bin/d2/d2_messages.mes index ababcac075..870c5e9311 100644 --- a/src/bin/d2/d2_messages.mes +++ b/src/bin/d2/d2_messages.mes @@ -457,9 +457,9 @@ error after receiving a signal. This is a programmatic error and should be reported. While The application will likely continue to operating, it may be unable to respond correctly to signals. -% DHCP_DDNS_STARTING DHCP-DDNS starting, pid: %1 +% DHCP_DDNS_STARTING DHCP-DDNS starting, pid: %1, version: %2 This is an informational message issued when controller for the -service first starts. +service first starts. Version is also reported. % DHCP_DDNS_STARTING_TRANSACTION Transaction Key: %1 This is a debug message issued when DHCP-DDNS has begun a transaction for diff --git a/src/bin/d2/d_controller.cc b/src/bin/d2/d_controller.cc index 9c094ee48c..6c0b745b53 100644 --- a/src/bin/d2/d_controller.cc +++ b/src/bin/d2/d_controller.cc @@ -12,7 +12,7 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. - +#include #include #include #include @@ -21,6 +21,7 @@ #include #include +#include namespace isc { namespace d2 { @@ -68,7 +69,7 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) { // Log the starting of the service. Although this is the controller // module, use a "DHCP_DDNS_" prefix to the module (to conform to the // principle of least astonishment). - LOG_INFO(dctl_logger, DHCP_DDNS_STARTING).arg(getpid()); + LOG_INFO(dctl_logger, DHCP_DDNS_STARTING).arg(getpid()).arg(VERSION); try { // Step 2 is to create and initialize the application process object. initProcess(); @@ -123,6 +124,20 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) { LOG_INFO(dctl_logger, DHCP_DDNS_SHUTDOWN); } +void +DControllerBase::printVersion(bool extended) const { + std::cout << VERSION << std::endl; + if (extended) { + std::cout << EXTENDED_VERSION << std::endl; + + // @todo print more details (is it Botan or OpenSSL build, + // with or without MySQL/Postgres? What compilation options were + // used? etc) + } + + exit(EXIT_SUCCESS); +} + void DControllerBase::parseArgs(int argc, char* argv[]) { @@ -132,14 +147,22 @@ DControllerBase::parseArgs(int argc, char* argv[]) int ch; opterr = 0; optind = 1; - std::string opts("vc:" + getCustomOpts()); + std::string opts("dvVc:" + getCustomOpts()); while ((ch = getopt(argc, argv, opts.c_str())) != -1) { switch (ch) { - case 'v': + case 'd': // Enables verbose logging. verbose_ = true; break; + case 'v': + printVersion(false); // print just Kea version and exit + break; // break not really needed, print_version never returns + + case 'V': + printVersion(true); // print extended Kea version and exit + break; // break not really needed, print_version never returns + case 'c': // config file name if (optarg == NULL) { diff --git a/src/bin/d2/d_controller.h b/src/bin/d2/d_controller.h index c1e35c9e0d..3ba5280814 100644 --- a/src/bin/d2/d_controller.h +++ b/src/bin/d2/d_controller.h @@ -457,6 +457,12 @@ protected: /// This is intended to be used for specific usage violation messages. void usage(const std::string& text); + /// @brief Prints version number to stdout and exit. + /// + /// Note: This method never returns, it terminates the process. + /// @param extended print additional information? + void printVersion(bool extended) const; + private: /// @brief Name of the service under control. /// This name is used as the configuration module name and appears in log diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index 96b553ed43..e290f68c84 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -41,17 +41,43 @@ const char* const DHCP4_NAME = "kea-dhcp4"; const char* const DHCP4_LOGGER_NAME = "kea-dhcp4"; +/// @brief Prints Kea Usage and exits +/// +/// Note: This function never returns. It terminates the process. void usage() { - cerr << "Usage: " << DHCP4_NAME << " [-v] [-p number] [-c file]" << endl; - cerr << " -v: verbose output" << endl; + cerr << "Kea DHCPv4 server, version " << VERSION << endl; + cerr << endl; + cerr << "Usage: " << DHCP4_NAME + << " [-v] [-V] [-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 << " -c file: specify configuration file" << endl; + cerr << " -v: print version number and exit" << endl; + cerr << " -V: print extended version and exit" << endl; exit(EXIT_FAILURE); } } // end of anonymous namespace +/// @brief Prints Kea version on stdout and exits. +/// +/// Note: This function never returns. It terminates the process. +/// @param extended print additional information? +void +printVersion(bool extended) { + cout << VERSION << endl; + if (extended) { + cout << EXTENDED_VERSION << endl; + + // @todo print more details (is it Botan or OpenSSL build, + // with or without MySQL/Postgres? What compilation options were + // used? etc) + } + + exit(EXIT_SUCCESS); +} + int main(int argc, char* argv[]) { int ch; @@ -62,12 +88,20 @@ main(int argc, char* argv[]) { // The standard config file std::string config_file(""); - while ((ch = getopt(argc, argv, "vp:c:")) != -1) { + while ((ch = getopt(argc, argv, "dvVp:c:")) != -1) { switch (ch) { - case 'v': + case 'd': verbose_mode = true; break; + case 'v': + printVersion(false); // print just Kea version and exit + break; // break not really needed, print_version never returns + + case 'V': + printVersion(true); // print extended Kea version and exit + break; // break not really needed, print_version never returns + case 'p': try { port_number = boost::lexical_cast(optarg); @@ -111,7 +145,7 @@ main(int argc, char* argv[]) { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_START_INFO) .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no"); - LOG_INFO(dhcp4_logger, DHCP4_STARTING); + LOG_INFO(dhcp4_logger, DHCP4_STARTING).arg(VERSION); // Create the server instance. ControlledDhcpv4Srv server(port_number); diff --git a/src/bin/dhcp6/dhcp6_messages.mes b/src/bin/dhcp6/dhcp6_messages.mes index 43a24e5eb9..70e5a065f3 100644 --- a/src/bin/dhcp6/dhcp6_messages.mes +++ b/src/bin/dhcp6/dhcp6_messages.mes @@ -540,9 +540,10 @@ standalone mode, not connected to the message queue. Standalone mode is only useful during program development, and should not be used in a production environment. -% DHCP6_STARTING server starting +% DHCP6_STARTING Kea DHCPv6 server version %1 starting This informational message indicates that the IPv6 DHCP server has -processed any command-line switches and is starting. +processed any command-line switches and is starting. The version +is also printed. % DHCP6_START_INFO pid: %1, port: %2, verbose: %3 This is a debug message issued during the IPv6 DHCP server startup. diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc index 983f169c34..09a3c5e957 100644 --- a/src/bin/dhcp6/main.cc +++ b/src/bin/dhcp6/main.cc @@ -41,17 +41,43 @@ const char* const DHCP6_NAME = "kea-dhcp6"; const char* const DHCP6_LOGGER_NAME = "kea-dhcp6"; +/// @brief Prints Kea Usage and exits +/// +/// Note: This function never returns. It terminates the process. void usage() { - cerr << "Usage: " << DHCP6_NAME << " [-v] [-p port_number] [-c cfgfile]" << endl; - cerr << " -v: verbose output" << endl; + cerr << "Kea DHCPv6 server, version " << VERSION << endl; + cerr << endl; + cerr << "Usage: " << DHCP6_NAME + << " [-c cfgfile] [-v] [-V] [-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 << " -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 << " -c file: specify configuration file" << endl; exit(EXIT_FAILURE); } } // end of anonymous namespace +/// @brief Prints Kea version on stdout and exits. +/// +/// Note: This function never returns. It terminates the process. +/// @param extended print additional information? +void +printVersion(bool extended) { + cout << VERSION << endl; + if (extended) { + cout << EXTENDED_VERSION << endl; + + // @todo print more details (is it Botan or OpenSSL build, + // with or without MySQL/Postgres? What compilation options were + // used? etc) + } + + exit(EXIT_SUCCESS); +} + int main(int argc, char* argv[]) { int ch; @@ -62,12 +88,20 @@ main(int argc, char* argv[]) { // The standard config file std::string config_file(""); - while ((ch = getopt(argc, argv, "vp:c:")) != -1) { + while ((ch = getopt(argc, argv, "dvp:c:")) != -1) { switch (ch) { - case 'v': + case 'd': verbose_mode = true; break; + case 'v': + printVersion(false); // print just Kea version and exit + break; // break not really needed, print_version never returns + + case 'V': + printVersion(true); // print extended Kea version and exit + break; // break not really needed, print_version never returns + case 'p': // port number try { port_number = boost::lexical_cast(optarg); @@ -112,7 +146,7 @@ main(int argc, char* argv[]) { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_START_INFO) .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no"); - LOG_INFO(dhcp6_logger, DHCP6_STARTING); + LOG_INFO(dhcp6_logger, DHCP6_STARTING).arg(VERSION); // Create the server instance. ControlledDhcpv6Srv server(port_number);