Hi Subrata,
I would like to add new function do_unshared_clone_tests() into libclone
to help unsharing inside the cloned process with mentioned
resources.
Its usability is scoped to testcases which likes to clone as well as
unshare resources.
Can you please adapt it.
Signed-off-by: Gowrishankar Muthukrishnan <[EMAIL PROTECTED]>
Index: a/testcases/kernel/containers/libclone/libclone.c
===================================================================
--- a.orig/testcases/kernel/containers/libclone/libclone.c
+++ a/testcases/kernel/containers/libclone/libclone.c
@@ -52,6 +52,69 @@ int do_clone_tests(unsigned long clone_f
return ret;
}
+/*
+ * do_unshared_clone_tests function clones new process
+ * and unshares it from parant on specified flags.
+ */
+int hookto_unshared_clone_tests(void *arg)
+{
+ int ret;
+ struct hook_clone_str *hook;
+ hook = (struct hook_clone_str *)arg;
+
+ ret = unshare(hook->unshare_flags);
+ if (ret < 0) {
+ perror("unshare");
+ return(-1);
+ }
+ ret = hook->fn(hook->arg);
+ return ret;
+}
+
+int do_unshared_clone_tests(unsigned long clone_flags,
+ unsigned long unshare_flags,
+ int(*fn1)(void *arg), void *arg1,
+ int(*fn2)(void *arg), void *arg2)
+{
+ int ret;
+ int stack_size = getpagesize() * 4;
+ void *childstack, *stack = malloc (stack_size);
+ siginfo_t *infop;
+ struct hook_clone_str *hook = malloc(sizeof(struct hook_clone_str*));
+ hook->unshare_flags = unshare_flags;
+ hook->fn = fn1;
+ hook->arg = arg1;
+
+ if (!stack) {
+ perror("malloc");
+ return -1;
+ }
+
+ childstack = stack + stack_size;
+
+#ifdef __ia64__
+ ret = clone2(hookto_unshared_clone_tests, childstack, getpagesize(),
clone_flags | SIGCHLD, (void *)hook, NULL, NULL, NULL);
+#else
+ ret = clone(hookto_unshared_clone_tests, childstack, clone_flags |
SIGCHLD, (void *)hook);
+#endif
+
+ if (ret == -1) {
+ perror("clone");
+ free(stack);
+ return -1;
+ }
+ if (fn2)
+ ret = fn2(arg2);
+
+ if (waitid(P_ALL, ret, infop, WEXITED|WSTOPPED) < 0) {
+ perror("waitid");
+ return -1;
+ }
+ printf("%s: child %d has exited with status %d",
+ __FUNCTION__, infop->si_pid, infop->si_code);
+ return ret;
+}
+
int do_unshare_tests(unsigned long clone_flags,
int (*fn1)(void *arg), void *arg1,
int (*fn2)(void *arg), void *arg2)
Index: a/testcases/kernel/containers/libclone/libclone.h
===================================================================
--- a.orig/testcases/kernel/containers/libclone/libclone.h
+++ a/testcases/kernel/containers/libclone/libclone.h
@@ -26,6 +26,8 @@
#include <libgen.h>
#include <sched.h>
#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
@@ -97,4 +99,19 @@ int do_clone_unshare_tests(int use_clone
int (*fn1)(void *arg), void *arg1,
int (*fn2)(void *arg), void *arg2);
+int do_unshared_clone_tests(unsigned long clone_flags,
+ unsigned long unshare_flags,
+ int(*fn1)(void *arg), void *arg1,
+ int(*fn2)(void *arg), void *arg2);
+
+/* structure to pack unshare flags, function to be executed in child
+ * name space and its arguments.
+ */
+
+struct hook_clone_str {
+ unsigned long unshare_flags;
+ int(*fn)(void *arg);
+ void *arg;
+};
+
#endif
--
Gowrishankar
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list