From 586e7b927461f6604ee3a3159cd7a6d4ac22ef30 Mon Sep 17 00:00:00 2001 From: Dmitry Rozhkov Date: Thu, 11 Feb 2016 13:29:57 +0200 Subject: [PATCH 1/2] Tolerate quotes in os-release files Some systems like Yocto or OpenSUSE prefer to wrap values in /etc/os-release file with quotes always and that still conforms to the format defined in systemd. This patch removes quotes from the values before trying to transform them into integer version id. Signed-off-by: Dmitry Rozhkov Upstream-Status: Backport (v3.0.0+) --- src/version.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/version.c b/src/version.c index 0e09cd9..83d6ad4 100644 --- a/src/version.c +++ b/src/version.c @@ -88,6 +88,7 @@ int read_version_from_subvol_file(char *path_prefix) FILE *file; int v = -1; char *buildstamp; + char *src, *dest; string_or_die(&buildstamp, "%s/usr/lib/os-release", path_prefix); file = fopen(buildstamp, "rm"); @@ -106,7 +107,22 @@ int read_version_from_subvol_file(char *path_prefix) break; } - if (strncmp(line,"VERSION_ID=", 11) == 0) { + if (strncmp(line, "VERSION_ID=", 11) == 0) { + src = &line[11]; + + /* Drop quotes and newline in value */ + dest = src; + while (*src) { + if (*src == '\'' || *src == '"' || *src == '\n') { + ++src; + } else { + *dest = *src; + ++dest; + ++src; + } + } + *dest = 0; + v = strtoull(&line[11], NULL, 10); break; } -- 2.5.0