sysinfo: Add support for /etc/os-release

This commit is contained in:
Patrick Griffis 2018-09-01 12:51:07 -04:00
parent 8665501c77
commit 2a8ab8bb7f

View File

@ -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)