* [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release
@ 2020-08-20 12:00 Petr Vorel
2020-08-20 12:25 ` Cyril Hrubis
0 siblings, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2020-08-20 12:00 UTC (permalink / raw)
To: ltp
ID is normally without double quotes, e.g.: ID=debian
But at least SLES and openSUSE contain double quotes, e.g.:
ID="opensuse-tumbleweed"
thus optionally strip the double quotes after scanning them.
Fixes: e2e60a39b ("lib/tst_kvercmp: Add support /etc/os-release")
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
lib/tst_kvercmp.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index 185a5c39c..dfd81ac83 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)
if (access(OSRELEASE_PATH, F_OK) != -1) {
SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+ if (p[0] == '"')
+ memmove(p, p + 1, strlen(p));
+
+ if (p[strlen(p) - 1] == '"')
+ p[strlen(p) - 1] = '\0';
+
while (*p) {
*p = toupper((unsigned char)*p);
p++;
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release
2020-08-20 12:00 [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release Petr Vorel
@ 2020-08-20 12:25 ` Cyril Hrubis
2020-08-20 12:43 ` Petr Vorel
2020-08-20 12:49 ` Petr Vorel
0 siblings, 2 replies; 5+ messages in thread
From: Cyril Hrubis @ 2020-08-20 12:25 UTC (permalink / raw)
To: ltp
Hi!
> diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> index 185a5c39c..dfd81ac83 100644
> --- a/lib/tst_kvercmp.c
> +++ b/lib/tst_kvercmp.c
> @@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)
> if (access(OSRELEASE_PATH, F_OK) != -1) {
> SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
>
> + if (p[0] == '"')
> + memmove(p, p + 1, strlen(p));
Why can't we just do distname++ and move the p = distname after this
condition?
> + if (p[strlen(p) - 1] == '"')
> + p[strlen(p) - 1] = '\0';
I guess that we can move this to the while loop with:
while (*p) {
if (*p == '"') {
*p = 0;
break;
}
*p = ....
p++;
}
> while (*p) {
> *p = toupper((unsigned char)*p);
> p++;
> --
> 2.28.0
>
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread* [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release
2020-08-20 12:25 ` Cyril Hrubis
@ 2020-08-20 12:43 ` Petr Vorel
2020-08-20 12:49 ` Petr Vorel
1 sibling, 0 replies; 5+ messages in thread
From: Petr Vorel @ 2020-08-20 12:43 UTC (permalink / raw)
To: ltp
Hi Cyril,
> > diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> > index 185a5c39c..dfd81ac83 100644
> > --- a/lib/tst_kvercmp.c
> > +++ b/lib/tst_kvercmp.c
> > @@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)
> > if (access(OSRELEASE_PATH, F_OK) != -1) {
> > SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
> > + if (p[0] == '"')
> > + memmove(p, p + 1, strlen(p));
> Why can't we just do distname++ and move the p = distname after this
> condition?
Sure.
> > + if (p[strlen(p) - 1] == '"')
> > + p[strlen(p) - 1] = '\0';
> I guess that we can move this to the while loop with:
> while (*p) {
> if (*p == '"') {
> *p = 0;
> break;
> }
> *p = ....
> p++;
> }
OK, " shouldn't be in the middle of the character, thus safe
Thanks for the suggestions.
Kind regards,
Petr
^ permalink raw reply [flat|nested] 5+ messages in thread* [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release
2020-08-20 12:25 ` Cyril Hrubis
2020-08-20 12:43 ` Petr Vorel
@ 2020-08-20 12:49 ` Petr Vorel
2020-08-20 12:53 ` Cyril Hrubis
1 sibling, 1 reply; 5+ messages in thread
From: Petr Vorel @ 2020-08-20 12:49 UTC (permalink / raw)
To: ltp
Hi Cyril,
> > diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> > index 185a5c39c..dfd81ac83 100644
> > --- a/lib/tst_kvercmp.c
> > +++ b/lib/tst_kvercmp.c
> > @@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)
> > if (access(OSRELEASE_PATH, F_OK) != -1) {
> > SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
> > + if (p[0] == '"')
> > + memmove(p, p + 1, strlen(p));
> Why can't we just do distname++ and move the p = distname after this
> condition?
OK, distname is char[], not a pointer, I guess I have to use memmove().
Kind regards,
Petr
^ permalink raw reply [flat|nested] 5+ messages in thread* [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release
2020-08-20 12:49 ` Petr Vorel
@ 2020-08-20 12:53 ` Cyril Hrubis
0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2020-08-20 12:53 UTC (permalink / raw)
To: ltp
Hi!
> > > diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> > > index 185a5c39c..dfd81ac83 100644
> > > --- a/lib/tst_kvercmp.c
> > > +++ b/lib/tst_kvercmp.c
> > > @@ -148,6 +148,12 @@ const char *tst_kvcmp_distname(const char *kver)
> > > if (access(OSRELEASE_PATH, F_OK) != -1) {
> > > SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
>
> > > + if (p[0] == '"')
> > > + memmove(p, p + 1, strlen(p));
>
> > Why can't we just do distname++ and move the p = distname after this
> > condition?
> OK, distname is char[], not a pointer, I guess I have to use memmove().
In that case you just need to do char *ret = distname + 1; p = ret; ....
return ret;
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-20 12:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-20 12:00 [LTP] [PATCH v2 1/1] tst_kvcmp: Strip double quotes when parsing /etc/os-release Petr Vorel
2020-08-20 12:25 ` Cyril Hrubis
2020-08-20 12:43 ` Petr Vorel
2020-08-20 12:49 ` Petr Vorel
2020-08-20 12:53 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox