11 #include <sys/mount.h>
21 (void) fprintf(stdout,"Clone started pid='%d', parent='%d'\n",getpid(),getppid());
22 (void) fflush(stdout);
23 (void) unshare(CLONE_NEWUTS|CLONE_NEWUSER|CLONE_NEWNS|CLONE_FILES|CLONE_FS);
24 if (mount("/wrk/jail", "/mnt", NULL, MS_BIND, NULL)<0) {
25 (void) fprintf(stdout,"unable to mount /wrk/jail on mnt error=<%s>\n",strerror(errno));
26 (void) fflush(stdout);
29 if (chdir("/mnt")<0) {
30 (void) fprintf(stdout,"unable to chdir to /wrk/jail error=<%s>\n",strerror(errno));
31 (void) fflush(stdout);
34 if (pivot_root(".", "old_root")<0) {
35 (void) fprintf(stdout,"privot_root error=<%s>\n",strerror(errno));
36 (void) fflush(stdout);
40 (void) fprintf(stdout,"unable to chdir to / error=<%s>\n",strerror(errno));
41 (void) fflush(stdout);
45 if (mount("none", "/proc","proc",0,NULL)<0) {
46 (void) fprintf(stdout,"mount MOVE error=<%s>\n",strerror(errno));
47 (void) fflush(stdout);
50 if (umount2("old_root",MNT_DETACH)<0) {
51 (void) fprintf(stdout,"Unable to umount old_root error=<%s>\n",strerror(errno));
52 (void) fflush(stdout);
55 (void) fprintf(stderr,"Pret 3!\n");
56 (void) fflush(stderr);
57 (void) execl("/bin/bash", NULL);
58 (void) fprintf(stdout,"Clone completed pid='%d' (UNEXPECTED!!)\n",getpid());
62 int main(int argc, char *argv[])
68 child_stack=(void **)malloc(STKSIZE);
69 if ((cpid=clone(&do_contain, child_stack+STKSIZE,SIGCHLD|__WCLONE|CLONE_NEWPID|CLONE_NEWNS,NULL))<0) {
70 (void) fprintf(stdout,"Unable to start container (error=%s)\n",strerror(errno));
71 (void) fflush(stdout);
74 if (waitpid(cpid,0,0)<0) {
75 (void) fprintf(stdout,"Waitpid error (%s)\n",strerror(errno));
76 (void) fflush(stdout);
79 (void) free(child_stack);
80 (void) fprintf(stdout,"Everything done\n");
81 (void) fflush(stdout);