1 /* 2 * Copyright (c) International Business Machines Corp., 2005 3 * Author: Ram Pai (linuxram (at) us.ibm.com) 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #define _GNU_SOURCE 21 22 #include <stdlib.h> 23 #include <stdio.h> 24 #include <string.h> 25 #include <sched.h> 26 #include <signal.h> 27 #include <unistd.h> 28 #include "test.h" 29 #include <sys/types.h> 30 #include <sys/wait.h> 31 32 int myfunc(void *arg) 33 { 34 return system(arg); 35 } 36 37 static void usage(char *cmd) 38 { 39 printf("%s child_script parent_script\n", cmd); 40 } 41 42 int main(int argc, char *argv[]) 43 { 44 char *child_cmd; 45 char *parent_cmd; 46 int ret = 0, childret = 0; 47 48 if (argc < 3) { 49 usage(argv[0]); 50 exit(1); 51 } 52 53 child_cmd = (char *)strdup(argv[2]); 54 parent_cmd = (char *)strdup(argv[1]); 55 56 printf("1\n"); 57 ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, myfunc, (void *)child_cmd); 58 if (ret != -1) { 59 system(parent_cmd); 60 wait(&childret); 61 } else { 62 fprintf(stderr, "clone failed\n"); 63 } 64 if (ret || !WIFEXITED(childret)) { 65 exit(1); 66 } 67 exit(0); 68 } 69