include version number of amqp-cpp, longer product name, change order of platform info

This commit is contained in:
Emiel Bruijntjes 2023-04-22 16:33:31 +02:00
parent 5bc547b121
commit d8550894ba
5 changed files with 35 additions and 16 deletions

View File

@ -6,19 +6,19 @@ export SONAME = 4.3
export VERSION = 4.3.24 export VERSION = 4.3.24
all: all:
$(MAKE) -C src all $(MAKE) VERSION=${VERSION} -C src all
pure: pure:
$(MAKE) -C src pure $(MAKE) VERSION=${VERSION} -C src pure
release: release:
$(MAKE) -C src release $(MAKE) VERSION=${VERSION} -C src release
static: static:
$(MAKE) -C src static $(MAKE) VERSION=${VERSION} -C src static
shared: shared:
$(MAKE) -C src shared $(MAKE) VERSION=${VERSION} -C src shared
clean: clean:
$(MAKE) -C src clean $(MAKE) -C src clean

View File

@ -1,6 +1,6 @@
CPP = g++ CPP = g++
RM = rm -f 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 = g++
LD_FLAGS = -Wall -shared LD_FLAGS = -Wall -shared
SHARED_LIB = lib$(LIBRARY_NAME).so.$(VERSION) SHARED_LIB = lib$(LIBRARY_NAME).so.$(VERSION)

View File

@ -14,6 +14,18 @@
#include "programname.h" #include "programname.h"
#include "platformname.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 * Set up namespace
*/ */
@ -207,7 +219,7 @@ public:
// fill the peer properties // fill the peer properties
if (!properties.contains("product")) properties["product"] = ProgramName(); 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("platform")) properties["platform"] = PlatformName();
if (!properties.contains("copyright")) properties["copyright"] = "Copernica AMQP-CPP library :: Copyright 2015-2023 Copernica BV"; 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"; if (!properties.contains("information")) properties["information"] = "https://github.com/CopernicaMarketingSoftware/AMQP-CPP";

View File

@ -41,13 +41,13 @@ public:
PlatformName() PlatformName()
{ {
// all information // all information
struct utsname sysinfo; struct utsname info;
// retrieve system info // retrieve system info
if (uname(&sysinfo) != 0) return; if (uname(&info) != 0) return;
// add all info // 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);
} }
/** /**

View File

@ -45,7 +45,17 @@ public:
/** /**
* Constructor * 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 * Destructor
@ -61,11 +71,8 @@ public:
// empty string when not valid // empty string when not valid
if (!_valid) return ""; if (!_valid) return "";
// locate the last slash // return path to executable
auto *slash = strrchr(_path, '/'); return _path;
// if not found return entire path, otherwise just the program name
return slash ? slash + 1 : _path;
} }
}; };