This is an automated email from the ASF dual-hosted git repository.
cmcfarlen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 2344ea4ad5 Cleanup AppVersionInfo and turn it into a singleton (#10712)
2344ea4ad5 is described below
commit 2344ea4ad5f05f932132587ddcad654d16134f7b
Author: Chris McFarlen <[email protected]>
AuthorDate: Tue Nov 7 10:03:07 2023 -0600
Cleanup AppVersionInfo and turn it into a singleton (#10712)
* Cleanup AppVersionInfo and turn it into a singleton
* move version back to tscore
---
include/iocore/eventsystem/EventSystem.h | 1 +
include/records/RecCore.h | 2 +-
include/tscore/Version.h | 54 +++++++++++++++++++++-
src/api/CMakeLists.txt | 8 ++--
src/api/InkAPI.cc | 6 +--
src/api/{ => unit_tests}/test_Metrics.cc | 0
src/iocore/cache/CacheVC.cc | 2 +-
src/iocore/cache/unit_tests/stub.cc | 4 --
src/proxy/http/unit_tests/unit_test_main.cc | 4 --
src/proxy/http2/test_HPACK.cc | 6 +--
src/proxy/logging/LogAccess.cc | 13 +++---
src/proxy/logging/LogStandalone.cc | 30 ++++++------
.../logging/unit-tests/benchmark_LogObject.cc | 1 -
src/records/P_RecCore.cc | 6 ++-
src/tests/CMakeLists.txt | 2 +-
src/traffic_cache_tool/CMakeLists.txt | 2 +-
src/traffic_crashlog/traffic_crashlog.cc | 7 ++-
src/traffic_ctl/CMakeLists.txt | 2 +-
src/traffic_logcat/logcat.cc | 5 +-
src/traffic_logstats/logstats.cc | 4 +-
src/traffic_quic/traffic_quic.cc | 5 +-
src/traffic_server/Crash.cc | 4 +-
src/traffic_server/traffic_server.cc | 39 ++++++++--------
src/traffic_top/traffic_top.cc | 3 +-
src/traffic_via/CMakeLists.txt | 2 +-
src/traffic_via/traffic_via.cc | 10 ++--
src/tscore/ArgParser.cc | 5 +-
src/tscore/CMakeLists.txt | 4 +-
src/tscore/Regression.cc | 4 +-
src/tscore/Version.cc | 31 +++++++++++++
src/tscore/ink_args.cc | 4 +-
src/tscore/unit_tests/test_Version.cc | 8 ++--
tools/jtest/jtest.cc | 6 +--
33 files changed, 174 insertions(+), 110 deletions(-)
diff --git a/include/iocore/eventsystem/EventSystem.h
b/include/iocore/eventsystem/EventSystem.h
index dae0387965..9e80c8ee49 100644
--- a/include/iocore/eventsystem/EventSystem.h
+++ b/include/iocore/eventsystem/EventSystem.h
@@ -25,6 +25,7 @@
#pragma once
#define _I_EventSystem_h
+#include "tscore/Version.h"
#include "tscore/ink_platform.h"
#include "ts/apidefs.h"
diff --git a/include/records/RecCore.h b/include/records/RecCore.h
index f938e1c61e..981be93fff 100644
--- a/include/records/RecCore.h
+++ b/include/records/RecCore.h
@@ -83,7 +83,7 @@ RecErrT _RecRegisterStatFloat(RecT rec_type, const char
*name, RecFloat data_def
#define RecRegisterStatFloat(rec_type, name, data_default, persist_type) \
_RecRegisterStatFloat((rec_type), (name), (data_default),
REC_PERSISTENCE_TYPE(persist_type))
-RecErrT _RecRegisterStatString(RecT rec_type, const char *name, RecString
data_default, RecPersistT persist_type);
+RecErrT _RecRegisterStatString(RecT rec_type, const char *name, RecStringConst
data_default, RecPersistT persist_type);
#define RecRegisterStatString(rec_type, name, data_default, persist_type) \
_RecRegisterStatString((rec_type), (name), (data_default),
REC_PERSISTENCE_TYPE(persist_type))
diff --git a/include/tscore/Version.h b/include/tscore/Version.h
index 7f89f9cfc9..215e7003ea 100644
--- a/include/tscore/Version.h
+++ b/include/tscore/Version.h
@@ -135,7 +135,7 @@ ModuleVersion::check(ModuleVersion const &that)
class AppVersionInfo
{
-public:
+private:
int defined;
char PkgStr[128];
char AppStr[128];
@@ -148,7 +148,59 @@ public:
char BldCompileFlagsStr[128];
char FullVersionInfoStr[256];
+public:
AppVersionInfo();
void setup(const char *pkg_name, const char *app_name, const char
*app_version, const char *build_date, const char *build_time,
const char *build_machine, const char *build_person, const char
*build_cflags);
+ void setup(const char *app_name);
+
+ const char *
+ package() const
+ {
+ return PkgStr;
+ }
+ const char *
+ application() const
+ {
+ return AppStr;
+ }
+ const char *
+ version() const
+ {
+ return VersionStr;
+ }
+ const char *
+ build_number() const
+ {
+ return BldNumStr;
+ }
+ const char *
+ build_time() const
+ {
+ return BldTimeStr;
+ }
+ const char *
+ build_date() const
+ {
+ return BldDateStr;
+ }
+ const char *
+ build_machine() const
+ {
+ return BldMachineStr;
+ }
+ const char *
+ build_person() const
+ {
+ return BldPersonStr;
+ }
+ const char *
+ full_version() const
+ {
+ return FullVersionInfoStr;
+ }
+
+ static const AppVersionInfo &get_version();
+ static const AppVersionInfo &setup_version(const char *name);
+ static void print_version();
};
diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt
index 8027734fa7..5821347b02 100644
--- a/src/api/CMakeLists.txt
+++ b/src/api/CMakeLists.txt
@@ -55,9 +55,11 @@ if(APPLE)
endif()
if(BUILD_TESTING)
- add_executable(test_Metrics test_Metrics.cc)
+ add_executable(test_ApiCore
+ unit_tests/test_Metrics.cc
+ )
- target_link_libraries(test_Metrics PRIVATE tsapicore tscore catch2::catch2)
+ target_link_libraries(test_ApiCore PRIVATE tsapicore tscore catch2::catch2)
- add_test(NAME test_Metrics COMMAND $<TARGET_FILE:test_Metrics>)
+ add_test(NAME test_ApiCore COMMAND $<TARGET_FILE:test_ApiCore>)
endif()
diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc
index 6df0578053..9965733d3d 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -32,10 +32,10 @@
#include "tscore/Encoding.h"
#include "tscore/PluginUserArgs.h"
#include "tscore/Layout.h"
-#include "tscore/Version.h"
#include "tscore/Diags.h"
#include "api/Metrics.h"
+#include "tscore/Version.h"
#include "api/InkAPIInternal.h"
#include "proxy/logging/Log.h"
#include "proxy/hdrs/URL.h"
@@ -106,8 +106,6 @@
_HDR.m_http = (HTTPHdrImpl *)_OBJ_PTR; \
_HDR.m_mime = _HDR.m_http->m_fields_impl;
-extern AppVersionInfo appVersionInfo;
-
/** Reservation for a user arg.
*/
struct UserArg {
@@ -1398,7 +1396,7 @@ api_init()
global_config_cbs = new ConfigUpdateCbTable;
// Setup the version string for returning to plugins
- ink_strlcpy(traffic_server_version, appVersionInfo.VersionStr,
sizeof(traffic_server_version));
+ ink_strlcpy(traffic_server_version,
AppVersionInfo::get_version().version(), sizeof(traffic_server_version));
// Extract the elements.
// coverity[secure_coding]
if (sscanf(traffic_server_version, "%d.%d.%d", &ts_major_version,
&ts_minor_version, &ts_patch_version) != 3) {
diff --git a/src/api/test_Metrics.cc b/src/api/unit_tests/test_Metrics.cc
similarity index 100%
rename from src/api/test_Metrics.cc
rename to src/api/unit_tests/test_Metrics.cc
diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc
index 8a48b7330a..b749c4a35a 100644
--- a/src/iocore/cache/CacheVC.cc
+++ b/src/iocore/cache/CacheVC.cc
@@ -42,6 +42,7 @@
#if DEBUG
#include "api/Metrics.h"
#endif
+#include "tscore/Version.h"
// inkevent
#include "iocore/eventsystem/Continuation.h"
@@ -55,7 +56,6 @@
#include "tscpp/api/HttpStatus.h"
// tscore
-#include "tscore/Version.h"
#include "tscore/ink_assert.h"
#include "tscore/ink_hrtime.h"
#include "tscore/Ptr.h"
diff --git a/src/iocore/cache/unit_tests/stub.cc
b/src/iocore/cache/unit_tests/stub.cc
index 57a95f9313..66c5d50def 100644
--- a/src/iocore/cache/unit_tests/stub.cc
+++ b/src/iocore/cache/unit_tests/stub.cc
@@ -27,10 +27,6 @@
#include "proxy/HttpAPIHooks.h"
-#include "tscore/Version.h"
-
-AppVersionInfo appVersionInfo;
-
void
HttpHookState::init(TSHttpHookID id, HttpAPIHooks const *global, HttpAPIHooks
const *ssn, HttpAPIHooks const *txn)
{
diff --git a/src/proxy/http/unit_tests/unit_test_main.cc
b/src/proxy/http/unit_tests/unit_test_main.cc
index 9947204d4e..41a6800593 100644
--- a/src/proxy/http/unit_tests/unit_test_main.cc
+++ b/src/proxy/http/unit_tests/unit_test_main.cc
@@ -24,7 +24,3 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
-
-#include "tscore/Version.h"
-
-AppVersionInfo appVersionInfo;
diff --git a/src/proxy/http2/test_HPACK.cc b/src/proxy/http2/test_HPACK.cc
index 894bc9992c..8760d95819 100644
--- a/src/proxy/http2/test_HPACK.cc
+++ b/src/proxy/http2/test_HPACK.cc
@@ -37,8 +37,6 @@ const static int MAX_TABLE_SIZE = 4096;
using namespace std;
-AppVersionInfo appVersionInfo;
-
static int cmd_disable_freelist = 0;
static char cmd_input_dir[512] = "";
static char cmd_output_dir[512] = "";
@@ -396,8 +394,8 @@ REGRESSION_TEST(HPACK_Encoding)(RegressionTest *t, int /*
atype ATS_UNUSED */, i
int
main(int argc, const char **argv)
{
- appVersionInfo.setup(PACKAGE_NAME, "test_HPACK", PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
+ auto &version = AppVersionInfo::setup_version("test_HPACK");
+ process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
ink_freelist_init_ops(cmd_disable_freelist, cmd_disable_pfreelist);
diff --git a/src/proxy/logging/LogAccess.cc b/src/proxy/logging/LogAccess.cc
index f6de3290fa..069a3a79e9 100644
--- a/src/proxy/logging/LogAccess.cc
+++ b/src/proxy/logging/LogAccess.cc
@@ -24,6 +24,7 @@
#include "proxy/logging/LogAccess.h"
+#include "tscore/Version.h"
#include "proxy/http/HttpSM.h"
#include "proxy/hdrs/MIME.h"
#include "iocore/utils/Machine.h"
@@ -31,8 +32,6 @@
#include "proxy/logging/LogBuffer.h"
#include "tscore/Encoding.h"
-extern AppVersionInfo appVersionInfo;
-
char INVALID_STR[] = "!INVALID_STR!";
#define HIDDEN_CONTENT_TYPE "@Content-Type"
@@ -1462,9 +1461,10 @@ LogAccess::marshal_proxy_provided_cert(char *buf)
int
LogAccess::marshal_version_build_number(char *buf)
{
- int len = LogAccess::strlen(appVersionInfo.BldNumStr);
+ auto &version = AppVersionInfo::get_version();
+ int len = LogAccess::strlen(version.build_number());
if (buf) {
- marshal_str(buf, appVersionInfo.BldNumStr, len);
+ marshal_str(buf, version.build_number(), len);
}
return len;
}
@@ -1475,9 +1475,10 @@ LogAccess::marshal_version_build_number(char *buf)
int
LogAccess::marshal_version_string(char *buf)
{
- int len = LogAccess::strlen(appVersionInfo.VersionStr);
+ auto &version = AppVersionInfo::get_version();
+ int len = LogAccess::strlen(version.version());
if (buf) {
- marshal_str(buf, appVersionInfo.VersionStr, len);
+ marshal_str(buf, version.version(), len);
}
return len;
}
diff --git a/src/proxy/logging/LogStandalone.cc
b/src/proxy/logging/LogStandalone.cc
index 2c0cd5407d..c1523f57fe 100644
--- a/src/proxy/logging/LogStandalone.cc
+++ b/src/proxy/logging/LogStandalone.cc
@@ -27,6 +27,7 @@
***************************************************************************/
+#include "tscore/Version.h"
#include "tscore/ink_platform.h"
#include "tscore/ink_lockfile.h"
#include "tscore/ink_sys_control.h"
@@ -47,7 +48,6 @@ static char error_tags[1024] = "";
static char action_tags[1024] = "";
static DiagsConfig *diagsConfig = nullptr;
-AppVersionInfo appVersionInfo;
/*-------------------------------------------------------------------------
init_system
@@ -57,7 +57,7 @@ AppVersionInfo appVersionInfo;
static void
logging_crash_handler(int signo, siginfo_t *info, void *ptr)
{
- signal_format_siginfo(signo, info, appVersionInfo.AppStr);
+ signal_format_siginfo(signo, info,
AppVersionInfo::get_version().application());
signal_crash_handler(signo, info, ptr);
}
@@ -68,8 +68,9 @@ init_system(bool notify_syslog)
signal_register_crash_handler(logging_crash_handler);
if (notify_syslog) {
- syslog(LOG_NOTICE, "NOTE: --- %s Starting ---", appVersionInfo.AppStr);
- syslog(LOG_NOTICE, "NOTE: %s Version: %s", appVersionInfo.AppStr,
appVersionInfo.FullVersionInfoStr);
+ auto &version = AppVersionInfo::get_version();
+ syslog(LOG_NOTICE, "NOTE: --- %s Starting ---", version.application());
+ syslog(LOG_NOTICE, "NOTE: %s Version: %s", version.application(),
version.full_version());
}
}
@@ -89,19 +90,14 @@ initialize_process_manager()
//
// Define version info records
//
- RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.short",
appVersionInfo.VersionStr, RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.long",
appVersionInfo.FullVersionInfoStr, RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_number", appVersionInfo.BldNumStr,
RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_time", appVersionInfo.BldTimeStr,
RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_date", appVersionInfo.BldDateStr,
RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_machine", appVersionInfo.BldMachineStr,
- RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_person", appVersionInfo.BldPersonStr,
- RECP_NON_PERSISTENT);
- // RecRegisterStatString(RECT_PROCESS,
- //
"proxy.process.version.server.build_compile_flags",
- // appVersionInfo.BldCompileFlagsStr,
- // RECP_NON_PERSISTENT);
+ auto &version = AppVersionInfo::get_version();
+ RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.short",
version.version(), RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.long",
version.full_version(), RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_number", version.build_number(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_time", version.build_time(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_date", version.build_date(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_machine", version.build_machine(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_person", version.build_person(),
RECP_NON_PERSISTENT);
}
/*-------------------------------------------------------------------------
diff --git a/src/proxy/logging/unit-tests/benchmark_LogObject.cc
b/src/proxy/logging/unit-tests/benchmark_LogObject.cc
index c0753c9a8c..f30877ee0e 100644
--- a/src/proxy/logging/unit-tests/benchmark_LogObject.cc
+++ b/src/proxy/logging/unit-tests/benchmark_LogObject.cc
@@ -60,7 +60,6 @@ benchmark_LogObject_LDADD = \
#include <condition_variable>
#include <chrono>
-AppVersionInfo appVersionInfo;
static char bind_stdout[512] = "";
static char bind_stderr[512] = "";
diff --git a/src/records/P_RecCore.cc b/src/records/P_RecCore.cc
index 98c4d3218d..a256dda123 100644
--- a/src/records/P_RecCore.cc
+++ b/src/records/P_RecCore.cc
@@ -35,6 +35,7 @@
#include "swoc/bwf_std.h"
#include <fstream>
+#include <iterator>
//-------------------------------------------------------------------------
// RecRegisterStatXXX
@@ -66,8 +67,11 @@ _RecRegisterStatFloat(RecT rec_type, const char *name,
RecFloat data_default, Re
}
RecErrT
-_RecRegisterStatString(RecT rec_type, const char *name, RecString
data_default, RecPersistT persist_type)
+_RecRegisterStatString(RecT rec_type, const char *name, RecStringConst
data_in, RecPersistT persist_type)
{
+ // NOTE(cmcfarlen): RecRegisterState calls RecDataSet which call strdup on
the string data.
+ // therefore, this const cast will not be modified nor escape the stack past
here.
+ char *data_default = const_cast<char *>(data_in);
REC_REGISTER_STAT_XXX(rec_string, RECD_STRING);
}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 7220f20fbf..4993cb9697 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -134,7 +134,7 @@ add_net_test(
)
set(LIBINKNET_UNIT_TEST_DIR "${CMAKE_SOURCE_DIR}/src/iocore/net/unit_tests")
target_compile_definitions(test_net PRIVATE
LIBINKNET_UNIT_TEST_DIR=${LIBINKNET_UNIT_TEST_DIR})
-target_link_libraries(test_net PRIVATE hdrs proxy)
+target_link_libraries(test_net PRIVATE hdrs proxy ts::tsapicore)
add_stubbed_test(EventSystem ${CMAKE_SOURCE_DIR}/src/iocore/net/NetVCTest.cc
${CMAKE_SOURCE_DIR}/src/iocore/eventsystem/unit_tests/test_EventSystem.cc)
target_link_libraries(EventSystem PRIVATE ts::inknet)
diff --git a/src/traffic_cache_tool/CMakeLists.txt
b/src/traffic_cache_tool/CMakeLists.txt
index 3fb0c79a25..18e8ba6a68 100644
--- a/src/traffic_cache_tool/CMakeLists.txt
+++ b/src/traffic_cache_tool/CMakeLists.txt
@@ -17,5 +17,5 @@
add_executable(traffic_cache_tool CacheDefs.cc CacheTool.cc CacheScan.cc)
-target_link_libraries(traffic_cache_tool PRIVATE ts::tscore libswoc)
+target_link_libraries(traffic_cache_tool PRIVATE ts::tscore libswoc
ts::tsapicore)
install(TARGETS traffic_cache_tool)
diff --git a/src/traffic_crashlog/traffic_crashlog.cc
b/src/traffic_crashlog/traffic_crashlog.cc
index 8cd218b5c5..3b922a0386 100644
--- a/src/traffic_crashlog/traffic_crashlog.cc
+++ b/src/traffic_crashlog/traffic_crashlog.cc
@@ -43,7 +43,6 @@ static char *user = nullptr;
// If pid_t is not sizeof(int), we will have to jiggle argument parsing.
extern char __pid_size_static_assert[sizeof(pid_t) == sizeof(int) ? 0 : -1];
-static AppVersionInfo appVersionInfo;
static const ArgumentDescription argument_descriptions[] = {
{"target", '-', "Target process ID", "I",
&target_pid, nullptr, nullptr},
{"host", '-', "Host triplet for the process being logged", "S*",
&host_triplet, nullptr, nullptr},
@@ -141,10 +140,10 @@ main(int /* argc ATS_UNUSED */, const char **argv)
DiagsPtr::set(new Diags("traffic_crashlog", "" /* tags */, "" /* actions */,
new BaseLogFile("stderr")));
- appVersionInfo.setup(PACKAGE_NAME, "traffic_crashlog", PACKAGE_VERSION,
__DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version("traffic_crashlog");
// Process command line arguments and dump into variables
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
+ process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
// XXX This is a hack. traffic_manager starts traffic_server with the euid
of the admin user. We are still
// privileged, but won't be able to open files in /proc or ptrace the
target. This really should be fixed
@@ -182,7 +181,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
facility = LOG_DAEMON;
}
- openlog(appVersionInfo.AppStr, LOG_PID | LOG_NDELAY | LOG_NOWAIT,
facility);
+ openlog(version.application(), LOG_PID | LOG_NDELAY | LOG_NOWAIT,
facility);
diags()->config.outputs[DL_Debug].to_syslog = true;
diags()->config.outputs[DL_Status].to_syslog = true;
diags()->config.outputs[DL_Note].to_syslog = true;
diff --git a/src/traffic_ctl/CMakeLists.txt b/src/traffic_ctl/CMakeLists.txt
index 2a9de7847c..d49c7f030d 100644
--- a/src/traffic_ctl/CMakeLists.txt
+++ b/src/traffic_ctl/CMakeLists.txt
@@ -20,6 +20,6 @@ add_executable(
${CMAKE_SOURCE_DIR}/src/shared/rpc/IPCSocketClient.cc
)
-target_link_libraries(traffic_ctl ts::tscore libswoc yaml-cpp::yaml-cpp)
+target_link_libraries(traffic_ctl ts::tscore libswoc yaml-cpp::yaml-cpp
ts::tsapicore)
install(TARGETS traffic_ctl)
diff --git a/src/traffic_logcat/logcat.cc b/src/traffic_logcat/logcat.cc
index 9b5d05c748..0344a087c4 100644
--- a/src/traffic_logcat/logcat.cc
+++ b/src/traffic_logcat/logcat.cc
@@ -21,6 +21,7 @@
limitations under the License.
*/
+#include "tscore/Version.h"
#include "tscore/ink_platform.h"
#include "tscore/ink_args.h"
#include "tscore/Layout.h"
@@ -255,7 +256,7 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
// build the application information structure
//
- appVersionInfo.setup(PACKAGE_NAME, PROGRAM_NAME, PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version(PROGRAM_NAME);
runroot_handler(argv);
// Before accessing file system initialize Layout engine
@@ -263,7 +264,7 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
// process command-line arguments
//
output_file[0] = 0;
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
+ process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
// check that only one of the -o and -a options was specified
//
diff --git a/src/traffic_logstats/logstats.cc b/src/traffic_logstats/logstats.cc
index 7eed350794..8894e6d1ac 100644
--- a/src/traffic_logstats/logstats.cc
+++ b/src/traffic_logstats/logstats.cc
@@ -661,7 +661,7 @@ void
CommandLineArgs::parse_arguments(const char **argv)
{
// process command-line arguments
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv, USAGE_LINE);
+ process_args(&AppVersionInfo::get_version(), argument_descriptions,
countof(argument_descriptions), argv, USAGE_LINE);
// Process as "CGI" ?
if (strstr(argv[0], ".cgi") || cgi) {
@@ -2434,7 +2434,7 @@ main(int /* argc ATS_UNUSED */, const char *argv[])
struct flock lck;
// build the application information structure
- appVersionInfo.setup(PACKAGE_NAME, PROGRAM_NAME, PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ AppVersionInfo::setup_version(PROGRAM_NAME);
runroot_handler(argv);
// Before accessing file system initialize Layout engine
diff --git a/src/traffic_quic/traffic_quic.cc b/src/traffic_quic/traffic_quic.cc
index edc1df799f..033ec417ea 100644
--- a/src/traffic_quic/traffic_quic.cc
+++ b/src/traffic_quic/traffic_quic.cc
@@ -56,8 +56,7 @@ main(int argc, const char **argv)
Layout::create();
// Set up the application version info
- AppVersionInfo appVersionInfo;
- appVersionInfo.setup(PACKAGE_NAME, "traffic_quic", PACKAGE_VERSION,
__DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version("traffic_quic");
QUICClientConfig config;
@@ -79,7 +78,7 @@ main(int argc, const char **argv)
};
// Process command line arguments and dump into variables
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
+ process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
if (config.http3) {
config.http0_9 = false;
diff --git a/src/traffic_server/Crash.cc b/src/traffic_server/Crash.cc
index ccfc2e73d3..5879bfa8ca 100644
--- a/src/traffic_server/Crash.cc
+++ b/src/traffic_server/Crash.cc
@@ -36,8 +36,6 @@
static constexpr int NO_FD = swoc::file::NO_FD;
-extern AppVersionInfo appVersionInfo;
-
static pid_t crash_logger_pid = -1;
static int crash_logger_fd = NO_FD;
@@ -171,6 +169,6 @@ crash_logger_invoke(int signo, siginfo_t *info, void *ctx)
}
// Log the signal, dump a stack trace and core.
- signal_format_siginfo(signo, info, appVersionInfo.AppStr); // XXX Add
timestamp ...
+ signal_format_siginfo(signo, info,
AppVersionInfo::get_version().application()); // XXX Add timestamp ...
signal_crash_handler(signo, info, ctx);
}
diff --git a/src/traffic_server/traffic_server.cc
b/src/traffic_server/traffic_server.cc
index 6c4fbf5741..1e66c85cfb 100644
--- a/src/traffic_server/traffic_server.cc
+++ b/src/traffic_server/traffic_server.cc
@@ -30,6 +30,7 @@
****************************************************************************/
+#include "tscore/Version.h"
#include "swoc/swoc_file.h"
#include "tscore/ink_platform.h"
@@ -195,8 +196,6 @@ static int cmd_block = 0;
// -1: cache is already initialized, don't delay.
static int delay_listen_for_cache = 0;
-AppVersionInfo appVersionInfo; // Build info for this application
-
static ArgumentDescription argument_descriptions[] = {
{"net_threads", 'n', "Number of Net Threads",
"I",
&num_of_net_threads, "PROXY_NET_THREADS", nullptr},
{"udp_threads", 'U', "Number of UDP Threads",
"I",
&num_of_udp_threads, "PROXY_UDP_THREADS", nullptr},
@@ -583,7 +582,8 @@ proxy_signal_handler(int signo, siginfo_t *info, void *ctx)
return;
}
- signal_format_siginfo(signo, info, appVersionInfo.AppStr);
+ auto &version = AppVersionInfo::get_version();
+ signal_format_siginfo(signo, info, version.application());
#if TS_HAS_PROFILER
HeapProfilerDump("/tmp/ts_end.hprof");
@@ -607,8 +607,9 @@ init_system()
signal_register_default_handler(proxy_signal_handler);
signal_register_crash_handler(signal_crash_handler);
- syslog(LOG_NOTICE, "NOTE: --- %s Starting ---", appVersionInfo.AppStr);
- syslog(LOG_NOTICE, "NOTE: %s Version: %s", appVersionInfo.AppStr,
appVersionInfo.FullVersionInfoStr);
+ auto &version = AppVersionInfo::get_version();
+ syslog(LOG_NOTICE, "NOTE: --- %s Starting ---", version.application());
+ syslog(LOG_NOTICE, "NOTE: %s Version: %s", version.application(),
version.full_version());
//
// Delimit file Descriptors
@@ -679,15 +680,14 @@ initialize_process_manager()
//
// Define version info records
//
- RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.short",
appVersionInfo.VersionStr, RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.long",
appVersionInfo.FullVersionInfoStr, RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_number", appVersionInfo.BldNumStr,
RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_time", appVersionInfo.BldTimeStr,
RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_date", appVersionInfo.BldDateStr,
RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_machine", appVersionInfo.BldMachineStr,
- RECP_NON_PERSISTENT);
- RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_person", appVersionInfo.BldPersonStr,
- RECP_NON_PERSISTENT);
+ auto &version = AppVersionInfo::get_version();
+ RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.short",
version.version(), RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS, "proxy.process.version.server.long",
version.full_version(), RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_number", version.build_number(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_time", version.build_time(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_date", version.build_date(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_machine", version.build_machine(),
RECP_NON_PERSISTENT);
+ RecRegisterStatString(RECT_PROCESS,
"proxy.process.version.server.build_person", version.build_person(),
RECP_NON_PERSISTENT);
}
extern void initializeRegistry();
@@ -1590,13 +1590,14 @@ chdir_root()
{
std::string prefix = Layout::get()->prefix;
+ auto &version = AppVersionInfo::get_version();
if (chdir(prefix.c_str()) < 0) {
- fprintf(stderr, "%s: unable to change to root directory \"%s\" [%d
'%s']\n", appVersionInfo.AppStr, prefix.c_str(), errno,
+ fprintf(stderr, "%s: unable to change to root directory \"%s\" [%d
'%s']\n", version.application(), prefix.c_str(), errno,
strerror(errno));
- fprintf(stderr, "%s: please correct the path or set the TS_ROOT
environment variable\n", appVersionInfo.AppStr);
+ fprintf(stderr, "%s: please correct the path or set the TS_ROOT
environment variable\n", version.application());
::exit(1);
} else {
- printf("%s: using root directory '%s'\n", appVersionInfo.AppStr,
prefix.c_str());
+ printf("%s: using root directory '%s'\n", version.application(),
prefix.c_str());
}
}
@@ -1779,7 +1780,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
pcre_free = ats_free;
// Define the version info
- appVersionInfo.setup(PACKAGE_NAME, "traffic_server", PACKAGE_VERSION,
__DATE__, __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version("traffic_server");
runroot_handler(argv);
// Before accessing file system initialize Layout engine
@@ -1791,7 +1792,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
std::sort(argument_descriptions, argument_descriptions +
countof(argument_descriptions),
[](ArgumentDescription const &a, ArgumentDescription const &b) {
return 0 > strcasecmp(a.name, b.name); });
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
+ process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
command_flag = command_flag || *command_string;
command_index = find_cmd_index(command_string);
command_valid = command_flag && command_index >= 0;
diff --git a/src/traffic_top/traffic_top.cc b/src/traffic_top/traffic_top.cc
index 2395c9ac88..645512dc83 100644
--- a/src/traffic_top/traffic_top.cc
+++ b/src/traffic_top/traffic_top.cc
@@ -389,8 +389,7 @@ main(int argc, const char **argv)
bool absolute = false;
string url;
- AppVersionInfo version;
- version.setup(PACKAGE_NAME, "traffic_top", PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version("traffic_top");
const ArgumentDescription argument_descriptions[] = {
{"sleep", 's', "Sets the delay between updates (in seconds)", "I",
&sleep_time, nullptr, nullptr},
diff --git a/src/traffic_via/CMakeLists.txt b/src/traffic_via/CMakeLists.txt
index 7bff76bc0e..54d62a8177 100644
--- a/src/traffic_via/CMakeLists.txt
+++ b/src/traffic_via/CMakeLists.txt
@@ -16,7 +16,7 @@
#######################
add_executable(traffic_via traffic_via.cc)
-target_link_libraries(traffic_via ts::tscore libswoc)
+target_link_libraries(traffic_via ts::tscore libswoc ts::tsapicore)
install(TARGETS traffic_via)
if(BUILD_TESTING)
diff --git a/src/traffic_via/traffic_via.cc b/src/traffic_via/traffic_via.cc
index 4cfb57ad86..7bf905c14c 100644
--- a/src/traffic_via/traffic_via.cc
+++ b/src/traffic_via/traffic_via.cc
@@ -39,8 +39,6 @@
#define SUBSTRING_VECTOR_COUNT 30 // Should be multiple of 3
-static AppVersionInfo appVersionInfo;
-
struct VIA {
VIA(const char *t) : title(t) {}
~VIA() { delete next; }
@@ -105,7 +103,7 @@ detailViaLookup(char flag)
break;
default:
viaTable = nullptr;
- fprintf(stderr, "%s: %s: %c\n", appVersionInfo.AppStr, "Invalid VIA header
character", flag);
+ fprintf(stderr, "%s: %s: %c\n",
AppVersionInfo::get_version().application(), "Invalid VIA header character",
flag);
break;
}
@@ -176,7 +174,7 @@ standardViaLookup(char flag)
break;
default:
viaTable = nullptr;
- fprintf(stderr, "%s: %s: %c\n", appVersionInfo.AppStr, "Invalid VIA header
character", flag);
+ fprintf(stderr, "%s: %s: %c\n",
AppVersionInfo::get_version().application(), "Invalid VIA header character",
flag);
break;
}
@@ -307,7 +305,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
bool opStatus;
// build the application information structure
- appVersionInfo.setup(PACKAGE_NAME, "traffic_via", PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version("traffic_via");
/* see 'ink_args.h' for meanings of the various fields */
ArgumentDescription argument_descriptions[] = {
@@ -315,7 +313,7 @@ main(int /* argc ATS_UNUSED */, const char **argv)
HELP_ARGUMENT_DESCRIPTION(),
};
- process_args(&appVersionInfo, argument_descriptions,
countof(argument_descriptions), argv);
+ process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
for (unsigned i = 0; i < n_file_arguments; ++i) {
if (strcmp(file_arguments[i], "-") == 0) {
diff --git a/src/tscore/ArgParser.cc b/src/tscore/ArgParser.cc
index a4dfc0e4f2..7d221f9468 100644
--- a/src/tscore/ArgParser.cc
+++ b/src/tscore/ArgParser.cc
@@ -125,9 +125,8 @@ void
ArgParser::Command::version_message() const
{
// unified version message of ATS
- AppVersionInfo appVersionInfo;
- appVersionInfo.setup(PACKAGE_NAME, _name.c_str(), PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
- ink_fputln(stdout, appVersionInfo.FullVersionInfoStr);
+ AppVersionInfo::setup_version(_name.c_str());
+ AppVersionInfo::print_version();
exit(0);
}
diff --git a/src/tscore/CMakeLists.txt b/src/tscore/CMakeLists.txt
index 811b89dcf5..a5a771a17f 100644
--- a/src/tscore/CMakeLists.txt
+++ b/src/tscore/CMakeLists.txt
@@ -111,7 +111,7 @@ else()
target_sources(tscore PRIVATE HKDF_openssl.cc)
endif()
-target_link_libraries(tscore PUBLIC OpenSSL::Crypto PCRE::PCRE libswoc
yaml-cpp::yaml-cpp resolv::resolv)
+target_link_libraries(tscore PUBLIC OpenSSL::Crypto PCRE::PCRE libswoc
yaml-cpp::yaml-cpp resolv::resolv ts::tsapicore)
if(TS_USE_POSIX_CAP)
target_link_libraries(tscore PUBLIC cap::cap)
@@ -153,7 +153,6 @@ if(BUILD_TESTING)
unit_tests/test_Regex.cc
unit_tests/test_Throttler.cc
unit_tests/test_Tokenizer.cc
- unit_tests/test_Version.cc
unit_tests/test_arena.cc
unit_tests/test_ink_inet.cc
unit_tests/test_ink_memory.cc
@@ -161,6 +160,7 @@ if(BUILD_TESTING)
unit_tests/test_layout.cc
unit_tests/test_scoped_resource.cc
unit_tests/unit_test_main.cc
+ unit_tests/test_Version.cc
)
target_link_libraries(
test_tscore
diff --git a/src/tscore/Regression.cc b/src/tscore/Regression.cc
index ea6be2798b..5657c7a8f7 100644
--- a/src/tscore/Regression.cc
+++ b/src/tscore/Regression.cc
@@ -222,9 +222,7 @@ RegressionTest::main(int /* argc */, const char **argv, int
level)
{"regression_list", 'l', "List Regression Tests", "T",
®ression_list, "PROXY_REGRESSION_LIST", nullptr},
};
- AppVersionInfo version;
-
- version.setup(PACKAGE_NAME, progname(argv[0]), PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version(progname(argv[0]));
process_args(&version, argument_descriptions,
countof(argument_descriptions), argv);
diff --git a/src/tscore/Version.cc b/src/tscore/Version.cc
index 48ad137c0c..e3af3041c9 100644
--- a/src/tscore/Version.cc
+++ b/src/tscore/Version.cc
@@ -24,6 +24,7 @@
#include "tscore/ink_platform.h"
#include "tscore/Version.h"
#include "tscore/ink_string.h"
+#include "tscore/ink_file.h"
AppVersionInfo::AppVersionInfo()
{
@@ -126,3 +127,33 @@ AppVersionInfo::setup(const char *pkg_name, const char
*app_name, const char *ap
defined = 1;
}
+
+void
+AppVersionInfo::setup(const char *name)
+{
+ setup(PACKAGE_NAME, name, PACKAGE_VERSION, __DATE__, __TIME__,
BUILD_MACHINE, BUILD_PERSON, "");
+}
+
+static AppVersionInfo appVersionInfo;
+
+const AppVersionInfo &
+AppVersionInfo::get_version()
+{
+ if (!appVersionInfo.defined) {
+ appVersionInfo.setup("<unknown>");
+ }
+ return appVersionInfo;
+}
+
+const AppVersionInfo &
+AppVersionInfo::setup_version(const char *name)
+{
+ appVersionInfo.setup(name);
+ return appVersionInfo;
+}
+
+void
+AppVersionInfo::print_version()
+{
+ ink_fputln(stdout, get_version().FullVersionInfoStr);
+}
diff --git a/src/tscore/ink_args.cc b/src/tscore/ink_args.cc
index 66fc5c8819..dcee7c4205 100644
--- a/src/tscore/ink_args.cc
+++ b/src/tscore/ink_args.cc
@@ -80,7 +80,7 @@ process_arg(const AppVersionInfo *appinfo, const
ArgumentDescription *argument_d
const char *arg = nullptr;
if (arg_is_version_flag(&argument_descriptions[i])) {
- ink_fputln(stdout, appinfo->FullVersionInfoStr);
+ ink_fputln(stdout, appinfo->full_version());
exit(0);
}
@@ -207,7 +207,7 @@ process_args_ex(const AppVersionInfo *appinfo, const
ArgumentDescription *argume
//
// Grab Command Line Arguments
//
- program_name = appinfo->AppStr;
+ program_name = appinfo->application();
while (*++argv) {
// Hack for supporting '-' as a file argument.
if (strcmp(*argv, "-") == 0) {
diff --git a/src/tscore/unit_tests/test_Version.cc
b/src/tscore/unit_tests/test_Version.cc
index 6b4a3fa512..1c043810c0 100644
--- a/src/tscore/unit_tests/test_Version.cc
+++ b/src/tscore/unit_tests/test_Version.cc
@@ -51,15 +51,15 @@ TEST_CASE("AppVersionInfo", "[libts][version]")
// If not empty BUILD_NUMBER overrides any result, in this case run only
// this test (the rest will always fail).
info.setup("Apache Traffic Server", "traffic_server", "5.2.1",
bench[0][0], bench[0][1], "build_slave", "builder", "");
- if (0 != std::strcmp(info.BldNumStr, bench[0][2])) {
- std::printf(errMsgFormat, bench[0][2], info.BldNumStr);
+ if (0 != std::strcmp(info.build_number(), bench[0][2])) {
+ std::printf(errMsgFormat, bench[0][2], info.build_number());
CHECK(false);
}
} else {
for (int i = 1; i < benchSize; i++) {
info.setup("Apache Traffic Server", "traffic_server", "5.2.1",
bench[i][0], bench[i][1], "build_slave", "builder", "");
- if (0 != std::strcmp(info.BldNumStr, bench[i][2])) {
- std::printf(errMsgFormat, bench[i][2], info.BldNumStr);
+ if (0 != std::strcmp(info.build_number(), bench[i][2])) {
+ std::printf(errMsgFormat, bench[i][2], info.build_number());
CHECK(false);
}
}
diff --git a/tools/jtest/jtest.cc b/tools/jtest/jtest.cc
index 3e5a3d8d82..0268cbb124 100644
--- a/tools/jtest/jtest.cc
+++ b/tools/jtest/jtest.cc
@@ -110,8 +110,6 @@
#define JTEST_DONE 0
#define JTEST_CONT 1
-static AppVersionInfo appVersionInfo;
-
static const char *hexdigits = "0123456789ABCDEFabcdef";
static const char *dontunescapify = "#;/?+=&:@%";
static const char *dontescapify = "#;/?+=&:@~.-_%";
@@ -3633,7 +3631,7 @@ get_defered_urls(FILE *fp)
int
main(int argc __attribute__((unused)), const char *argv[])
{
- appVersionInfo.setup(PACKAGE_NAME, "jtest", PACKAGE_VERSION, __DATE__,
__TIME__, BUILD_MACHINE, BUILD_PERSON, "");
+ auto &version = AppVersionInfo::setup_version("jtest");
/* for QA -- we want to be able to tail an output file
* during execution "nohup jtest -P pxy -p prt &"
@@ -3642,7 +3640,7 @@ main(int argc __attribute__((unused)), const char *argv[])
fd = (FD *)malloc(MAXFDS * sizeof(FD));
memset(static_cast<void *>(fd), 0, MAXFDS * sizeof(FD));
- process_args(&appVersionInfo, argument_descriptions,
n_argument_descriptions, argv);
+ process_args(&version, argument_descriptions, n_argument_descriptions, argv);
if (!drand_seed) {
ts::Random::seed((long)time(nullptr));