From 2a8ab8bb7fe19bc6ca30179c52d32bc1f9e8881d Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Sat, 1 Sep 2018 12:51:07 -0400 Subject: sysinfo: Add support for /etc/os-release --- plugins/sysinfo/unix/parse.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'plugins/sysinfo/unix') 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) -- cgit 1.4.1