summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2018-09-01 12:51:07 -0400
committerPatrick Griffis <tingping@tingping.se>2018-09-01 12:51:07 -0400
commit2a8ab8bb7fe19bc6ca30179c52d32bc1f9e8881d (patch)
tree68b55779cdfd61cabb432af053aee9945263e0d6
parent8665501c77b4b2868a0277a531c13a55103fed95 (diff)
sysinfo: Add support for /etc/os-release
-rw-r--r--plugins/sysinfo/unix/parse.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugins/sysinfo/unix/parse.c b/plugins/sysinfo/unix/parse.c
index 784e2824..748f75be 100644
--- a/plugins/sysinfo/unix/parse.c
+++ b/plugins/sysinfo/unix/parse.c
@@ -269,6 +269,16 @@ int xs_parse_meminfo(unsigned long long *mem_tot, unsigned long long *mem_free,
 	return 0;
 }
 
+static void strip_quotes(char *string)
+{
+  size_t len = strlen(string);
+  if (string[len - 1] == '"')
+	string[--len] = '\0';
+
+  if (string[0] == '"')
+	memmove(string, string + 1, len + 1);
+}
+
 int xs_parse_distro(char *name)
 {
 	FILE *fp = NULL;
@@ -320,6 +330,20 @@ int xs_parse_distro(char *name)
 		else
 			g_snprintf(buffer, bsize, "Gentoo Linux %s", keywords);
 	}
+	else if((fp = fopen("/etc/os-release", "r")) != NULL)
+	{
+		char name[bsize], version[bsize];
+		strcpy(name, "?");
+		strcpy(version, "?");
+		while(fgets(buffer, bsize, fp) != NULL)
+		{
+			find_match_char(buffer, "NAME=", name);
+			find_match_char(buffer, "VERSION=", version);
+		}
+		strip_quotes(name);
+		strip_quotes(version);
+		g_snprintf(buffer, bsize, "%s %s", name, version);
+	}
 	else
 		g_snprintf(buffer, bsize, "Unknown Distro");
 	if(fp != NULL)