diff options
| author | Leandro Pereira <leandro@hardinfo.org> | 2018-05-16 06:50:56 -0700 | 
|---|---|---|
| committer | Leandro Pereira <leandro@hardinfo.org> | 2018-05-16 06:50:56 -0700 | 
| commit | 6dfda529f4bde07cdda52a62c30eeda4cdd9eb17 (patch) | |
| tree | 21008a3b098f9ccfff02a9ad0ad5ed5e6b093663 /modules | |
| parent | c45ec053dc97d30922a6c19c8fc8aec30b294a11 (diff) | |
Parse /usr/lib/os-release while detecting distribution
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/computer/os.c | 33 | 
1 files changed, 33 insertions, 0 deletions
| 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 @@ -282,6 +282,33 @@ computer_get_language(void)  }  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)  {      static const struct { @@ -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"); | 
