Skip to content

Commit e2e60a3

Browse files
Cypresslinmetan-ucw
authored andcommitted
lib/tst_kvercmp: Add support /etc/os-release
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 parse OS name from ID= in /etc/os-release, instead of doing this from checking kver substring like what we did for RHEL and Oracle Linux here. From the document [1] this string will alway be in lowercase. Example: "ID=fedora" or "ID=debian". Thus it needs to be converted to uppercase to make it consistent with other return values in tst_kvcmp_distname(). [1] https://www.freedesktop.org/software/systemd/man/os-release.html Signed-off-by: Po-Hsu Lin <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent 4218a54 commit e2e60a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/tst_kvercmp.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1919
*/
2020

21+
#include <ctype.h>
2122
#include <stdlib.h>
2223
#include <unistd.h>
2324
#include <string.h>
2425
#include <limits.h>
2526
#include <sys/utsname.h>
2627
#include "test.h"
2728

29+
#define OSRELEASE_PATH "/etc/os-release"
30+
2831
static char *parse_digit(const char *str, int *d)
2932
{
3033
unsigned long v;
@@ -127,6 +130,9 @@ int tst_kvexcmp(const char *tst_exv, const char *cur_ver)
127130

128131
const char *tst_kvcmp_distname(const char *kver)
129132
{
133+
static char distname[64];
134+
char *p = distname;
135+
130136
if (strstr(kver, ".el5uek"))
131137
return "OL5UEK";
132138

@@ -139,6 +145,17 @@ const char *tst_kvcmp_distname(const char *kver)
139145
if (strstr(kver, ".el6"))
140146
return "RHEL6";
141147

148+
if (access(OSRELEASE_PATH, F_OK) != -1) {
149+
SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
150+
151+
while (*p) {
152+
*p = toupper((unsigned char)*p);
153+
p++;
154+
}
155+
156+
return distname;
157+
}
158+
142159
return NULL;
143160
}
144161

0 commit comments

Comments
 (0)