Serge E. Hallyn wrote:
Quoting Rishikesh ([EMAIL PROTECTED]):
Dave Hansen wrote:
On Thu, 2007-04-19 at 17:09 +0530, Rishikesh wrote:
+int kernel_version_newenough()
+{
+       int ret;
+       struct utsname buf;
+       char *s;
+       int maj, min, micro;
+
+       ret = uname(&buf);
+       if (ret == -1) {
+               perror("uname");
+               return 0;
+       }
+       s = buf.release;
+       sscanf(s, "%d.%d.%d", &maj, &min, &micro);
+       if (maj < 2)
+               return 0;
+       if (min < 6)
+               return 0;
+       if (micro < 19)
+               return 0;
+       return 1;
+}
Does LTP usually check for version numbers like this?  I can't imagine
this is new territory.

A much better and more flexible function would be:

        kernel_version_after(int major, int minor, int micro)

-- Dave

Hey dave,

Ya it's true LTP is having the library for checking kernel version (ltp-full-20070331/lib/tst_kvercmp.c ), but as i think this implementation is because of checking the uts name space kernel version, please correct me serge if i am wrong.Since UTS namespace implementation introduced around 2.6.19, so we are just checking for the version for above than that, and it also assumes that kernel before than that version it is not available.

If there is an LTP function to check for kernel version, clearly that
should be used here.

thanks,
-serge

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Hi,

Here i am attaching the patch for using the LTP API for checking the kernel version.


Rishi

This patch will call the LTP API for checking the kernel version more than 2.6.19.
---
 testcases/kernel/containers/utsname/check_utsns_enabled.c |   70 ++++++++++++++
 1 files changed, 70 insertions(+)

Index: ltp-full-20070331/testcases/kernel/containers/utsname/check_utsns_enabled.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ltp-full-20070331/testcases/kernel/containers/utsname/check_utsns_enabled.c	2007-04-23 11:29:17.000000000 +0530
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2007 IBM
+ * Author: Serge Hallyn <[EMAIL PROTECTED]>
+ *
+ * uts namespaces were introduced around 2.6.19.  Kernels before that,
+ * assume they are not enabled.  Kernels after that, check for -EINVAL
+ * when trying to use CLONE_NEWUTS.
+ */
+
+#include <sys/utsname.h>
+#include <sched.h>
+#include <stdio.h>
+#include "../libclone/libclone.h"
+#include "test.h"
+
+int dummy(void *v)
+{
+	return 0;
+}
+
+/*
+ * Not really expecting anyone to use this on a 2.6.19-rc kernel,
+ * else we may get some false positives here.
+ */
+#if 0
+int kernel_version_newenough()
+{
+	int ret;
+	struct utsname buf;
+	char *s;
+	int maj, min, micro;
+
+	ret = uname(&buf);
+	if (ret == -1) {
+		perror("uname");
+		return 0;
+	}
+	s = buf.release;
+	sscanf(s, "%d.%d.%d", &maj, &min, &micro);
+	if (maj < 2)
+		return 0;
+	if (min < 6)
+		return 0;
+	if (micro < 19)
+		return 0;
+	return 1;
+}
+#endif  /* Library is already provided by LTP*/
+int main()
+{
+	void *childstack, *stack;
+	int pid;
+
+	//if (!kernel_version_newenough())
+	if (tst_kvercmp(2,6,19) < 0)
+		return 1;
+	stack = malloc(getpagesize());
+	if (!stack) {
+		perror("malloc");
+		return 2;
+	}
+
+	childstack = stack + getpagesize();
+
+	pid = clone(dummy, childstack, CLONE_NEWUTS, NULL);
+
+	if (pid == -1)
+		return 3;
+	return 0;
+}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to