1
/* $Id: clone.c 441 2007-03-14 20:53:10Z steve-beattie $ */
4
* Copyright (C) 2007 Novell/SUSE
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License as
8
* published by the Free Software Foundation, version 2 of the
17
#include <sys/types.h>
26
#include <linux/unistd.h>
28
struct option long_options[] =
30
{"newns", 0, 0, 'n'}, /* create a new namespace */
34
static void usage (char * program) {
35
fprintf(stderr, "usage: %s [arguments]\n",
37
fprintf(stderr, "%s\n", "$Id: clone.c 441 2007-03-14 20:53:10Z steve-beattie $");
41
static int filedes[2] = {-1, -1};
43
static int do_child(void *arg)
49
rc = dup2(filedes[1], STDOUT_FILENO);
51
perror("FAIL: pipe failed");
55
rc = write(filedes[1], "PASS\n", strlen("PASS\n"));
57
perror("FAIL: write failed");
64
int main(int argc, char *argv[])
70
void *child_stack = malloc(PAGE_SIZE << 4);
73
while ((c = getopt_long (argc, argv, "+hn", long_options, NULL)) != -1) {
76
clone_flags |= CLONE_NEWNS;
92
perror("FAIL: pipe failed");
96
rc = clone(&do_child, child_stack, clone_flags, NULL);
98
perror("FAIL: clone failed");
103
rc = waitpid(-1, (&waitstatus), __WALL);
105
read(filedes[0], &buf, sizeof(buf));
107
fprintf(stderr, "FAIL: wait failed - %s\n",
112
if ((WEXITSTATUS(waitstatus) == 0) && strcmp("PASS\n", buf) == 0) {
116
return WEXITSTATUS(waitstatus);