From 6dfda529f4bde07cdda52a62c30eeda4cdd9eb17 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Wed, 16 May 2018 06:50:56 -0700 Subject: Parse /usr/lib/os-release while detecting distribution --- modules/computer/os.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'modules/computer') diff --git a/modules/computer/os.c b/modules/computer/os.c index a8886f64..aec53df2 100644 --- a/modules/computer/os.c +++ b/modules/computer/os.c @@ -281,6 +281,33 @@ computer_get_language(void) return ret; } +static gchar * +parse_os_release(void) +{ + gchar *pretty_name = NULL; + gchar **split, *contents, *line; + + if (!g_file_get_contents("/usr/lib/os-release", &contents, NULL, NULL)) + return NULL; + + split = g_strsplit(idle_free(contents), "\n", 0); + if (!split) + return NULL; + + for (line = *split; *line; line++) { + if (!strncmp(line, "PRETTY_NAME=", sizeof("PRETTY_NAME=") - 1)) { + pretty_name = g_strdup(line + + strlen("PRETTY_NAME=") + 1); + strend(pretty_name, '"'); + break; + } + } + + g_strfreev(split); + + return pretty_name; +} + static gchar * detect_distro(void) { @@ -327,6 +354,12 @@ detect_distro(void) gchar *contents; int i; + if (g_file_test("/usr/lib/os-release", G_FILE_TEST_EXISTS)) { + contents = parse_os_release(); + if (contents) + return contents; + } + if (g_spawn_command_line_sync("lsb_release -d", &contents, NULL, NULL, NULL)) { gchar *tmp = strstr(idle_free(contents), "Description:\t"); -- cgit v1.2.3