Skip to content
Snippets Groups Projects
Commit 08fb2c51 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

[LinuxVersion] Cache linux version to avoid uname() syscall

Also add error handling to uname() call.
parent c0fc1699
No related branches found
No related tags found
1 merge request!342Improve LinuxVersion
......@@ -34,10 +34,17 @@ static auto checked_strtol(const std::string& s) -> long {
namespace emper::lib {
std::string LinuxVersion::globalVersion;
LinuxVersion::LinuxVersion() {
struct utsname buf;
uname(&buf);
version = std::string(buf.release);
if (globalVersion.empty()) {
struct utsname buf;
if (uname(&buf)) {
DIE_MSG_ERRNO("Failed to invoke uname()");
}
globalVersion = std::string(buf.release);
}
version = globalVersion;
}
// Returns 1 if s is smaller, -1 if this is smaller, 0 if equal
......
......@@ -9,6 +9,7 @@ class TestLinuxVersion;
namespace emper::lib {
class LinuxVersion {
friend class ::TestLinuxVersion;
static std::string globalVersion;
std::string version;
auto compare(const std::string& s) -> int;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment