define and use common clone helpers (v2)
PATCH 1/1 define and use common clone helpers (v2)
Define ltp_clone() and ltp_clone_malloc() in libltp, and convert existing clone usages to them. (clone04 can't use it bc it wants to pass NULL, which ltp_clone() will for many arches convert to NULL+stacksize-1).
This seems to pass on my test system, but would need careful review and ack before considering applying.
Changelog:
Sep 29: [suggested by Mike Frysinger <[email protected]>]
1. rename ltp_clone_malloc ltp_clone_quick, and have ltp_clone_malloc take stacksize from caller. [ no i couldn't think of a better name than 'quick' ]
2. have ltp_clone() accept a NULL stack
3. convert clone04 testcase
4. save errno over free on failure
5. don't perror, use tst_resm when needed
6. change order of ltp_clone* arguments so first n arguments are always consistent.
--- include/test.h | 10 ++ lib/cloner.c | 102 ++++++++++++++++++++ testcases/kernel/containers/libclone/libclone.c | 32 +------ testcases/kernel/containers/libclone/libclone.h | 13 --- testcases/kernel/containers/libclone/libnetns.c | 19 +---- .../kernel/containers/mqns/check_mqns_enabled.c | 2 +- .../kernel/containers/pidns/check_pidns_enabled.c | 2 +- testcases/kernel/containers/pidns/pidns12.c | 2 +- testcases/kernel/containers/pidns/pidns13.c | 4 +- testcases/kernel/containers/pidns/pidns16.c | 2 +- testcases/kernel/containers/pidns/pidns20.c | 2 +- testcases/kernel/containers/pidns/pidns21.c | 2 +- testcases/kernel/containers/pidns/pidns30.c | 2 +- testcases/kernel/containers/pidns/pidns31.c | 2 +- .../containers/sysvipc/check_ipcns_enabled.c | 14 +--- .../containers/utsname/check_utsns_enabled.c | 14 +--- .../kernel/controllers/cgroup/clone_platform.h | 34 ------- testcases/kernel/controllers/cgroup/test_6_2.c | 14 +--- testcases/kernel/fs/fs_bind/bin/Makefile | 10 +- testcases/kernel/fs/fs_bind/bin/nsclone.c | 19 +--- .../tests/execshare/selinux_execshare_parent.c | 18 +---- testcases/kernel/security/tomoyo/newns.c | 6 +- testcases/kernel/syscalls/clone/clone01.c | 11 +-- testcases/kernel/syscalls/clone/clone02.c | 13 +-- testcases/kernel/syscalls/clone/clone03.c | 10 +-- testcases/kernel/syscalls/clone/clone04.c | 14 +--- testcases/kernel/syscalls/clone/clone05.c | 11 +-- testcases/kernel/syscalls/clone/clone06.c | 11 +-- testcases/kernel/syscalls/clone/clone07.c | 13 +-- 29 files changed, 154 insertions(+), 254 deletions(-) create mode 100644 lib/cloner.c delete mode 100644 testcases/kernel/controllers/cgroup/clone_platform.h
include/test.h +10 -0
@@ -245,6 +245,16 @@ int tst_cwd_has_free(int required_kib);void maybe_run_child (void (*child)(),char *fmt, ...);int self_exec (char *argv0,char *fmt, ...); +/* +* Functions from lib/cloner.c +*/ +int ltp_clone (unsigned long clone_flags,int (*fn)(void *arg),void *arg, +int stack_size,void *stack); +int ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg), +void *arg,int stacksize); +int ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg), +void *arg); +#ifdef TST_USE_COMPAT16_SYSCALL #define TCID_BIT_SUFFIX "_16"#elif TST_USE_NEWER64_SYSCALL
lib/cloner.c new file +102 -0
102 lines not on this page · raw message
testcases/kernel/containers/libclone/libclone.c +1 -31
@@ -16,43 +16,13 @@***************************************************************************/ #include "libclone.h" -/* Serge: should I be passing in strings for error messages? */ - -int do_clone (unsigned long clone_flags, -int (*fn1)(void *arg),void *arg1) -{ -int ret; -int stack_size =getpagesize () *4 ; -void *stack =malloc (stack_size); - -if (!stack) { -perror ("malloc" ); -return -1 ; - } - -#if defined(__hppa__) - ret =clone (fn1, stack, clone_flags, arg1); -#elif defined(__ia64__) - ret =clone2 (fn1, stack, stack_size, clone_flags, arg1,NULL ,NULL ,NULL ); -#else - ret =clone (fn1, stack + stack_size, clone_flags, arg1); -#endif - -if (ret ==-1 ) { -perror ("clone" ); -free (stack); - } - -return ret; -} -int do_clone_tests (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1,int (*fn2)(void *arg),void *arg2) {int ret; - ret =do_clone (clone_flags |SIGCHLD , fn1, arg1); + ret =ltp_clone_quick (clone_flags |SIGCHLD , fn1, arg1);if (ret ==-1 ) {return -1 ;
testcases/kernel/containers/libclone/libclone.h +0 -13
@@ -55,16 +55,6 @@#define __NR_unshare SYS_unshare#endif -#if defined (__s390__) || (__s390x__) -#define clone __clone -extern int __clone (int (void *),void *,int ,void *); -#elif defined(__ia64__) -#define clone2 __clone2 -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif -#ifndef CLONE_NEWUTS #define CLONE_NEWUTS 0x04000000#endif
@@ -92,9 +82,6 @@ extern int create_net_namespace(char *, char *);* Fn2 may be NULL. */ -int do_clone (unsigned long clone_flags, -int (*fn1)(void *arg),void *arg1); -int do_clone_tests (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1,int (*fn2)(void *arg),void *arg2);
testcases/kernel/containers/libclone/libnetns.c +2 -17
@@ -61,35 +61,20 @@ int create_net_namespace(char *p1, char *c1)int pid, status =0 , ret;char *ltproot, *par;long int clone_flags =0 ; -int stack_size =getpagesize () *4 ; -void *childstack, *stack;if (tst_kvercmp (2 ,6 ,19 ) <0 )return 1 ; - stack =malloc (stack_size); -if (!stack) { -perror ("failled to malloc memory for stack..." ); -return -1 ; - } - childstack = stack + stack_size; - clone_flags |=CLONE_NEWNS ;/* Enable other namespaces too optionally */ #ifdef CLONE_NEWPID clone_flags |=CLONE_NEWPID ;#endif -#ifdef __ia64__ - pid =clone2 (child_fn, childstack,getpagesize (), clone_flags |SIGCHLD , - (void *)c1,NULL ,NULL ,NULL ); -#else - pid =clone (child_fn, childstack, clone_flags |SIGCHLD , (void *)c1); -#endif + pid =ltp_clone_quick (clone_flags, child_fn, (void *) c1);if (pid ==-1 ) { -perror ("Failled to do clone..." ); -free (stack); +perror ("Failed to do clone..." );return -1 ; }
testcases/kernel/containers/mqns/check_mqns_enabled.c +1 -1
@@ -46,7 +46,7 @@ int main()mq_close (mqd);mq_unlink ("/checkmqnsenabled" ); - pid =do_clone (CLONE_NEWIPC , dummy,NULL ); + pid =ltp_clone_quick (CLONE_NEWIPC , dummy,NULL );if (pid ==-1 )return 5 ;
testcases/kernel/containers/pidns/check_pidns_enabled.c +1 -1
@@ -59,7 +59,7 @@ int main()if (tst_kvercmp (2 ,6 ,24 ) <0 )return 1 ; - pid =do_clone (CLONE_NEWPID , dummy,NULL ); + pid =ltp_clone_quick (CLONE_NEWPID , dummy,NULL );/* Check for the clone function return value */ if (pid ==-1 )
testcases/kernel/containers/pidns/pidns12.c +1 -1
@@ -146,7 +146,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)." ,\strerror (errno));
testcases/kernel/containers/pidns/pidns13.c +2 -2
@@ -213,11 +213,11 @@ int main(int argc, char *argv[])/* Create container 1 */ *cinit_no =1 ; - cpid1 =do_clone (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no); + cpid1 =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no);/* Create container 2 */ *cinit_no =2 ; - cpid2 =do_clone (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no); + cpid2 =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no);if (cpid1 <0 || cpid2 <0 ) {tst_resm (TBROK ,"parent: clone() failed." );cleanup ();
testcases/kernel/containers/pidns/pidns16.c +1 -1
@@ -129,7 +129,7 @@ int main(int argc, char *argv[]) globalpid =getpid (); - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"clone() failed." );
testcases/kernel/containers/pidns/pidns20.c +1 -1
@@ -180,7 +180,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,\strerror (errno));
testcases/kernel/containers/pidns/pidns21.c +1 -1
@@ -182,7 +182,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,\strerror (errno));
testcases/kernel/containers/pidns/pidns30.c +1 -1
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])tst_resm (TINFO ,"parent: successfully created posix mqueue" );/* container creation on PID namespace */ - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,strerror (errno));cleanup (TBROK ,F_STEP_2 , mqd);
testcases/kernel/containers/pidns/pidns31.c +1 -1
@@ -269,7 +269,7 @@ int main(int argc, char *argv[])tst_resm (TINFO ,"parent: successfully created posix mqueue" );/* container creation on PID namespace */ - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,strerror (errno));cleanup (TBROK ,F_STEP_1 , mqd);
testcases/kernel/containers/sysvipc/check_ipcns_enabled.c +1 -13
@@ -26,24 +26,12 @@ int dummy(void *v) }int main () { -void *childstack, *stack;int pid;if (tst_kvercmp (2 ,6 ,19 ) <0 )return 1 ; - stack =malloc (getpagesize ()); -if (!stack) { -perror ("malloc" ); -return 2 ; - } - childstack = stack +getpagesize (); - -#ifdef __ia64__ - pid =clone2 (dummy, childstack,getpagesize (),CLONE_NEWIPC ,NULL ,NULL ,NULL ,NULL ); -#else - pid =clone (dummy, childstack,CLONE_NEWIPC ,NULL ); -#endif + pid =ltp_clone_quick (CLONE_NEWIPC , dummy,NULL );if (pid ==-1 )return 3 ;
testcases/kernel/containers/utsname/check_utsns_enabled.c +1 -13
@@ -61,25 +61,13 @@ int kernel_version_newenough()#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 (); -#ifdef __ia64__ - pid =clone2 (dummy, childstack,getpagesize (),CLONE_NEWUTS ,NULL ,NULL ,NULL ,NULL ); -#else - pid =clone (dummy, childstack,CLONE_NEWUTS ,NULL ); -#endif + pid =ltp_clone_quick (CLONE_NEWUTS , dummy,NULL );if (pid ==-1 )return 3 ;
testcases/kernel/controllers/cgroup/clone_platform.h deleted +0 -34
@@ -1,34 +0,0 @@ -/* -* Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., 59 -* Temple Place - Suite 330, Boston MA 02111-1307, USA. -* -*/ -/* Common platform specific defines for the clone system call tests */ - -//#define CHILD_STACK_SIZE 8192 -#define CHILD_STACK_SIZE 16384 - -#if defined (__s390__) || (__s390x__) -#define clone __clone -extern int __clone (int (void *),void *,int ,void *); -#elif defined(__ia64__) -#define clone2 __clone2 -/* Prototype provided by David Mosberger */ -/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */ -/* size_t child_stack_size, int flags, void *arg, */ -/* pid_t *parent_tid, void *tls, pid_t *child_tid) */ -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif
testcases/kernel/controllers/cgroup/test_6_2.c +1 -13
@@ -24,8 +24,6 @@#include <unistd.h> #include <sched.h> -#include "clone_platform.h" -#define DEFAULT_USEC 30000int foo (void __attribute__((unused)) *arg)
@@ -33,8 +31,6 @@ int foo(void __attribute__((unused)) *arg)return 0 ; } -char *stack[4096 ]; -int main (int argc,char **argv) {int usec =DEFAULT_USEC ;
@@ -44,15 +40,7 @@ int main(int argc, char **argv)while (1 ) {usleep (usec); -#if defined(__hppa__) -clone (foo, stack,CLONE_NEWNS ,NULL ); -#elif defined(__ia64__) -clone2 (foo, stack, -4096 ,CLONE_NEWNS ,NULL ,NULL ,NULL ,NULL ); -#else -clone - (foo, stack +4096 ,CLONE_NEWNS ,NULL ); -#endif +ltp_clone_quick (CLONE_NEWNS , foo,NULL ); }return 0 ;
testcases/kernel/fs/fs_bind/bin/Makefile +4 -6
@@ -2,10 +2,8 @@ LTP_SRC_ROOT=../../../../.. LTP_BIN=$(LTP_SRC_ROOT)/testcases/bin -#CFLAGS+= -I$(LTP_SRC_ROOT)/include -Wall -g -CFLAGS+= -Wall -g -#LIBS+= -L$(LTP_SRC_ROOT)/lib -lltp -LIBS+= +CFLAGS+= -I$(LTP_SRC_ROOT)/include -Wall -g +LIBS+= -L$(LTP_SRC_ROOT)/lib -lltp all: smount nsclone
@@ -19,10 +17,10 @@ uninstall: @/bin/true nsclone: nsclone.c - $(CC) $(CFLAGS) $(LIBS) -o nsclone nsclone.c + $(CC) $(CFLAGS) -o nsclone nsclone.c $(LIBS) smount: smount.c - $(CC) $(CFLAGS) $(LIBS) -o smount smount.c + $(CC) $(CFLAGS) -o smount smount.c clean: rm -f smount nsclone
testcases/kernel/fs/fs_bind/bin/nsclone.c +4 -15
@@ -22,18 +22,10 @@#include <sched.h> #include <signal.h> #include <unistd.h> +#include <test.h> #include <sys/types.h> #include <sys/wait.h> -#ifdef __ia64__ -#define clone2 __clone2 -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif - -char somemem[4096 ]; -int myfunc (void *arg){return system (arg); }
@@ -59,12 +51,9 @@ int main(int argc, char *argv[]) parent_cmd = (char *)strdup (argv[1 ]);printf ("1\n" ); -#ifdef __ia64__ -if (clone2 (myfunc, somemem,getpagesize (),CLONE_NEWNS |SIGCHLD , - child_cmd,NULL ,NULL ,NULL ) !=-1 ) { -#else -if (clone (myfunc, somemem,CLONE_NEWNS |SIGCHLD , child_cmd) !=-1 ) { -#endif + ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , myfunc, + (void *)child_cmd); +if (ret !=-1 ) {system (parent_cmd);wait (&childret); }else {
testcases/kernel/security/selinux-testsuite/tests/execshare/selinux_execshare_parent.c +1 -17
@@ -28,8 +28,6 @@ int clone_fn(char **argv)int main (int argc,char **argv) { -int pagesize; -void *clone_stack, *page;int pid, rc, len, status, cloneflags;security_context_t context_s;context_t context;
@@ -45,14 +43,6 @@ int main(int argc, char **argv)exit (-1 ); } - pagesize =getpagesize (); - page =malloc (pagesize); -if (!page) { -perror ("malloc" ); -exit (-1 ); - } - clone_stack = page + pagesize; - rc =getcon (&context_s);if (rc <0 ) {fprintf (stderr,"%s: unable to get my context\n" , argv[0 ]);
@@ -83,13 +73,7 @@ int main(int argc, char **argv)fprintf (stderr,"%s: unable to set exec context to %s\n" , argv[0 ], context_s);exit (-1 ); } -#if defined(__hppa__) - pid =clone (clone_fn, page, cloneflags |SIGCHLD , argv); -#elif defined(__ia64__) - pid =__clone2 (clone_fn, clone_stack, pagesize, cloneflags |SIGCHLD , argv,NULL ,NULL ,NULL ); -#else - pid =clone (clone_fn, clone_stack, cloneflags |SIGCHLD , argv); -#endif + pid =ltp_clone_quick (cloneflags |SIGCHLD , child_fn, argv);if (pid <0 ) {perror ("clone" );exit (-1 );
testcases/kernel/security/tomoyo/newns.c +3 -3
@@ -38,9 +38,9 @@ static int child(void *arg)int main (int argc,char *argv[]) {char c =0 ; -char *stack =malloc (8192 ); -const pid_t pid =clone (child, stack + (8192 /2 ),CLONE_NEWNS , - (void *) argv); +const pid_t pid; + + pid =ltp_clone_quick (CLONE_NEWNS , child, (void *) argv);while (waitpid (pid,NULL , __WALL) ==EOF && errno ==EINTR ) c++;/* Dummy. */ return 0 ;
testcases/kernel/syscalls/clone/clone01.c +2 -9
@@ -120,15 +120,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (do_child, child_stack,SIGCHLD ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (do_child, child_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (do_child, child_stack +CHILD_STACK_SIZE ,SIGCHLD ,NULL )); -#endif +TEST (ltp_clone (SIGCHLD , do_child,NULL ,CHILD_STACK_SIZE , + child_stack)); again:if ((child_pid =wait (&status)) ==-1 )
testcases/kernel/syscalls/clone/clone02.c +2 -11
@@ -190,17 +190,8 @@ int main(int ac, char **av) }/* Test the system call */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack, - test_cases[i].flags,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE , test_cases[i].flags,NULL , -NULL ,NULL ,NULL )); -#else -TEST (clone (child_fn, child_stack +CHILD_STACK_SIZE , - test_cases[i].flags,NULL )); -#endif +TEST (ltp_clone (test_cases[i].flags, child_fn,NULL , +CHILD_STACK_SIZE , child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/clone/clone03.c +2 -8
@@ -125,14 +125,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack,0 ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE ,0 ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone (child_fn, child_stack +CHILD_STACK_SIZE ,0 ,NULL )); -#endif +TEST (ltp_clone (0 , child_fn,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/clone/clone04.c +2 -12
@@ -133,18 +133,8 @@ int main(int ac, char **av)/* * call the system call with the TEST() macro */ -#if defined(__hppa__) -TEST (clone (test_cases[ind].child_fn, test_stack, -SIGCHLD ,NULL )); -#elif defined(__ia64__) - test_cases[ind].child_fn =NULL ; -TEST (clone2 (test_cases[ind].child_fn, test_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL , -NULL ,NULL ,NULL )); -#else -TEST (clone (test_cases[ind].child_fn, test_stack, -0 ,NULL )); -#endif +TEST (ltp_clone (0 ,test_cases[ind].child_fn,NULL , +CHILD_STACK_SIZE , test_stack));if ((TEST_RETURN ==-1 ) && (TEST_ERRNO == test_cases[ind].exp_errno)) {
testcases/kernel/syscalls/clone/clone05.c +2 -9
@@ -119,15 +119,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack,FLAG ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE ,FLAG ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (child_fn, child_stack +CHILD_STACK_SIZE ,FLAG ,NULL )); -#endif +TEST (ltp_clone (FLAG , child_fn,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code & parent_variable */ if ((TEST_RETURN !=-1 ) && (parent_variable)) {
testcases/kernel/syscalls/clone/clone06.c +2 -9
@@ -132,15 +132,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_environ, child_stack,0 ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_environ, child_stack, -CHILD_STACK_SIZE ,0 ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (child_environ, child_stack +CHILD_STACK_SIZE ,0 ,NULL )); -#endif +TEST (ltp_clone (0 , child_environ,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/clone/clone07.c +2 -11
@@ -126,17 +126,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) - child_pid =clone (do_child, child_stack,SIGCHLD ,NULL ); -#elif defined(__ia64__) - child_pid =clone2 (do_child, child_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL , -NULL ,NULL ,NULL ); -#else - child_pid = - (clone - (do_child, child_stack +CHILD_STACK_SIZE ,SIGCHLD ,NULL )); -#endif + child_pid =ltp_clone (SIGCHLD , do_child,NULL , +CHILD_STACK_SIZE , child_stack);wait (NULL );free (child_stack); }/* End for TEST_LOOPING */
Signature · 13 lines
1.6.1.1 ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 3 lines · On Tuesday 29 September 2009 19:30:15 Serge E. Hallyn wrote:
Define
ltp_clone()andltp_clone_malloc()in libltp, and convert existing clone usages to them. (clone04 can't use it bc it wants to pass NULL, whichltp_clone()will for many arches convert to NULL+stacksize-1).
i thought you fixed the clone04 issue ?
include/test.h int tst_cwd_has_free(int required_kib); · line 252
Quoted 2 lines
include/test.h +2
-0+int ltp_clone (unsigned long clone_flags,int (*fn)(void *arg),void *arg, +int stack_size,void *stack);
change stack_size to size_t to match malloc()
lib/cloner.c line 39
Quoted 6 lines
lib/cloner.c new file +6
-0+/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */ +/* size_t child_stack_size, int flags, void *arg, */ +/* pid_t *parent_tid, void *tls, pid_t *child_tid) */ +extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, +size_t child_stack_size,int flags,void *arg, +pid_t *parent_tid,void *tls,pid_t *child_tid);
what's with the big commented prototype ? just scrub it ...
Quoted 1 line
+ * 1. hppa takes bottom of stack and no stacksize
note that it's because their stack grows up
Quoted 1 line
+ * 3. all others take top of stack,
note that it's because their stack grows down
otherwise, all the changes look straight forward. thanks again. -mike
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 6 lines · Mike Frysinger
Quoted 3 lines · On Tuesday 29 September 2009 19:30:15 Serge E. Hallyn wrote:
Define
ltp_clone()andltp_clone_malloc()in libltp, and convert existing clone usages to them. (clone04 can't use it bc it wants to pass NULL, whichltp_clone()will for many arches convert to NULL+stacksize-1).i thought you fixed the clone04 issue ?
Gah. That's what i get for just wanting to get the thing out. Here is a new version.
thanks,
-serge
From fbbd57c760776307a462a58a31bdf106502ae2e6 Mon Sep 17 00:00:00 2001
From: Serge E. Hallyn <[email protected]>
Date: Mon, 21 Sep 2009 12:10:12 -0400
Subject: [PATCH 1/1] define and use common clone helpers (v3)
Define ltp_clone() and ltp_clone_malloc() in libltp, and convert existing clone usages to them.
Changelog:
Sep 29: [suggested by Mike Frysinger <[email protected]>]
1. rename ltp_clone_malloc ltp_clone_quick, and have ltp_clone_malloc take stacksize from caller. [ no i couldn't think of a better name than 'quick' ]
2. have ltp_clone() accept a NULL stack
3. convert clone04 testcase
4. save errno over free on failure
5. don't perror
6. change order of ltp_clone* arguments so first n arguments are always consistent.
7. (v3) pass size_t instead of int to malloc
--- include/test.h | 10 ++ lib/cloner.c | 99 ++++++++++++++++++++ testcases/kernel/containers/libclone/libclone.c | 32 +------ testcases/kernel/containers/libclone/libclone.h | 13 --- testcases/kernel/containers/libclone/libnetns.c | 19 +---- .../kernel/containers/mqns/check_mqns_enabled.c | 2 +- .../kernel/containers/pidns/check_pidns_enabled.c | 2 +- testcases/kernel/containers/pidns/pidns12.c | 2 +- testcases/kernel/containers/pidns/pidns13.c | 4 +- testcases/kernel/containers/pidns/pidns16.c | 2 +- testcases/kernel/containers/pidns/pidns20.c | 2 +- testcases/kernel/containers/pidns/pidns21.c | 2 +- testcases/kernel/containers/pidns/pidns30.c | 2 +- testcases/kernel/containers/pidns/pidns31.c | 2 +- .../containers/sysvipc/check_ipcns_enabled.c | 14 +--- .../containers/utsname/check_utsns_enabled.c | 14 +--- .../kernel/controllers/cgroup/clone_platform.h | 34 ------- testcases/kernel/controllers/cgroup/test_6_2.c | 14 +--- testcases/kernel/fs/fs_bind/bin/Makefile | 10 +- testcases/kernel/fs/fs_bind/bin/nsclone.c | 19 +--- .../tests/execshare/selinux_execshare_parent.c | 18 +---- testcases/kernel/security/tomoyo/newns.c | 6 +- testcases/kernel/syscalls/clone/clone01.c | 11 +-- testcases/kernel/syscalls/clone/clone02.c | 13 +-- testcases/kernel/syscalls/clone/clone03.c | 10 +-- testcases/kernel/syscalls/clone/clone04.c | 14 +--- testcases/kernel/syscalls/clone/clone05.c | 11 +-- testcases/kernel/syscalls/clone/clone06.c | 11 +-- testcases/kernel/syscalls/clone/clone07.c | 13 +-- 29 files changed, 151 insertions(+), 254 deletions(-) create mode 100644 lib/cloner.c delete mode 100644 testcases/kernel/controllers/cgroup/clone_platform.h
include/test.h +10 -0
@@ -245,6 +245,16 @@ int tst_cwd_has_free(int required_kib);void maybe_run_child (void (*child)(),char *fmt, ...);int self_exec (char *argv0,char *fmt, ...); +/* +* Functions from lib/cloner.c +*/ +int ltp_clone (unsigned long clone_flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack); +int ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg), +void *arg,size_t stacksize); +int ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg), +void *arg); +#ifdef TST_USE_COMPAT16_SYSCALL #define TCID_BIT_SUFFIX "_16"#elif TST_USE_NEWER64_SYSCALL
lib/cloner.c new file +99 -0
99 lines not on this page · raw message
testcases/kernel/containers/libclone/libclone.c +1 -31
@@ -16,43 +16,13 @@***************************************************************************/ #include "libclone.h" -/* Serge: should I be passing in strings for error messages? */ - -int do_clone (unsigned long clone_flags, -int (*fn1)(void *arg),void *arg1) -{ -int ret; -int stack_size =getpagesize () *4 ; -void *stack =malloc (stack_size); - -if (!stack) { -perror ("malloc" ); -return -1 ; - } - -#if defined(__hppa__) - ret =clone (fn1, stack, clone_flags, arg1); -#elif defined(__ia64__) - ret =clone2 (fn1, stack, stack_size, clone_flags, arg1,NULL ,NULL ,NULL ); -#else - ret =clone (fn1, stack + stack_size, clone_flags, arg1); -#endif - -if (ret ==-1 ) { -perror ("clone" ); -free (stack); - } - -return ret; -} -int do_clone_tests (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1,int (*fn2)(void *arg),void *arg2) {int ret; - ret =do_clone (clone_flags |SIGCHLD , fn1, arg1); + ret =ltp_clone_quick (clone_flags |SIGCHLD , fn1, arg1);if (ret ==-1 ) {return -1 ;
testcases/kernel/containers/libclone/libclone.h +0 -13
@@ -55,16 +55,6 @@#define __NR_unshare SYS_unshare#endif -#if defined (__s390__) || (__s390x__) -#define clone __clone -extern int __clone (int (void *),void *,int ,void *); -#elif defined(__ia64__) -#define clone2 __clone2 -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif -#ifndef CLONE_NEWUTS #define CLONE_NEWUTS 0x04000000#endif
@@ -92,9 +82,6 @@ extern int create_net_namespace(char *, char *);* Fn2 may be NULL. */ -int do_clone (unsigned long clone_flags, -int (*fn1)(void *arg),void *arg1); -int do_clone_tests (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1,int (*fn2)(void *arg),void *arg2);
testcases/kernel/containers/libclone/libnetns.c +2 -17
@@ -61,35 +61,20 @@ int create_net_namespace(char *p1, char *c1)int pid, status =0 , ret;char *ltproot, *par;long int clone_flags =0 ; -int stack_size =getpagesize () *4 ; -void *childstack, *stack;if (tst_kvercmp (2 ,6 ,19 ) <0 )return 1 ; - stack =malloc (stack_size); -if (!stack) { -perror ("failled to malloc memory for stack..." ); -return -1 ; - } - childstack = stack + stack_size; - clone_flags |=CLONE_NEWNS ;/* Enable other namespaces too optionally */ #ifdef CLONE_NEWPID clone_flags |=CLONE_NEWPID ;#endif -#ifdef __ia64__ - pid =clone2 (child_fn, childstack,getpagesize (), clone_flags |SIGCHLD , - (void *)c1,NULL ,NULL ,NULL ); -#else - pid =clone (child_fn, childstack, clone_flags |SIGCHLD , (void *)c1); -#endif + pid =ltp_clone_quick (clone_flags, child_fn, (void *) c1);if (pid ==-1 ) { -perror ("Failled to do clone..." ); -free (stack); +perror ("Failed to do clone..." );return -1 ; }
testcases/kernel/containers/mqns/check_mqns_enabled.c +1 -1
@@ -46,7 +46,7 @@ int main()mq_close (mqd);mq_unlink ("/checkmqnsenabled" ); - pid =do_clone (CLONE_NEWIPC , dummy,NULL ); + pid =ltp_clone_quick (CLONE_NEWIPC , dummy,NULL );if (pid ==-1 )return 5 ;
testcases/kernel/containers/pidns/check_pidns_enabled.c +1 -1
@@ -59,7 +59,7 @@ int main()if (tst_kvercmp (2 ,6 ,24 ) <0 )return 1 ; - pid =do_clone (CLONE_NEWPID , dummy,NULL ); + pid =ltp_clone_quick (CLONE_NEWPID , dummy,NULL );/* Check for the clone function return value */ if (pid ==-1 )
testcases/kernel/containers/pidns/pidns12.c +1 -1
@@ -146,7 +146,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)." ,\strerror (errno));
testcases/kernel/containers/pidns/pidns13.c +2 -2
@@ -213,11 +213,11 @@ int main(int argc, char *argv[])/* Create container 1 */ *cinit_no =1 ; - cpid1 =do_clone (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no); + cpid1 =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no);/* Create container 2 */ *cinit_no =2 ; - cpid2 =do_clone (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no); + cpid2 =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no);if (cpid1 <0 || cpid2 <0 ) {tst_resm (TBROK ,"parent: clone() failed." );cleanup ();
testcases/kernel/containers/pidns/pidns16.c +1 -1
@@ -129,7 +129,7 @@ int main(int argc, char *argv[]) globalpid =getpid (); - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"clone() failed." );
testcases/kernel/containers/pidns/pidns20.c +1 -1
@@ -180,7 +180,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,\strerror (errno));
testcases/kernel/containers/pidns/pidns21.c +1 -1
@@ -182,7 +182,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,\strerror (errno));
testcases/kernel/containers/pidns/pidns30.c +1 -1
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])tst_resm (TINFO ,"parent: successfully created posix mqueue" );/* container creation on PID namespace */ - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,strerror (errno));cleanup (TBROK ,F_STEP_2 , mqd);
testcases/kernel/containers/pidns/pidns31.c +1 -1
@@ -269,7 +269,7 @@ int main(int argc, char *argv[])tst_resm (TINFO ,"parent: successfully created posix mqueue" );/* container creation on PID namespace */ - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,strerror (errno));cleanup (TBROK ,F_STEP_1 , mqd);
testcases/kernel/containers/sysvipc/check_ipcns_enabled.c +1 -13
@@ -26,24 +26,12 @@ int dummy(void *v) }int main () { -void *childstack, *stack;int pid;if (tst_kvercmp (2 ,6 ,19 ) <0 )return 1 ; - stack =malloc (getpagesize ()); -if (!stack) { -perror ("malloc" ); -return 2 ; - } - childstack = stack +getpagesize (); - -#ifdef __ia64__ - pid =clone2 (dummy, childstack,getpagesize (),CLONE_NEWIPC ,NULL ,NULL ,NULL ,NULL ); -#else - pid =clone (dummy, childstack,CLONE_NEWIPC ,NULL ); -#endif + pid =ltp_clone_quick (CLONE_NEWIPC , dummy,NULL );if (pid ==-1 )return 3 ;
testcases/kernel/containers/utsname/check_utsns_enabled.c +1 -13
@@ -61,25 +61,13 @@ int kernel_version_newenough()#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 (); -#ifdef __ia64__ - pid =clone2 (dummy, childstack,getpagesize (),CLONE_NEWUTS ,NULL ,NULL ,NULL ,NULL ); -#else - pid =clone (dummy, childstack,CLONE_NEWUTS ,NULL ); -#endif + pid =ltp_clone_quick (CLONE_NEWUTS , dummy,NULL );if (pid ==-1 )return 3 ;
testcases/kernel/controllers/cgroup/clone_platform.h deleted +0 -34
@@ -1,34 +0,0 @@ -/* -* Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., 59 -* Temple Place - Suite 330, Boston MA 02111-1307, USA. -* -*/ -/* Common platform specific defines for the clone system call tests */ - -//#define CHILD_STACK_SIZE 8192 -#define CHILD_STACK_SIZE 16384 - -#if defined (__s390__) || (__s390x__) -#define clone __clone -extern int __clone (int (void *),void *,int ,void *); -#elif defined(__ia64__) -#define clone2 __clone2 -/* Prototype provided by David Mosberger */ -/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */ -/* size_t child_stack_size, int flags, void *arg, */ -/* pid_t *parent_tid, void *tls, pid_t *child_tid) */ -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif
testcases/kernel/controllers/cgroup/test_6_2.c +1 -13
@@ -24,8 +24,6 @@#include <unistd.h> #include <sched.h> -#include "clone_platform.h" -#define DEFAULT_USEC 30000int foo (void __attribute__((unused)) *arg)
@@ -33,8 +31,6 @@ int foo(void __attribute__((unused)) *arg)return 0 ; } -char *stack[4096 ]; -int main (int argc,char **argv) {int usec =DEFAULT_USEC ;
@@ -44,15 +40,7 @@ int main(int argc, char **argv)while (1 ) {usleep (usec); -#if defined(__hppa__) -clone (foo, stack,CLONE_NEWNS ,NULL ); -#elif defined(__ia64__) -clone2 (foo, stack, -4096 ,CLONE_NEWNS ,NULL ,NULL ,NULL ,NULL ); -#else -clone - (foo, stack +4096 ,CLONE_NEWNS ,NULL ); -#endif +ltp_clone_quick (CLONE_NEWNS , foo,NULL ); }return 0 ;
testcases/kernel/fs/fs_bind/bin/Makefile +4 -6
@@ -2,10 +2,8 @@ LTP_SRC_ROOT=../../../../.. LTP_BIN=$(LTP_SRC_ROOT)/testcases/bin -#CFLAGS+= -I$(LTP_SRC_ROOT)/include -Wall -g -CFLAGS+= -Wall -g -#LIBS+= -L$(LTP_SRC_ROOT)/lib -lltp -LIBS+= +CFLAGS+= -I$(LTP_SRC_ROOT)/include -Wall -g +LIBS+= -L$(LTP_SRC_ROOT)/lib -lltp all: smount nsclone
@@ -19,10 +17,10 @@ uninstall: @/bin/true nsclone: nsclone.c - $(CC) $(CFLAGS) $(LIBS) -o nsclone nsclone.c + $(CC) $(CFLAGS) -o nsclone nsclone.c $(LIBS) smount: smount.c - $(CC) $(CFLAGS) $(LIBS) -o smount smount.c + $(CC) $(CFLAGS) -o smount smount.c clean: rm -f smount nsclone
testcases/kernel/fs/fs_bind/bin/nsclone.c +4 -15
@@ -22,18 +22,10 @@#include <sched.h> #include <signal.h> #include <unistd.h> +#include <test.h> #include <sys/types.h> #include <sys/wait.h> -#ifdef __ia64__ -#define clone2 __clone2 -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif - -char somemem[4096 ]; -int myfunc (void *arg){return system (arg); }
@@ -59,12 +51,9 @@ int main(int argc, char *argv[]) parent_cmd = (char *)strdup (argv[1 ]);printf ("1\n" ); -#ifdef __ia64__ -if (clone2 (myfunc, somemem,getpagesize (),CLONE_NEWNS |SIGCHLD , - child_cmd,NULL ,NULL ,NULL ) !=-1 ) { -#else -if (clone (myfunc, somemem,CLONE_NEWNS |SIGCHLD , child_cmd) !=-1 ) { -#endif + ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , myfunc, + (void *)child_cmd); +if (ret !=-1 ) {system (parent_cmd);wait (&childret); }else {
testcases/kernel/security/selinux-testsuite/tests/execshare/selinux_execshare_parent.c +1 -17
@@ -28,8 +28,6 @@ int clone_fn(char **argv)int main (int argc,char **argv) { -int pagesize; -void *clone_stack, *page;int pid, rc, len, status, cloneflags;security_context_t context_s;context_t context;
@@ -45,14 +43,6 @@ int main(int argc, char **argv)exit (-1 ); } - pagesize =getpagesize (); - page =malloc (pagesize); -if (!page) { -perror ("malloc" ); -exit (-1 ); - } - clone_stack = page + pagesize; - rc =getcon (&context_s);if (rc <0 ) {fprintf (stderr,"%s: unable to get my context\n" , argv[0 ]);
@@ -83,13 +73,7 @@ int main(int argc, char **argv)fprintf (stderr,"%s: unable to set exec context to %s\n" , argv[0 ], context_s);exit (-1 ); } -#if defined(__hppa__) - pid =clone (clone_fn, page, cloneflags |SIGCHLD , argv); -#elif defined(__ia64__) - pid =__clone2 (clone_fn, clone_stack, pagesize, cloneflags |SIGCHLD , argv,NULL ,NULL ,NULL ); -#else - pid =clone (clone_fn, clone_stack, cloneflags |SIGCHLD , argv); -#endif + pid =ltp_clone_quick (cloneflags |SIGCHLD , child_fn, argv);if (pid <0 ) {perror ("clone" );exit (-1 );
testcases/kernel/security/tomoyo/newns.c +3 -3
@@ -38,9 +38,9 @@ static int child(void *arg)int main (int argc,char *argv[]) {char c =0 ; -char *stack =malloc (8192 ); -const pid_t pid =clone (child, stack + (8192 /2 ),CLONE_NEWNS , - (void *) argv); +const pid_t pid; + + pid =ltp_clone_quick (CLONE_NEWNS , child, (void *) argv);while (waitpid (pid,NULL , __WALL) ==EOF && errno ==EINTR ) c++;/* Dummy. */ return 0 ;
testcases/kernel/syscalls/clone/clone01.c +2 -9
@@ -120,15 +120,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (do_child, child_stack,SIGCHLD ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (do_child, child_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (do_child, child_stack +CHILD_STACK_SIZE ,SIGCHLD ,NULL )); -#endif +TEST (ltp_clone (SIGCHLD , do_child,NULL ,CHILD_STACK_SIZE , + child_stack)); again:if ((child_pid =wait (&status)) ==-1 )
testcases/kernel/syscalls/clone/clone02.c +2 -11
@@ -190,17 +190,8 @@ int main(int ac, char **av) }/* Test the system call */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack, - test_cases[i].flags,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE , test_cases[i].flags,NULL , -NULL ,NULL ,NULL )); -#else -TEST (clone (child_fn, child_stack +CHILD_STACK_SIZE , - test_cases[i].flags,NULL )); -#endif +TEST (ltp_clone (test_cases[i].flags, child_fn,NULL , +CHILD_STACK_SIZE , child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/clone/clone03.c +2 -8
@@ -125,14 +125,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack,0 ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE ,0 ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone (child_fn, child_stack +CHILD_STACK_SIZE ,0 ,NULL )); -#endif +TEST (ltp_clone (0 , child_fn,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/clone/clone04.c +2 -12
@@ -133,18 +133,8 @@ int main(int ac, char **av)/* * call the system call with the TEST() macro */ -#if defined(__hppa__) -TEST (clone (test_cases[ind].child_fn, test_stack, -SIGCHLD ,NULL )); -#elif defined(__ia64__) - test_cases[ind].child_fn =NULL ; -TEST (clone2 (test_cases[ind].child_fn, test_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL , -NULL ,NULL ,NULL )); -#else -TEST (clone (test_cases[ind].child_fn, test_stack, -0 ,NULL )); -#endif +TEST (ltp_clone (0 ,test_cases[ind].child_fn,NULL , +CHILD_STACK_SIZE , test_stack));if ((TEST_RETURN ==-1 ) && (TEST_ERRNO == test_cases[ind].exp_errno)) {
testcases/kernel/syscalls/clone/clone05.c +2 -9
@@ -119,15 +119,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack,FLAG ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE ,FLAG ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (child_fn, child_stack +CHILD_STACK_SIZE ,FLAG ,NULL )); -#endif +TEST (ltp_clone (FLAG , child_fn,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code & parent_variable */ if ((TEST_RETURN !=-1 ) && (parent_variable)) {
testcases/kernel/syscalls/clone/clone06.c +2 -9
@@ -132,15 +132,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_environ, child_stack,0 ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_environ, child_stack, -CHILD_STACK_SIZE ,0 ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (child_environ, child_stack +CHILD_STACK_SIZE ,0 ,NULL )); -#endif +TEST (ltp_clone (0 , child_environ,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {
testcases/kernel/syscalls/clone/clone07.c +2 -11
@@ -126,17 +126,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) - child_pid =clone (do_child, child_stack,SIGCHLD ,NULL ); -#elif defined(__ia64__) - child_pid =clone2 (do_child, child_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL , -NULL ,NULL ,NULL ); -#else - child_pid = - (clone - (do_child, child_stack +CHILD_STACK_SIZE ,SIGCHLD ,NULL )); -#endif + child_pid =ltp_clone (SIGCHLD , do_child,NULL , +CHILD_STACK_SIZE , child_stack);wait (NULL );free (child_stack); }/* End for TEST_LOOPING */
Signature · 13 lines
1.6.1.1 ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 10 lines · Serge E. Hallyn
Quoted 6 lines · Mike Frysinger
Quoted 3 lines · On Tuesday 29 September 2009 19:30:15 Serge E. Hallyn wrote:
Define
ltp_clone()andltp_clone_malloc()in libltp, and convert existing clone usages to them. (clone04 can't use it bc it wants to pass NULL, whichltp_clone()will for many arches convert to NULL+stacksize-1).i thought you fixed the clone04 issue ?
Gah. That's what i get for just wanting to get the thing out. Here is a new version.
Sorry for being not in action for long. Garret made lot of changes for his Makefile enhancements and lot of files from the containers directory are missing. This patch fails to apply hence:
patching file include/test.h
patching file lib/cloner.c
patching file testcases/kernel/containers/libclone/libclone.c patching file testcases/kernel/containers/libclone/libclone.h can't find file to patch at input line 395
Perhaps you used the wrong -p or --strip option? The text leading up to this was:
--------------------------
|diff --git a/testcases/kernel/containers/libclone/libnetns.c b/testcases/kernel/containers/libclone/libnetns.c
|index 821fec1..e4def81 100644 |--- a/testcases/kernel/containers/libclone/libnetns.c |+++ b/testcases/kernel/containers/libclone/libnetns.c
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 437
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/testcases/kernel/containers/mqns/check_mqns_enabled.c b/testcases/kernel/containers/mqns/check_mqns_enabled.c
|index 169e8c9..45cc6fe 100644 |--- a/testcases/kernel/containers/mqns/check_mqns_enabled.c |+++ b/testcases/kernel/containers/mqns/check_mqns_enabled.c
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 450
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/testcases/kernel/containers/pidns/check_pidns_enabled.c b/testcases/kernel/containers/pidns/check_pidns_enabled.c
|index 209dbb3..e217b47 100644 |--- a/testcases/kernel/containers/pidns/check_pidns_enabled.c |+++ b/testcases/kernel/containers/pidns/check_pidns_enabled.c
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
patching file testcases/kernel/containers/pidns/pidns12.c
patching file testcases/kernel/containers/pidns/pidns13.c
patching file testcases/kernel/containers/pidns/pidns16.c
patching file testcases/kernel/containers/pidns/pidns20.c
patching file testcases/kernel/containers/pidns/pidns21.c
patching file testcases/kernel/containers/pidns/pidns30.c
patching file testcases/kernel/containers/pidns/pidns31.c
patching file testcases/kernel/containers/sysvipc/check_ipcns_enabled.c patching file testcases/kernel/containers/utsname/check_utsns_enabled.c patching file testcases/kernel/controllers/cgroup/clone_platform.h patching file testcases/kernel/controllers/cgroup/test_6_2.c
patching file testcases/kernel/fs/fs_bind/bin/Makefile
Hunk #1 FAILED at 2.
Hunk #2 FAILED at 17.
2 out of 2 hunks FAILED -- saving rejects to file testcases/kernel/fs/fs_bind/bin/Makefile.rej
patching file testcases/kernel/fs/fs_bind/bin/nsclone.c
patching file testcases/kernel/security/selinux-testsuite/tests/execshare/selinux_execshare_parent.c patching file testcases/kernel/security/tomoyo/newns.c
patching file testcases/kernel/syscalls/clone/clone01.c
patching file testcases/kernel/syscalls/clone/clone02.c
patching file testcases/kernel/syscalls/clone/clone03.c
patching file testcases/kernel/syscalls/clone/clone04.c
patching file testcases/kernel/syscalls/clone/clone05.c
patching file testcases/kernel/syscalls/clone/clone06.c
patching file testcases/kernel/syscalls/clone/clone07.c
Could you please resend this over Garretś new source code from LTP CVS ?
Regards--
Subrata
Quoted 850 lines
thanks,
-sergeQuoted 1 line
From
fbbd57c760776307a462a58a31bdf106502ae2e6Mon Sep 17 00:00:00 2001From: Serge E. Hallyn <[email protected]>
Date: Mon, 21 Sep 2009 12:10:12 -0400
Subject: [PATCH 1/1] define and use common clone helpers (v3)Define
ltp_clone()andltp_clone_malloc()in libltp, and convert existing clone usages to them.Changelog:
Sep 29: [suggested by Mike Frysinger <[email protected]>]
1. renameltp_clone_mallocltp_clone_quick, and haveltp_clone_malloctake stacksize from caller. [ no i couldn't think of a better name than 'quick' ]
2. haveltp_clone()accept a NULL stack
3. convert clone04 testcase
4. save errno over free on failure
5. don't perror
6. change order of ltp_clone* arguments so first n arguments are always consistent.
7. (v3) passsize_tinstead of int to mallocSigned-off-by Serge E. Hallyn <[email protected]>--- include/test.h | 10 ++ lib/cloner.c | 99 ++++++++++++++++++++ testcases/kernel/containers/libclone/libclone.c | 32 +------ testcases/kernel/containers/libclone/libclone.h | 13 --- testcases/kernel/containers/libclone/libnetns.c | 19 +---- .../kernel/containers/mqns/check_mqns_enabled.c | 2 +- .../kernel/containers/pidns/check_pidns_enabled.c | 2 +- testcases/kernel/containers/pidns/pidns12.c | 2 +- testcases/kernel/containers/pidns/pidns13.c | 4 +- testcases/kernel/containers/pidns/pidns16.c | 2 +- testcases/kernel/containers/pidns/pidns20.c | 2 +- testcases/kernel/containers/pidns/pidns21.c | 2 +- testcases/kernel/containers/pidns/pidns30.c | 2 +- testcases/kernel/containers/pidns/pidns31.c | 2 +- .../containers/sysvipc/check_ipcns_enabled.c | 14 +--- .../containers/utsname/check_utsns_enabled.c | 14 +--- .../kernel/controllers/cgroup/clone_platform.h | 34 ------- testcases/kernel/controllers/cgroup/test_6_2.c | 14 +--- testcases/kernel/fs/fs_bind/bin/Makefile | 10 +- testcases/kernel/fs/fs_bind/bin/nsclone.c | 19 +--- .../tests/execshare/selinux_execshare_parent.c | 18 +---- testcases/kernel/security/tomoyo/newns.c | 6 +- testcases/kernel/syscalls/clone/clone01.c | 11 +-- testcases/kernel/syscalls/clone/clone02.c | 13 +-- testcases/kernel/syscalls/clone/clone03.c | 10 +-- testcases/kernel/syscalls/clone/clone04.c | 14 +--- testcases/kernel/syscalls/clone/clone05.c | 11 +-- testcases/kernel/syscalls/clone/clone06.c | 11 +-- testcases/kernel/syscalls/clone/clone07.c | 13 +-- 29 files changed, 151 insertions(+), 254 deletions(-) create mode 100644 lib/cloner.c delete mode 100644 testcases/kernel/controllers/cgroup/clone_platform.hinclude/test.h +10
-0@@ -245,6 +245,16 @@ int tst_cwd_has_free(int required_kib);void maybe_run_child (void (*child)(),char *fmt, ...);int self_exec (char *argv0,char *fmt, ...); +/* +* Functions from lib/cloner.c +*/ +int ltp_clone (unsigned long clone_flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack); +int ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg), +void *arg,size_t stacksize); +int ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg), +void *arg); +#ifdef TST_USE_COMPAT16_SYSCALL #define TCID_BIT_SUFFIX "_16"#elif TST_USE_NEWER64_SYSCALL lib/cloner.c new file +99
-0@@ -0,0 +1,99 @@ +/* +* Copyright (c) International Business Machines Corp., 2009 +* Some wrappers for clone functionality. Thrown together by Serge Hallyn +* <[email protected]> based on existing clone usage in ltp. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> /* fork, getpid, sleep */ +#include <string.h> +#include <stdlib.h> /* exit */ +#include "test.h" + +/* copied from several other files under ltp */ +#if defined (__s390__) || (__s390x__) +#define clone __clone +extern int __clone (int (void *),void *,int ,void *); +#elif defined(__ia64__) +#define clone2 __clone2 +/* Prototype provided by David Mosberger */ +extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, +size_t child_stack_size,int flags,void *arg, +pid_t *parent_tid,void *tls,pid_t *child_tid); +#endif +/*********************************************************************** +* ltp_clone: wrapper for clone to hide the architecture dependencies. +* 1. hppa takes bottom of stack and no stacksize (stack grows up) +* 2. __ia64__ takes bottom of stack and uses clone2 +* 3. all others take top of stack (stack grows down) +***********************************************************************/ +int +ltp_clone (unsigned long clone_flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack) +{ +int ret; + +#if defined(__hppa__) + ret =clone (fn, stack, clone_flags, arg); +#elif defined(__ia64__) + ret =clone2 (fn, stack, stack_size, clone_flags, arg,NULL ,NULL ,NULL ); +#else + ret =clone (fn, (stack ? stack + stack_size -1 :NULL ), + clone_flags, arg); +#endif + +return ret; +} + +/*********************************************************************** +* ltp_clone_malloc: also does the memory allocation for clone with a +* caller-specified size. +***********************************************************************/ +int +ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg),void *arg, +size_t stack_size) +{ +int ret; +void *stack =malloc (stack_size); +int saved_errno; + +if (!stack) +return -1 ; + + ret =ltp_clone (clone_flags, fn, arg, stack_size, stack); + +if (ret ==-1 ) { + saved_errno = errno; +free (stack); + errno = saved_errno; + } + +return ret; +} + +/*********************************************************************** +* ltp_clone_quick: calls ltp_clone_malloc with predetermined stack size. +* Experience thus far suggests that one page is often insufficient, +* while 4*getpagesize() seems adequate. +***********************************************************************/ +int +ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg),void *arg) +{ +size_t stack_size =getpagesize () *4 ; + +return ltp_clone_malloc (clone_flags, fn, arg, stack_size); +}testcases/kernel/containers/libclone/libclone.c +1
-31@@ -16,43 +16,13 @@***************************************************************************/ #include "libclone.h" -/* Serge: should I be passing in strings for error messages? */ - -int do_clone (unsigned long clone_flags, -int (*fn1)(void *arg),void *arg1) -{ -int ret; -int stack_size =getpagesize () *4 ; -void *stack =malloc (stack_size); - -if (!stack) { -perror ("malloc" ); -return -1 ; - } - -#if defined(__hppa__) - ret =clone (fn1, stack, clone_flags, arg1); -#elif defined(__ia64__) - ret =clone2 (fn1, stack, stack_size, clone_flags, arg1,NULL ,NULL ,NULL ); -#else - ret =clone (fn1, stack + stack_size, clone_flags, arg1); -#endif - -if (ret ==-1 ) { -perror ("clone" ); -free (stack); - } - -return ret; -} -int do_clone_tests (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1,int (*fn2)(void *arg),void *arg2) {int ret; - ret =do_clone (clone_flags |SIGCHLD , fn1, arg1); + ret =ltp_clone_quick (clone_flags |SIGCHLD , fn1, arg1);if (ret ==-1 ) {return -1 ;testcases/kernel/containers/libclone/libclone.h +0
-13@@ -55,16 +55,6 @@#define __NR_unshare SYS_unshare#endif -#if defined (__s390__) || (__s390x__) -#define clone __clone -extern int __clone (int (void *),void *,int ,void *); -#elif defined(__ia64__) -#define clone2 __clone2 -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif -#ifndef CLONE_NEWUTS #define CLONE_NEWUTS 0x04000000#endif @@ -92,9 +82,6 @@ extern int create_net_namespace(char *, char *);* Fn2 may be NULL. */ -int do_clone (unsigned long clone_flags, -int (*fn1)(void *arg),void *arg1); -int do_clone_tests (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1,int (*fn2)(void *arg),void *arg2);testcases/kernel/containers/libclone/libnetns.c +2
-17@@ -61,35 +61,20 @@ int create_net_namespace(char *p1, char *c1)int pid, status =0 , ret;char *ltproot, *par;long int clone_flags =0 ; -int stack_size =getpagesize () *4 ; -void *childstack, *stack;if (tst_kvercmp (2 ,6 ,19 ) <0 )return 1 ; - stack =malloc (stack_size); -if (!stack) { -perror ("failled to malloc memory for stack..." ); -return -1 ; - } - childstack = stack + stack_size; - clone_flags |=CLONE_NEWNS ;/* Enable other namespaces too optionally */ #ifdef CLONE_NEWPID clone_flags |=CLONE_NEWPID ;#endif -#ifdef __ia64__ - pid =clone2 (child_fn, childstack,getpagesize (), clone_flags |SIGCHLD , - (void *)c1,NULL ,NULL ,NULL ); -#else - pid =clone (child_fn, childstack, clone_flags |SIGCHLD , (void *)c1); -#endif + pid =ltp_clone_quick (clone_flags, child_fn, (void *) c1);if (pid ==-1 ) { -perror ("Failled to do clone..." ); -free (stack); +perror ("Failed to do clone..." );return -1 ; }testcases/kernel/containers/mqns/check_mqns_enabled.c +1
-1@@ -46,7 +46,7 @@ int main()mq_close (mqd);mq_unlink ("/checkmqnsenabled" ); - pid =do_clone (CLONE_NEWIPC , dummy,NULL ); + pid =ltp_clone_quick (CLONE_NEWIPC , dummy,NULL );if (pid ==-1 )return 5 ;testcases/kernel/containers/pidns/check_pidns_enabled.c +1
-1@@ -59,7 +59,7 @@ int main()if (tst_kvercmp (2 ,6 ,24 ) <0 )return 1 ; - pid =do_clone (CLONE_NEWPID , dummy,NULL ); + pid =ltp_clone_quick (CLONE_NEWPID , dummy,NULL );/* Check for the clone function return value */ if (pid ==-1 )testcases/kernel/containers/pidns/pidns12.c +1
-1@@ -146,7 +146,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)." ,\strerror (errno));testcases/kernel/containers/pidns/pidns13.c +2
-2@@ -213,11 +213,11 @@ int main(int argc, char *argv[])/* Create container 1 */ *cinit_no =1 ; - cpid1 =do_clone (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no); + cpid1 =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no);/* Create container 2 */ *cinit_no =2 ; - cpid2 =do_clone (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no); + cpid2 =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn, cinit_no);if (cpid1 <0 || cpid2 <0 ) {tst_resm (TBROK ,"parent: clone() failed." );cleanup ();testcases/kernel/containers/pidns/pidns16.c +1
-1@@ -129,7 +129,7 @@ int main(int argc, char *argv[]) globalpid =getpid (); - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"clone() failed." );testcases/kernel/containers/pidns/pidns20.c +1
-1@@ -180,7 +180,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,\strerror (errno));testcases/kernel/containers/pidns/pidns21.c +1
-1@@ -182,7 +182,7 @@ int main(int argc, char *argv[])cleanup (); } - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,\strerror (errno));testcases/kernel/containers/pidns/pidns30.c +1
-1@@ -299,7 +299,7 @@ int main(int argc, char *argv[])tst_resm (TINFO ,"parent: successfully created posix mqueue" );/* container creation on PID namespace */ - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,strerror (errno));cleanup (TBROK ,F_STEP_2 , mqd);testcases/kernel/containers/pidns/pidns31.c +1
-1@@ -269,7 +269,7 @@ int main(int argc, char *argv[])tst_resm (TINFO ,"parent: successfully created posix mqueue" );/* container creation on PID namespace */ - cpid =do_clone (CLONE_NEWPID |SIGCHLD , child_fn,NULL ); + cpid =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_fn,NULL );if (cpid <0 ) {tst_resm (TBROK ,"parent: clone() failed(%s)" ,strerror (errno));cleanup (TBROK ,F_STEP_1 , mqd);testcases/kernel/containers/sysvipc/check_ipcns_enabled.c +1
-13@@ -26,24 +26,12 @@ int dummy(void *v) }int main () { -void *childstack, *stack;int pid;if (tst_kvercmp (2 ,6 ,19 ) <0 )return 1 ; - stack =malloc (getpagesize ()); -if (!stack) { -perror ("malloc" ); -return 2 ; - } - childstack = stack +getpagesize (); - -#ifdef __ia64__ - pid =clone2 (dummy, childstack,getpagesize (),CLONE_NEWIPC ,NULL ,NULL ,NULL ,NULL ); -#else - pid =clone (dummy, childstack,CLONE_NEWIPC ,NULL ); -#endif + pid =ltp_clone_quick (CLONE_NEWIPC , dummy,NULL );if (pid ==-1 )return 3 ;testcases/kernel/containers/utsname/check_utsns_enabled.c +1
-13@@ -61,25 +61,13 @@ int kernel_version_newenough()#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 (); -#ifdef __ia64__ - pid =clone2 (dummy, childstack,getpagesize (),CLONE_NEWUTS ,NULL ,NULL ,NULL ,NULL ); -#else - pid =clone (dummy, childstack,CLONE_NEWUTS ,NULL ); -#endif + pid =ltp_clone_quick (CLONE_NEWUTS , dummy,NULL );if (pid ==-1 )return 3 ;testcases/kernel/controllers/cgroup/clone_platform.h deleted +0
-34@@ -1,34 +0,0 @@ -/* -* Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved. -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of version 2 of the GNU General Public License as -* published by the Free Software Foundation. -* -* This program is distributed in the hope that it would be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -* -* You should have received a copy of the GNU General Public License along -* with this program; if not, write the Free Software Foundation, Inc., 59 -* Temple Place - Suite 330, Boston MA 02111-1307, USA. -* -*/ -/* Common platform specific defines for the clone system call tests */ - -//#define CHILD_STACK_SIZE 8192 -#define CHILD_STACK_SIZE 16384 - -#if defined (__s390__) || (__s390x__) -#define clone __clone -extern int __clone (int (void *),void *,int ,void *); -#elif defined(__ia64__) -#define clone2 __clone2 -/* Prototype provided by David Mosberger */ -/* int __clone2(int (*fn) (void *arg), void *child_stack_base, */ -/* size_t child_stack_size, int flags, void *arg, */ -/* pid_t *parent_tid, void *tls, pid_t *child_tid) */ -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif testcases/kernel/controllers/cgroup/test_6_2.c +1
-13@@ -24,8 +24,6 @@#include <unistd.h> #include <sched.h> -#include "clone_platform.h" -#define DEFAULT_USEC 30000int foo (void __attribute__((unused)) *arg)@@ -33,8 +31,6 @@ int foo(void __attribute__((unused)) *arg)return 0 ; } -char *stack[4096 ]; -int main (int argc,char **argv) {int usec =DEFAULT_USEC ;@@ -44,15 +40,7 @@ int main(int argc, char **argv)while (1 ) {usleep (usec); -#if defined(__hppa__) -clone (foo, stack,CLONE_NEWNS ,NULL ); -#elif defined(__ia64__) -clone2 (foo, stack, -4096 ,CLONE_NEWNS ,NULL ,NULL ,NULL ,NULL ); -#else -clone - (foo, stack +4096 ,CLONE_NEWNS ,NULL ); -#endif +ltp_clone_quick (CLONE_NEWNS , foo,NULL ); }return 0 ;testcases/kernel/fs/fs_bind/bin/Makefile +4
-6@@ -2,10 +2,8 @@ LTP_SRC_ROOT=../../../../.. LTP_BIN=$(LTP_SRC_ROOT)/testcases/bin -#CFLAGS+= -I$(LTP_SRC_ROOT)/include -Wall -g -CFLAGS+= -Wall -g -#LIBS+= -L$(LTP_SRC_ROOT)/lib -lltp -LIBS+= +CFLAGS+= -I$(LTP_SRC_ROOT)/include -Wall -g +LIBS+= -L$(LTP_SRC_ROOT)/lib -lltp all: smount nsclone@@ -19,10 +17,10 @@ uninstall: @/bin/true nsclone: nsclone.c - $(CC) $(CFLAGS) $(LIBS) -o nsclone nsclone.c + $(CC) $(CFLAGS) -o nsclone nsclone.c $(LIBS) smount: smount.c - $(CC) $(CFLAGS) $(LIBS) -o smount smount.c + $(CC) $(CFLAGS) -o smount smount.c clean: rm -f smount nsclonetestcases/kernel/fs/fs_bind/bin/nsclone.c +4
-15@@ -22,18 +22,10 @@#include <sched.h> #include <signal.h> #include <unistd.h> +#include <test.h> #include <sys/types.h> #include <sys/wait.h> -#ifdef __ia64__ -#define clone2 __clone2 -extern int __clone2 (int (*fn) (void *arg),void *child_stack_base, -size_t child_stack_size,int flags,void *arg, -pid_t *parent_tid,void *tls,pid_t *child_tid); -#endif - -char somemem[4096 ]; -int myfunc (void *arg){return system (arg); }@@ -59,12 +51,9 @@ int main(int argc, char *argv[]) parent_cmd = (char *)strdup (argv[1 ]);printf ("1\n" ); -#ifdef __ia64__ -if (clone2 (myfunc, somemem,getpagesize (),CLONE_NEWNS |SIGCHLD , - child_cmd,NULL ,NULL ,NULL ) !=-1 ) { -#else -if (clone (myfunc, somemem,CLONE_NEWNS |SIGCHLD , child_cmd) !=-1 ) { -#endif + ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , myfunc, + (void *)child_cmd); +if (ret !=-1 ) {system (parent_cmd);wait (&childret); }else {testcases/kernel/security/selinux-testsuite/tests/execshare/selinux_execshare_parent.c +1
-17@@ -28,8 +28,6 @@ int clone_fn(char **argv)int main (int argc,char **argv) { -int pagesize; -void *clone_stack, *page;int pid, rc, len, status, cloneflags;security_context_t context_s;context_t context;@@ -45,14 +43,6 @@ int main(int argc, char **argv)exit (-1 ); } - pagesize =getpagesize (); - page =malloc (pagesize); -if (!page) { -perror ("malloc" ); -exit (-1 ); - } - clone_stack = page + pagesize; - rc =getcon (&context_s);if (rc <0 ) {fprintf (stderr,"%s: unable to get my context\n" , argv[0 ]);@@ -83,13 +73,7 @@ int main(int argc, char **argv)fprintf (stderr,"%s: unable to set exec context to %s\n" , argv[0 ], context_s);exit (-1 ); } -#if defined(__hppa__) - pid =clone (clone_fn, page, cloneflags |SIGCHLD , argv); -#elif defined(__ia64__) - pid =__clone2 (clone_fn, clone_stack, pagesize, cloneflags |SIGCHLD , argv,NULL ,NULL ,NULL ); -#else - pid =clone (clone_fn, clone_stack, cloneflags |SIGCHLD , argv); -#endif + pid =ltp_clone_quick (cloneflags |SIGCHLD , child_fn, argv);if (pid <0 ) {perror ("clone" );exit (-1 );testcases/kernel/security/tomoyo/newns.c +3
-3@@ -38,9 +38,9 @@ static int child(void *arg)int main (int argc,char *argv[]) {char c =0 ; -char *stack =malloc (8192 ); -const pid_t pid =clone (child, stack + (8192 /2 ),CLONE_NEWNS , - (void *) argv); +const pid_t pid; + + pid =ltp_clone_quick (CLONE_NEWNS , child, (void *) argv);while (waitpid (pid,NULL , __WALL) ==EOF && errno ==EINTR ) c++;/* Dummy. */ return 0 ;testcases/kernel/syscalls/clone/clone01.c +2
-9@@ -120,15 +120,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (do_child, child_stack,SIGCHLD ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (do_child, child_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (do_child, child_stack +CHILD_STACK_SIZE ,SIGCHLD ,NULL )); -#endif +TEST (ltp_clone (SIGCHLD , do_child,NULL ,CHILD_STACK_SIZE , + child_stack)); again:if ((child_pid =wait (&status)) ==-1 )testcases/kernel/syscalls/clone/clone02.c +2
-11@@ -190,17 +190,8 @@ int main(int ac, char **av) }/* Test the system call */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack, - test_cases[i].flags,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE , test_cases[i].flags,NULL , -NULL ,NULL ,NULL )); -#else -TEST (clone (child_fn, child_stack +CHILD_STACK_SIZE , - test_cases[i].flags,NULL )); -#endif +TEST (ltp_clone (test_cases[i].flags, child_fn,NULL , +CHILD_STACK_SIZE , child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {testcases/kernel/syscalls/clone/clone03.c +2
-8@@ -125,14 +125,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack,0 ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE ,0 ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone (child_fn, child_stack +CHILD_STACK_SIZE ,0 ,NULL )); -#endif +TEST (ltp_clone (0 , child_fn,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {testcases/kernel/syscalls/clone/clone04.c +2
-12@@ -133,18 +133,8 @@ int main(int ac, char **av)/* * call the system call with the TEST() macro */ -#if defined(__hppa__) -TEST (clone (test_cases[ind].child_fn, test_stack, -SIGCHLD ,NULL )); -#elif defined(__ia64__) - test_cases[ind].child_fn =NULL ; -TEST (clone2 (test_cases[ind].child_fn, test_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL , -NULL ,NULL ,NULL )); -#else -TEST (clone (test_cases[ind].child_fn, test_stack, -0 ,NULL )); -#endif +TEST (ltp_clone (0 ,test_cases[ind].child_fn,NULL , +CHILD_STACK_SIZE , test_stack));if ((TEST_RETURN ==-1 ) && (TEST_ERRNO == test_cases[ind].exp_errno)) {testcases/kernel/syscalls/clone/clone05.c +2
-9@@ -119,15 +119,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_fn, child_stack,FLAG ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_fn, child_stack, -CHILD_STACK_SIZE ,FLAG ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (child_fn, child_stack +CHILD_STACK_SIZE ,FLAG ,NULL )); -#endif +TEST (ltp_clone (FLAG , child_fn,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code & parent_variable */ if ((TEST_RETURN !=-1 ) && (parent_variable)) {testcases/kernel/syscalls/clone/clone06.c +2
-9@@ -132,15 +132,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) -TEST (clone (child_environ, child_stack,0 ,NULL )); -#elif defined(__ia64__) -TEST (clone2 (child_environ, child_stack, -CHILD_STACK_SIZE ,0 ,NULL ,NULL ,NULL ,NULL )); -#else -TEST (clone - (child_environ, child_stack +CHILD_STACK_SIZE ,0 ,NULL )); -#endif +TEST (ltp_clone (0 , child_environ,NULL ,CHILD_STACK_SIZE , + child_stack));/* check return code */ if (TEST_RETURN ==-1 ) {testcases/kernel/syscalls/clone/clone07.c +0
-6@@ -126,17 +126,8 @@ int main(int ac, char **av)/* * Call clone(2) */ -#if defined(__hppa__) - child_pid =clone (do_child, child_stack,SIGCHLD ,NULL ); -#elif defined(__ia64__) - child_pid =clone2 (do_child, child_stack, -CHILD_STACK_SIZE ,SIGCHLD ,NULL , -NULL ,NULL ,NULL );
testcases/kernel/syscalls/clone/clone07.c int main(int ac, char **av) · line 133
Quoted 10 lines
testcases/kernel/syscalls/clone/clone07.c +2
-5-#else - child_pid = - (clone - (do_child, child_stack +CHILD_STACK_SIZE ,SIGCHLD ,NULL )); -#endif + child_pid =ltp_clone (SIGCHLD , do_child,NULL , +CHILD_STACK_SIZE , child_stack);wait (NULL );free (child_stack); }/* End for TEST_LOOPING */
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 8 lines · On Tuesday 13 October 2009 08:13:35 Subrata Modak wrote:
Quoted 7 lines · Serge E. Hallyn
Quoted 6 lines · Mike Frysinger
Quoted 4 lines · On Tuesday 29 September 2009 19:30:15 Serge E. Hallyn wrote:
Define
ltp_clone()andltp_clone_malloc()in libltp, and convert existing clone usages to them. (clone04 can't use it bc it wants to pass NULL, whichltp_clone()will for many arches convert to NULL+stacksize-1).
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
i thought you fixed the clone04 issue ?
Gah. That's what i get for just wanting to get the thing out. Here is a new version.
Sorry for being not in action for long. Garret made lot of changes for his
Makefileenhancements and lot of files from the containers directory are missing. This patch fails to apply hence:
ive updated and committed. things seem to work for me, but if someone could double check on diff arches, that'd probably be good.
thanks for this clean up Serge ... ltp needed it pretty badly -mike
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list