This patch checks for the UTS namespace enablibility in the kernel.
Signed-off-by: Rishikesh K Rajak <[EMAIL PROTECTED]>
Cc: Serge Hallyn <[EMAIL PROTECTED]>
---
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-19 10:59:32.000000000 +0530
@@ -0,0 +1,67 @@
+/*
+ * 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"
+
+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.
+ */
+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, µ);
+ if (maj < 2)
+ return 0;
+ if (min < 6)
+ return 0;
+ if (micro < 19)
+ return 0;
+ return 1;
+}
+
+int main()
+{
+ void *childstack, *stack;
+ int pid;
+
+ if (!kernel_version_newenough())
+ 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