[Powertop] [PATCH] report: Try /etc/lsb-release for OS information

Namhyung Kim <namhyung at gmail.com> Thu, 20 Sep 2012 23:58:29 +0900
Newsgroups dev.linux.lists.powertop
Message-ID <[email protected]>
Ubuntu doesn't provide /etc/{system,redhat,os}-release but
/etc/lsb-release file.  Since it's present on any LSB (Linux Standard
Base) compliant distributions, it'd better to try to read it.

To this end, change read_os_release to receive an additional argument
to find the right line - in this case it's "DISTRIB_DESCRIPTION".

Signed-off-by: Namhyung Kim <namhyung(a)gmail.com>
---
 src/report.cpp |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/report.cpp b/src/report.cpp
index 6776b30..085e81b 100644
--- a/src/report.cpp
+++ b/src/report.cpp
@@ -83,12 +83,11 @@ string cpu_model(void)
 	return "";
 }
 
-static string read_os_release(const string &filename)
+static string read_os_release(const string &filename, const char *pname)
 {
 	ifstream file;
 	char content[4096];
 	char *c;
-	const char *pname = "PRETTY_NAME=";
 	string os("");
 
 	file.open(filename.c_str(), ios::in);
@@ -160,7 +159,9 @@ static void system_info(void)
 	if (str.length() < 1)
 		str = read_sysfs_string("/etc/redhat-release");
 	if (str.length() < 1)
-		str = read_os_release("/etc/os-release");
+		str = read_os_release("/etc/os-release", "PRETTY_NAME=");
+	if (str.length() < 1)
+		str = read_os_release("/etc/lsb-release", "DISTRIB_DESCRIPTION=");
 
 	if (reporttype) {
 		fprintf(reportout.http_report, "<tr class=\"system_even\"><td>OS Information</td><td>%s</td></tr>\n",
-- 
1.7.9.2