From f66bae27f3ccd0d82b4e953ef99d1b84be87298a Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Wed, 28 Sep 2011 14:04:46 -0700 Subject: [PATCH] build-info: Add xorp version string to xorpsh. This also makes the version available to all code, so remove the #define hack in master_conf_tree.cc This means one less place we have to change the xorp version. Also, add run-time info (uname -a, cat /etc/issue if it exists) to the xorp logs to aid trouble-shooting bug reports. Signed-off-by: Ben Greear --- xorp/RELEASE_NOTES | 7 +++++- xorp/SConstruct | 9 +++++++ xorp/cli/cli_node_net.cc | 6 ++--- xorp/cli/cli_private.hh | 15 ----------- xorp/libxorp/build_info.hh | 25 +++++++++++++------ xorp/libxorp/build_info.prefix | 2 +- xorp/rtrmgr/main_rtrmgr.cc | 44 ++++++++++++++++++++++++++++++--- xorp/rtrmgr/master_conf_tree.cc | 4 +-- 8 files changed, 78 insertions(+), 34 deletions(-) diff --git a/xorp/RELEASE_NOTES b/xorp/RELEASE_NOTES index b313d3096..2c99d3431 100644 --- a/xorp/RELEASE_NOTES +++ b/xorp/RELEASE_NOTES @@ -3,8 +3,13 @@ This file contains XORP release notes (most recent releases first). +Release 1.8.5 -Release 1.8.4 + * Compile in build-information to better track versions in logs and + bug reports. + + +Release 1.8.4 (September 20, 2011) * Add async-XRL support, from Steven Simpson diff --git a/xorp/SConstruct b/xorp/SConstruct index 6f1ae581f..81ced07fb 100644 --- a/xorp/SConstruct +++ b/xorp/SConstruct @@ -826,6 +826,15 @@ else: ( 'XRL_PF', ord(xrl_pf_dict[env['transport']]) ), ]) +# Read our VERSION file and use it's contents to pass the +# version into the compile process. +vf = open('VERSION', 'r') +ver = vf.readline() +ver = ver.strip() +env.AppendUnique(CPPDEFINES = [ + ( 'XORP_VERSION', ver), + ]) + # Forcibly disable GCC's SSP support., as it may be incompatible # with the XORP code base. env.AppendUnique(CPPDEFINES = [ diff --git a/xorp/cli/cli_node_net.cc b/xorp/cli/cli_node_net.cc index 5189fed12..672cedc3e 100644 --- a/xorp/cli/cli_node_net.cc +++ b/xorp/cli/cli_node_net.cc @@ -54,9 +54,8 @@ #include "cli_client.hh" #include "cli_private.hh" -#ifdef XORP_BUILDINFO #include "libxorp/build_info.hh" -#endif + #ifdef HAVE_ARPA_TELNET_H #include #endif @@ -563,7 +562,8 @@ CliClient::start_connection(string& error_msg) strncpy(hostname, "xorp", sizeof(hostname) - 1); } hostname[sizeof(hostname) - 1] = '\0'; - cli_print(c_format("%s%s\n", XORP_CLI_WELCOME, hostname)); + cli_print(c_format("Welcome to XORP v%s on %s\n", + BuildInfo::getXorpVersion(), hostname)); #ifdef XORP_BUILDINFO const char* bits = "32-bit"; if (sizeof(void*) == 8) diff --git a/xorp/cli/cli_private.hh b/xorp/cli/cli_private.hh index 41a63a436..1c8d4fdcd 100644 --- a/xorp/cli/cli_private.hh +++ b/xorp/cli/cli_private.hh @@ -17,7 +17,6 @@ // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA; // http://xorp.net -// $XORP: xorp/cli/cli_private.hh,v 1.12 2008/10/02 21:56:30 bms Exp $ #ifndef __CLI_CLI_PRIVATE_HH__ @@ -34,7 +33,6 @@ // #define CLI_MAX_CONNECTIONS 129 // XXX: intentionally not 2^n number -#define XORP_CLI_WELCOME "Welcome to XORP on " #define XORP_CLI_PROMPT "Xorp> " #define XORP_CLI_PROMPT_ENABLE "XORP# " @@ -45,17 +43,4 @@ #define CHAR_TO_META(c) ((c) | 0x080) #endif - -// -// Structures/classes, typedefs and macros -// - -// -// Global variables -// - -// -// Global functions prototypes -// - #endif // __CLI_CLI_PRIVATE_HH__ diff --git a/xorp/libxorp/build_info.hh b/xorp/libxorp/build_info.hh index 6a35113b0..5cb4e231e 100644 --- a/xorp/libxorp/build_info.hh +++ b/xorp/libxorp/build_info.hh @@ -21,15 +21,24 @@ class BuildInfo { public: - /** git md5sum for HEAD */ - static const char* getGitVersion(); - /** Last 3 git change logs */ - static const char* getGitLog(); + /** As in: 1.8.5-WIP */ +#define DEFSTR1(a) #a +#define DEFSTR(a) DEFSTR1(a) + static const char* getXorpVersion() { + return DEFSTR(XORP_VERSION); + } - static const char* getShortBuildDate(); - static const char* getBuildDate(); - static const char* getBuilder(); - static const char* getBuildMachine(); +#ifdef XORP_BUILDINFO + /** git md5sum for HEAD */ + static const char* getGitVersion(); + /** Last 3 git change logs */ + static const char* getGitLog(); + + static const char* getShortBuildDate(); + static const char* getBuildDate(); + static const char* getBuilder(); + static const char* getBuildMachine(); +#endif }; #endif diff --git a/xorp/libxorp/build_info.prefix b/xorp/libxorp/build_info.prefix index 6cdfbcaf4..3380bfa94 100644 --- a/xorp/libxorp/build_info.prefix +++ b/xorp/libxorp/build_info.prefix @@ -1,5 +1,5 @@ -// The BuildInfo.cc file is Autogenerated, modifying by hand +// The build_info.cc file is Autogenerated, modifying by hand // will be a waste of time. You should modify the create_buildinfo.sh // script or the build_info.prefix file instead. diff --git a/xorp/rtrmgr/main_rtrmgr.cc b/xorp/rtrmgr/main_rtrmgr.cc index 0b2285d66..0658ebdc3 100644 --- a/xorp/rtrmgr/main_rtrmgr.cc +++ b/xorp/rtrmgr/main_rtrmgr.cc @@ -28,10 +28,7 @@ #include "libxorp/daemon.h" #include "libxorp/eventloop.hh" #include "libxorp/utils.hh" - -#ifdef XORP_BUILDINFO #include "libxorp/build_info.hh" -#endif #include @@ -714,11 +711,50 @@ main(int argc, char* const argv[]) open_syslog(); #ifdef XORP_BUILDINFO - XLOG_INFO("\n\nXORP BuildInfo, git version: %s built: %s\nBy: %s on machine: %s\nRecent git changes:\n%s\n", + XLOG_INFO("\n\nXORP %s BuildInfo:\ngit version: %s built: %s\nBy: %s on machine: %s\nRecent git changes:\n%s\n", + BuildInfo::getXorpVersion(), BuildInfo::getGitVersion(), BuildInfo::getBuildDate(), BuildInfo::getBuilder(), BuildInfo::getBuildMachine(), BuildInfo::getGitLog()); +#else + XLOG_INFO("\n\nXORP %s\n", BuildInfo::getXorpVersion()); +#endif + + // Log our current system, if on unix +#ifndef __WIN32__ + string tmp_fname(c_format("/tmp/xorp-tmp-%i.txt", getpid())); + string cmd(c_format("uname -a > %s", tmp_fname.c_str())); + system(cmd.c_str()); + ifstream tstf("/etc/issue"); + if (tstf) { + string cmd(c_format("cat /etc/issue >> %s", tmp_fname.c_str())); + system(cmd.c_str()); + } + tstf.close(); + tstf.clear(); + tstf.open(tmp_fname.c_str()); + if (tstf) { + cmd = ""; + char tmpb[500]; + while (tstf) { + tstf.getline(tmpb, 499); + if (tstf.gcount()) { + tmpb[tstf.gcount()] = 0; + cmd += tmpb; + } + else { + break; + } + } + XLOG_INFO("\nHost Information:\n%s\n\n", + cmd.c_str()); + tstf.close(); + } + unlink(tmp_fname.c_str()); +#else + XLOG_INFO("\nHost Information: Windows\n\n"); #endif + // // The main procedure diff --git a/xorp/rtrmgr/master_conf_tree.cc b/xorp/rtrmgr/master_conf_tree.cc index ae431f7af..97239e445 100644 --- a/xorp/rtrmgr/master_conf_tree.cc +++ b/xorp/rtrmgr/master_conf_tree.cc @@ -27,6 +27,7 @@ #include "libxorp/xlog.h" #include "libxorp/debug.h" #include "libxorp/utils.hh" +#include "libxorp/build_info.hh" #ifdef HAVE_GRP_H #include @@ -71,7 +72,6 @@ #endif #define XORP_CONFIG_FORMAT_VERSION "1.1" -#define XORP_CONFIG_XORP_VERSION "1.8.5-WIP" // // The strings that are used to add and delete a load or save file, to @@ -915,7 +915,7 @@ MasterConfigTree::save_to_file(const string& filename, uid_t user_id, header += "\n * Configuration format: "; header += XORP_CONFIG_FORMAT_VERSION; header += "\n * XORP version: "; - header += XORP_CONFIG_XORP_VERSION; + header += BuildInfo::getXorpVersion(); header += "\n * Date: "; header += xlog_localtime2string(); header += "\n * Host: ";