diff --git a/Makefile b/Makefile index d460001..6f9254c 100644 --- a/Makefile +++ b/Makefile @@ -6,19 +6,19 @@ export SONAME = 4.3 export VERSION = 4.3.24 all: - $(MAKE) -C src all + $(MAKE) VERSION=${VERSION} -C src all pure: - $(MAKE) -C src pure + $(MAKE) VERSION=${VERSION} -C src pure release: - $(MAKE) -C src release + $(MAKE) VERSION=${VERSION} -C src release static: - $(MAKE) -C src static + $(MAKE) VERSION=${VERSION} -C src static shared: - $(MAKE) -C src shared + $(MAKE) VERSION=${VERSION} -C src shared clean: $(MAKE) -C src clean diff --git a/src/Makefile b/src/Makefile index c8c4401..d96674e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ CPP = g++ RM = rm -f -CPPFLAGS = -Wall -c -I../include -std=c++17 -MD -Wno-class-conversion +CPPFLAGS = -Wall -c -I../include -std=c++17 -MD -Wno-class-conversion -DVERSION=${VERSION} LD = g++ LD_FLAGS = -Wall -shared SHARED_LIB = lib$(LIBRARY_NAME).so.$(VERSION) diff --git a/src/connectionstartframe.h b/src/connectionstartframe.h index 27701bf..a7658e9 100644 --- a/src/connectionstartframe.h +++ b/src/connectionstartframe.h @@ -14,6 +14,18 @@ #include "programname.h" #include "platformname.h" +/** + * Cause we want to print out version string that is passed to compiled with -D + * flag. Why 2 macros? https://www.guyrutenberg.com/2008/12/20/expanding-macros-into-string-constants-in-c/ + */ +#define STR_EXPAND(s) #s +#define STR(s) STR_EXPAND(s) + +/** + * The version and distro names + */ +#define VERSION_NAME STR(VERSION) + /** * Set up namespace */ @@ -207,7 +219,7 @@ public: // fill the peer properties if (!properties.contains("product")) properties["product"] = ProgramName(); - if (!properties.contains("version")) properties["version"] = "Unknown"; + if (!properties.contains("version")) properties["version"] = "AMQP-CPP " VERSION_NAME; if (!properties.contains("platform")) properties["platform"] = PlatformName(); if (!properties.contains("copyright")) properties["copyright"] = "Copernica AMQP-CPP library :: Copyright 2015-2023 Copernica BV"; if (!properties.contains("information")) properties["information"] = "https://github.com/CopernicaMarketingSoftware/AMQP-CPP"; diff --git a/src/platformname.h b/src/platformname.h index af89410..a1bccf2 100644 --- a/src/platformname.h +++ b/src/platformname.h @@ -41,13 +41,13 @@ public: PlatformName() { // all information - struct utsname sysinfo; + struct utsname info; // retrieve system info - if (uname(&sysinfo) != 0) return; + if (uname(&info) != 0) return; // add all info - _value.append(sysinfo.sysname).append(" ").append(sysinfo.version).append(" ").append(sysinfo.release).append(" running on ").append(sysinfo.nodename); + _value.append(info.sysname).append(" ").append(info.nodename).append(" ").append(info.release).append(" ").append(info.version); } /** diff --git a/src/programname.h b/src/programname.h index 3fd892d..edae22d 100644 --- a/src/programname.h +++ b/src/programname.h @@ -45,7 +45,17 @@ public: /** * Constructor */ - ProgramName() : _valid(readlink("/proc/self/exe", _path, PATH_MAX) == 0) {} + ProgramName() + { + // read the link target + auto size = readlink("/proc/self/exe", _path, PATH_MAX); + + // -1 is returned on error, otherwise the size + _valid = size >= 0; + + // set trailing null byte + _path[size == PATH_MAX ? PATH_MAX-1 : size] = '\0'; + } /** * Destructor @@ -61,11 +71,8 @@ public: // empty string when not valid if (!_valid) return ""; - // locate the last slash - auto *slash = strrchr(_path, '/'); - - // if not found return entire path, otherwise just the program name - return slash ? slash + 1 : _path; + // return path to executable + return _path; } };