[gnome-system-monitor] Added support for retrieving system information from systemd osrelease. https://bugzilla.gnome.org/s



commit b28cc82e5bb830b3f837fa5add2db6bcf5192232
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Nov 29 23:14:08 2012 +0200

    Added support for retrieving system information from systemd osrelease.
    https://bugzilla.gnome.org/show_bug.cgi?id=688981

 src/sysinfo.cpp |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)
---
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;
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]