Browse Source

[3508] version reporting added to Kea4,Kea6,D2

Tomek Mrugalski 10 years ago
parent
commit
2ea8006b3f

+ 2 - 2
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
 reported.  While The application will likely continue to operating, it may be
 unable to respond correctly to signals.
 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
 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
 % DHCP_DDNS_STARTING_TRANSACTION Transaction Key: %1
 This is a debug message issued when DHCP-DDNS has begun a transaction for
 This is a debug message issued when DHCP-DDNS has begun a transaction for

+ 27 - 4
src/bin/d2/d_controller.cc

@@ -12,7 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 // PERFORMANCE OF THIS SOFTWARE.
 
 
-
+#include <config.h>
 #include <d2/d2_log.h>
 #include <d2/d2_log.h>
 #include <config/ccsession.h>
 #include <config/ccsession.h>
 #include <d2/d_controller.h>
 #include <d2/d_controller.h>
@@ -21,6 +21,7 @@
 #include <dhcpsrv/configuration.h>
 #include <dhcpsrv/configuration.h>
 
 
 #include <sstream>
 #include <sstream>
+#include <unistd.h>
 
 
 namespace isc {
 namespace isc {
 namespace d2 {
 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
     // Log the starting of the service.  Although this is the controller
     // module, use a "DHCP_DDNS_" prefix to the module (to conform to the
     // module, use a "DHCP_DDNS_" prefix to the module (to conform to the
     // principle of least astonishment).
     // 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 {
     try {
         // Step 2 is to create and initialize the application process object.
         // Step 2 is to create and initialize the application process object.
         initProcess();
         initProcess();
@@ -124,6 +125,20 @@ DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
 }
 }
 
 
 void
 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[])
 DControllerBase::parseArgs(int argc, char* argv[])
 {
 {
     // Iterate over the given command line options. If its a stock option
     // Iterate over the given command line options. If its a stock option
@@ -132,14 +147,22 @@ DControllerBase::parseArgs(int argc, char* argv[])
     int ch;
     int ch;
     opterr = 0;
     opterr = 0;
     optind = 1;
     optind = 1;
-    std::string opts("vc:" + getCustomOpts());
+    std::string opts("dvVc:" + getCustomOpts());
     while ((ch = getopt(argc, argv, opts.c_str())) != -1) {
     while ((ch = getopt(argc, argv, opts.c_str())) != -1) {
         switch (ch) {
         switch (ch) {
-        case 'v':
+        case 'd':
             // Enables verbose logging.
             // Enables verbose logging.
             verbose_ = true;
             verbose_ = true;
             break;
             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':
         case 'c':
             // config file name
             // config file name
             if (optarg == NULL) {
             if (optarg == NULL) {

+ 6 - 0
src/bin/d2/d_controller.h

@@ -457,6 +457,12 @@ protected:
     /// This is intended to be used for specific usage violation messages.
     /// This is intended to be used for specific usage violation messages.
     void usage(const std::string& text);
     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:
 private:
     /// @brief Name of the service under control.
     /// @brief Name of the service under control.
     /// This name is used as the configuration module name and appears in log
     /// This name is used as the configuration module name and appears in log

+ 40 - 6
src/bin/dhcp4/main.cc

@@ -41,17 +41,43 @@ const char* const DHCP4_NAME = "kea-dhcp4";
 
 
 const char* const DHCP4_LOGGER_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
 void
 usage() {
 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 "
     cerr << "  -p number: specify non-standard port number 1-65535 "
          << "(useful for testing only)" << endl;
          << "(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);
     exit(EXIT_FAILURE);
 }
 }
 } // end of anonymous namespace
 } // 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
 int
 main(int argc, char* argv[]) {
 main(int argc, char* argv[]) {
     int ch;
     int ch;
@@ -62,12 +88,20 @@ main(int argc, char* argv[]) {
     // The standard config file
     // The standard config file
     std::string config_file("");
     std::string config_file("");
 
 
-    while ((ch = getopt(argc, argv, "vp:c:")) != -1) {
+    while ((ch = getopt(argc, argv, "dvVp:c:")) != -1) {
         switch (ch) {
         switch (ch) {
-        case 'v':
+        case 'd':
             verbose_mode = true;
             verbose_mode = true;
             break;
             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':
         case 'p':
             try {
             try {
                 port_number = boost::lexical_cast<int>(optarg);
                 port_number = boost::lexical_cast<int>(optarg);
@@ -111,7 +145,7 @@ main(int argc, char* argv[]) {
         LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_START_INFO)
         LOG_DEBUG(dhcp4_logger, DBG_DHCP4_START, DHCP4_START_INFO)
             .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no");
             .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.
         // Create the server instance.
         ControlledDhcpv4Srv server(port_number);
         ControlledDhcpv4Srv server(port_number);

+ 3 - 2
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
 is only useful during program development, and should not be used in a
 production environment.
 production environment.
 
 
-% DHCP6_STARTING server starting
+% DHCP6_STARTING Kea DHCPv6 server version %1 starting
 This informational message indicates that the IPv6 DHCP server has
 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
 % DHCP6_START_INFO pid: %1, port: %2, verbose: %3
 This is a debug message issued during the IPv6 DHCP server startup.
 This is a debug message issued during the IPv6 DHCP server startup.

+ 40 - 6
src/bin/dhcp6/main.cc

@@ -41,17 +41,43 @@ const char* const DHCP6_NAME = "kea-dhcp6";
 
 
 const char* const DHCP6_LOGGER_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
 void
 usage() {
 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 "
     cerr << "  -p number: specify non-standard port number 1-65535 "
          << "(useful for testing only)" << endl;
          << "(useful for testing only)" << endl;
-    cerr << "  -c file: specify configuration file" << endl;
     exit(EXIT_FAILURE);
     exit(EXIT_FAILURE);
 }
 }
 } // end of anonymous namespace
 } // 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
 int
 main(int argc, char* argv[]) {
 main(int argc, char* argv[]) {
     int ch;
     int ch;
@@ -62,12 +88,20 @@ main(int argc, char* argv[]) {
     // The standard config file
     // The standard config file
     std::string config_file("");
     std::string config_file("");
 
 
-    while ((ch = getopt(argc, argv, "vp:c:")) != -1) {
+    while ((ch = getopt(argc, argv, "dvp:c:")) != -1) {
         switch (ch) {
         switch (ch) {
-        case 'v':
+        case 'd':
             verbose_mode = true;
             verbose_mode = true;
             break;
             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
         case 'p': // port number
             try {
             try {
                 port_number = boost::lexical_cast<int>(optarg);
                 port_number = boost::lexical_cast<int>(optarg);
@@ -112,7 +146,7 @@ main(int argc, char* argv[]) {
         LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_START_INFO)
         LOG_DEBUG(dhcp6_logger, DBG_DHCP6_START, DHCP6_START_INFO)
             .arg(getpid()).arg(port_number).arg(verbose_mode ? "yes" : "no");
             .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.
         // Create the server instance.
         ControlledDhcpv6Srv server(port_number);
         ControlledDhcpv6Srv server(port_number);