From 8ecf9d4feca66b6dec751e8931116ad1e0969b7c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 24 Nov 2012 11:59:20 -0500 Subject: [PATCH] Fix system information on Fedora lsb_release may not be present, and in that case, we should read /etc/os-release, which is present on all systemd-using distributions and contains the information we need in an easy to parse format. --- src/sysinfo.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/sysinfo.cpp b/src/sysinfo.cpp index 51e7b44..fd2cf66 100644 --- a/src/sysinfo.cpp +++ b/src/sysinfo.cpp @@ -536,9 +536,44 @@ namespace { } }; + class GenericSysInfo + : public SysInfo + { + public: + GenericSysInfo() + { + this->load_os_release(); + } + + private: + void load_os_release() + { + std::ifstream input("/etc/os-release"); + + if (input) { + while (!input.eof()) { + string s; + int len; + std::getline(input, s); + if (s.find("NAME=") == 0) { + len = strlen("NAME="); + this->distro_name = s.substr(len); + } else if (s.find("VERSION=") == 0) { + len = strlen("VERSION="); + // also strip the surrounding quotes + this->distro_release = s.substr(len + 1, s.size() - len - 2); + } + } + } + } + }; + SysInfo* get_sysinfo() { - if (char *p = g_find_program_in_path("lsb_release")) { + if (g_file_test ("/etc/os-release", G_FILE_TEST_EXISTS)) { + return new GenericSysInfo; + } + else if (char *p = g_find_program_in_path("lsb_release")) { g_free(p); return new LSBSysInfo; } -- 1.8.0