Introduce a build-time mechanism to allow vendors or downstream
distributions to append their release/version metadata to the output of
ceph version and ceph versions.
The release string is read from the file `/etc/ceph_version` and appends
it to the version string as `release <value>`. If no value is supplied
or the file is empty, the version output remains unchanged.
Example:
If the `/etc/ceph_version` file has "8.1.0" as string then,
ceph version
8d7daada90 (
98d7daada90c6585c6724f69793e804a5e23cb24) tentacle (dev - Debug) release 8.1.0
Signed-off-by: Naveen Naidu <naveen.naidu@ibm.com>
#include <stdlib.h>
#include <sstream>
+#include <fstream>
+#include <string>
+#include <iterator>
+
#include "ceph_ver.h"
#include "common/ceph_strings.h"
return STRINGIFY(CEPH_GIT_VER);
}
+static std::string read_vendor_release_file()
+{
+ auto filename = "/etc/ceph_version";
+ std::ifstream file(filename);
+
+ if(!file.is_open()){
+ return "";
+ }
+
+ std::string content;
+ try {
+ content.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
+ } catch (const std::exception &e) {
+ return "";
+ }
+ if (!content.empty()) {
+ return std::string(" release ") + content;
+ }
+
+ return "";
+
+}
+
std::string const pretty_version_to_str(void)
{
std::ostringstream oss;
#ifdef WITH_CRIMSON
<< " (crimson)"
#endif
+ << read_vendor_release_file()
;
return oss.str();
}