diff mbox series

[1/2] lib/tst_kvercmp: Add support to get distname for Ubuntu in tst_kvcmp_distname

Message ID 20200817120644.9401-2-po-hsu.lin@canonical.com
State Changes Requested
Headers show
Series Fix for syscalls/utimensat01 test on Ubuntu 4.4 kernel | expand

Commit Message

Po-Hsu Lin Aug. 17, 2020, 12:06 p.m. UTC
The kver on Ubuntu will be something like these:
* 4.4.0-187-generic
* 5.4.0-1021-kvm
* 4.15.0-1093-azure

So it's better to grep for ^ID=ubuntu in /etc/os-release to determine
the distname, instead of doing this from checking kver substring like
what we did for RHEL / Oracle Linux

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 lib/tst_kvercmp.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Cyril Hrubis Aug. 17, 2020, 12:34 p.m. UTC | #1
Hi!
> * 4.4.0-187-generic
> * 5.4.0-1021-kvm
> * 4.15.0-1093-azure
> 
> So it's better to grep for ^ID=ubuntu in /etc/os-release to determine
> the distname, instead of doing this from checking kver substring like
> what we did for RHEL / Oracle Linux
> 
> Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
> ---
>  lib/tst_kvercmp.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
> index dc3bb669b..349d45543 100644
> --- a/lib/tst_kvercmp.c
> +++ b/lib/tst_kvercmp.c
> @@ -139,6 +139,11 @@ const char *tst_kvcmp_distname(const char *kver)
>  	if (strstr(kver, ".el6"))
>  		return "RHEL6";
>  
> +	// Special case for Ubuntu, kernel version cannot reveal the dist_name
> +	int rc = WEXITSTATUS(system("grep -q ^ID=ubuntu /etc/os-release 2>/dev/null"));
> +	if (rc == 0)
> +		return "UBUNTU";

Can we please properly parse the /etc/os-release file insetad of this
hackery?

It should be as easy as one SAFE_FILE_SCANF() in the case that the file
exists.
Cyril Hrubis Aug. 17, 2020, 12:45 p.m. UTC | #2
Hi!
> It should be as easy as one SAFE_FILE_SCANF() in the case that the file
> exists.

It's SAFE_FILE_LINES_SCANF()
Po-Hsu Lin Aug. 18, 2020, 9:37 a.m. UTC | #3
On Mon, Aug 17, 2020 at 8:44 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > It should be as easy as one SAFE_FILE_SCANF() in the case that the file
> > exists.
>
> It's SAFE_FILE_LINES_SCANF()

Hello Cyril,
thanks for your suggestion, I will submit V2 for this.

>
> --
> Cyril Hrubis
> chrubis@suse.cz
diff mbox series

Patch

diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index dc3bb669b..349d45543 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -139,6 +139,11 @@  const char *tst_kvcmp_distname(const char *kver)
 	if (strstr(kver, ".el6"))
 		return "RHEL6";
 
+	// Special case for Ubuntu, kernel version cannot reveal the dist_name
+	int rc = WEXITSTATUS(system("grep -q ^ID=ubuntu /etc/os-release 2>/dev/null"));
+	if (rc == 0)
+		return "UBUNTU";
+
 	return NULL;
 }