From: cee1 Date: Mon, 18 Apr 2011 09:15:25 +0000 (+0800) Subject: text-progress-bar: Add support for /etc/os-release X-Git-Tag: 0.8.4~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aefa84dc9e5b6ece4550ce40fd8b5969e056959f;p=thirdparty%2Fplymouth.git text-progress-bar: Add support for /etc/os-release Systemd uses '/etc/os-release' as release file, see http://0pointer.de/public/systemd-man/os-release.html --- diff --git a/src/libply-splash-core/ply-text-progress-bar.c b/src/libply-splash-core/ply-text-progress-bar.c index 39e98cf0..7ac02220 100644 --- a/src/libply-splash-core/ply-text-progress-bar.c +++ b/src/libply-splash-core/ply-text-progress-bar.c @@ -98,27 +98,64 @@ ply_text_progress_bar_free (ply_text_progress_bar_t *progress_bar) static void get_os_string (void) { - int fd; - char *buf, *pos, *pos2; - struct stat sbuf; - - fd = open(RELEASE_FILE, O_RDONLY); - if (fd == -1) return; - if (fstat(fd, &sbuf) == -1) return; - buf = calloc(sbuf.st_size + 1, sizeof(char)); - read(fd, buf, sbuf.st_size); - close(fd); - - pos = strstr(buf, " release "); - if (!pos) goto out; - pos2 = strstr(pos, " ("); - if (!pos2) goto out; - *pos = '\0'; - pos+= 9; - *pos2 = '\0'; - asprintf(&os_string," %s %s", buf, pos); + int fd; + char *buf, *pos, *pos2; + struct stat sbuf; + + fd = open (RELEASE_FILE, O_RDONLY); + if (fd == -1) + return; + + if (fstat (fd, &sbuf) == -1) + return; + + buf = calloc (sbuf.st_size + 1, sizeof(char)); + read (fd, buf, sbuf.st_size); + close (fd); + + if (strcmp (RELEASE_FILE, "/etc/os-release") == 0) + { + char key[] = "PRETTY_NAME="; + + for (pos = strstr (buf, key); + pos != NULL; + pos = strstr (pos, key)) + { + if (pos == buf || pos[-1] == '\n') + break; + } + + if (pos != NULL) + { + pos += strlen (key); + pos2 = strstr (pos, "\n"); + + if (pos2 != NULL) + *pos2 = '\0'; + + asprintf (&os_string, " %s", pos); + } + goto out; + } + + pos = strstr (buf, " release "); + + if (pos == NULL) + goto out; + + pos2 = strstr (pos, " ("); + + if (pos2 == NULL) + goto out; + + *pos = '\0'; + pos += strlen (" release "); + + *pos2 = '\0'; + asprintf (&os_string, " %s %s", buf, pos); + out: - free(buf); + free (buf); } void