Skip to contentSkip to conversation

tst_kvcmp: Fix parsing format for /etc/os-release

PATCH New Petr Vorel 3 participants 4 messages Aug 20, 2020 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 tst_kvcmp: Fix parsing format for /etc/os-release

We need to strip double quotes.
Also for openSUSE Tumbleweed, which contains ID="opensuse-tumbleweed" it "\"%s\"" does not remove trailing double quote, thus match all but double quote.

Fixes e2e60a39b ("lib/tst_kvercmp: Add support /etc/os-release")
---
 lib/tst_kvercmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/tst_kvercmp.c +2 -1
index 185a5c39c..7e980e076 100644
@@ -146,7 +146,8 @@ const char *tst_kvcmp_distname(const char *kver)
 		return "RHEL6";
 
 	if (access(OSRELEASE_PATH, F_OK) != -1) {
-		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=\"%[^\"]\"",
+				      distname);
 
 		while (*p) {
 			*p = toupper((unsigned char)*p);
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/1 tst_kvcmp: Fix parsing format for /etc/os-release

Hello Petr,

I tried to run this with the syscalls/utimensat01 test on Ubuntu (ID=ubuntu), it will fail with:
safe_file_ops.c:220: BROK: Expected 1 conversions got 0 FILE '/etc/os-release' at tst_kvercmp.c:152

Quoted 30 lines · Petr Vorel

We need to strip double quotes.
Also for openSUSE Tumbleweed, which contains ID="opensuse-tumbleweed" it "\"%s\"" does not remove trailing double quote, thus match all but double quote.

Fixes e2e60a39b ("lib/tst_kvercmp: Add support /etc/os-release")
---
 lib/tst_kvercmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/tst_kvercmp.c +2 -2
index 185a5c39c..7e980e076 100644
@@ -146,7 +146,8 @@ const char *tst_kvcmp_distname(const char *kver)
                return "RHEL6";
 
        if (access(OSRELEASE_PATH, F_OK) != -1) {
-               SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+               SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=\"%[^\"]\"",
+                                     distname);
 
                while (*p) {
                        *p = toupper((unsigned char)*p);
--

2.28.0

#2 lore raw

PATCH 1/1 tst_kvcmp: Fix parsing format for /etc/os-release

In reply to Petr Vorel

Hi!

Quoted 17 lines

We need to strip double quotes.
Also for openSUSE Tumbleweed, which contains ID="opensuse-tumbleweed" it "\"%s\"" does not remove trailing double quote, thus match all but double quote.

Fixes e2e60a39b ("lib/tst_kvercmp: Add support /etc/os-release")
---
 lib/tst_kvercmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/tst_kvercmp.c +0 -0
index 185a5c39c..7e980e076 100644

lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 150

Quoted 6 lines
lib/tst_kvercmp.c +2 -1
@@ -146,7 +146,8 @@ const char *tst_kvcmp_distname(const char *kver)
 		return "RHEL6";
 
 	if (access(OSRELEASE_PATH, F_OK) != -1) {
-		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=\"%[^\"]\"",
+				      distname);

I guess like opensuse is the only one that uses double quotes there. Does this actually work on, for example debian, that has ID=debian in the /etc/os-release?

I guess that it may be actually easier to optionaly strip the double quotes after the scanf().

Quoted 6 lines
lib/tst_kvercmp.c +0 -0
 		while (*p) {
 			*p = toupper((unsigned char)*p);
Signature · 1 line
2.28.0
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

PATCH 1/1 tst_kvcmp: Fix parsing format for /etc/os-release

Hi Cyril, Po-Hsu,

Quoted 8 lines

lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 150

Quoted 4 lines
lib/tst_kvercmp.c +2 -1
 	if (access(OSRELEASE_PATH, F_OK) != -1) {
-		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=\"%[^\"]\"",
+				      distname);

I guess like opensuse is the only one that uses double quotes there. Does this actually work on, for example debian, that has ID=debian in the /etc/os-release?

No, sorry for overlooking that.

Quoted 2 lines

I guess that it may be actually easier to optionaly strip the double quotes after the scanf().

+1, I'll send v2.

Kind regards,
Petr