All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release
@ 2020-08-20 10:02 Petr Vorel
  2020-08-20 10:36 ` Po-Hsu Lin
  2020-08-20 10:46 ` Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Petr Vorel @ 2020-08-20 10:02 UTC (permalink / raw)
  To: ltp

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")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 lib/tst_kvercmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index 185a5c39c..7e980e076 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release
  2020-08-20 10:02 [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release Petr Vorel
@ 2020-08-20 10:36 ` Po-Hsu Lin
  2020-08-20 10:46 ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Po-Hsu Lin @ 2020-08-20 10:36 UTC (permalink / raw)
  To: ltp

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

On Thu, Aug 20, 2020 at 6:02 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> 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")
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  lib/tst_kvercmp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> index 185a5c39c..7e980e076 100644
> --- a/lib/tst_kvercmp.c
> +++ b/lib/tst_kvercmp.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release
  2020-08-20 10:02 [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release Petr Vorel
  2020-08-20 10:36 ` Po-Hsu Lin
@ 2020-08-20 10:46 ` Cyril Hrubis
  2020-08-20 11:05   ` Petr Vorel
  1 sibling, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2020-08-20 10:46 UTC (permalink / raw)
  To: ltp

Hi!
> 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")
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  lib/tst_kvercmp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> index 185a5c39c..7e980e076 100644
> --- a/lib/tst_kvercmp.c
> +++ b/lib/tst_kvercmp.c
> @@ -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().

>  
>  		while (*p) {
>  			*p = toupper((unsigned char)*p);
> -- 
> 2.28.0
> 

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release
  2020-08-20 10:46 ` Cyril Hrubis
@ 2020-08-20 11:05   ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2020-08-20 11:05 UTC (permalink / raw)
  To: ltp

Hi Cyril, Po-Hsu,

> >  	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.

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-20 11:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-20 10:02 [LTP] [PATCH 1/1] tst_kvcmp: Fix parsing format for /etc/os-release Petr Vorel
2020-08-20 10:36 ` Po-Hsu Lin
2020-08-20 10:46 ` Cyril Hrubis
2020-08-20 11:05   ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.