static void test(void) { int status, ret = 0; ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL); if (ret == -1) tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL); if (ret == -1) tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); while (wait(&status) > 0) { if (WIFEXITED(status) && WEXITSTATUS(status) == 1) ret = 1; if (WIFEXITED(status) && WEXITSTATUS(status) == 2) tst_brkm(TBROK | TERRNO, cleanup, "error in child"); if (WIFSIGNALED(status)) { tst_resm(TFAIL, "child was killed with signal %s", tst_strsig(WTERMSIG(status))); return; } } if (ret) tst_resm(TFAIL, "SysV msg: communication with identical keys" " between namespaces"); else tst_resm(TPASS, "SysV msg: communication with identical keys" " between namespaces"); }
int main(int argc, char *argv[]) { int status; pid_t pid; setup(); pid = getpid(); /* Container creation on PID namespace */ TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn, NULL)); if (TEST_RETURN == -1) { tst_brkm(TBROK | TTERRNO, CLEANUP, "clone failed"); } sleep(1); if (wait(&status) < 0) tst_resm(TWARN, "parent: waitpid() failed."); if (WIFEXITED(status) && WEXITSTATUS(status) != 0) tst_resm(TBROK, "container was terminated abnormally"); CLEANUP(); tst_exit(); }
int main(int argc, char *argv[]) { int status; pid_t pid; setup(); pid = getpid(); /* Container creation on PID namespace */ TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn, NULL)); if (TEST_RETURN == -1) { tst_brkm(TBROK | TERRNO, NULL, "clone failed"); } sleep(1); if (wait(&status) == -1) tst_resm(TFAIL, "waitpid failed"); if (WIFEXITED(status) && WEXITSTATUS(status) != 0) tst_resm(TFAIL, "container exited abnormally"); else if (WIFSIGNALED(status)) tst_resm(TFAIL, "container was signaled with signal = %d", WTERMSIG(status)); tst_exit(); }
int main(int argc, char *argv[]) { int r; mqd_t mqd; char buf[30]; int use_clone = T_UNSHARE; if (argc == 2 && strcmp(argv[1], "-clone") == 0) { tst_resm(TINFO, "Testing posix mq namespaces through clone(2).\n"); use_clone = T_CLONE; } else tst_resm(TINFO, "Testing posix mq namespaces through unshare(2).\n"); if (pipe(p1) == -1 || pipe(p2) == -1) { tst_brkm(TBROK|TERRNO, NULL, "pipe failed"); } mqd = syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR|O_CREAT|O_EXCL, 0777, NULL); if (mqd == -1) { perror("mq_open"); tst_resm(TFAIL, "mq_open failed\n"); tst_exit(); } tst_resm(TINFO, "Checking namespaces isolation from parent to child\n"); /* fire off the test */ r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL); if (r < 0) { tst_resm(TFAIL, "failed clone/unshare\n"); mq_close(mqd); syscall(__NR_mq_unlink, NOSLASH_MQ1); tst_exit(); } close(p1[0]); close(p2[1]); if (write(p1[1], "go", strlen("go") + 1) < 0) tst_resm(TBROK | TERRNO, "write(p1[1], \"go\", ...) failed"); else if (read(p2[0], buf, 7) < 0) tst_resm(TBROK | TERRNO, "read(p2[0], buf, ...) failed"); else { if (!strcmp(buf, "exists")) { tst_resm(TFAIL, "child process found mqueue\n"); } else if (!strcmp(buf, "notfnd")) { tst_resm(TPASS, "child process didn't find mqueue\n"); } else { tst_resm(TFAIL, "UNKNOWN RESULT\n"); } } /* destroy the mqueue */ if (mq_close(mqd) == -1) { tst_brkm(TBROK|TERRNO, NULL, "mq_close failed"); } syscall(__NR_mq_unlink, NOSLASH_MQ1); tst_exit(); }
int main(int argc, char *argv[]) { int r; mqd_t mqd; char buf[30]; int use_clone = T_UNSHARE; if (argc == 2 && strcmp(argv[1], "-clone") == 0) { tst_resm(TINFO, "Testing posix mq namespaces through clone(2).\n"); use_clone = T_CLONE; } else tst_resm(TINFO, "Testing posix mq namespaces through unshare(2).\n"); if (pipe(p1) == -1) { perror("pipe"); exit(EXIT_FAILURE); } if (pipe(p2) == -1) { perror("pipe"); exit(EXIT_FAILURE); } /* fire off the test */ r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mqueue, NULL); if (r < 0) { tst_resm(TFAIL, "failed clone/unshare\n"); tst_exit(); } tst_resm(TINFO, "Checking namespaces isolation (child to parent)\n"); close(p1[0]); close(p2[1]); if (write(p1[1], "go", strlen("go") + 1) < 0) { tst_resm(TBROK, "write(p1[1], \"go\", ..) failed"); } if (read(p2[0], buf, 7) < 0) { tst_resm(TBROK, "read(p1[0], ..) failed"); } else if (!strcmp(buf, "mqfail")) { tst_resm(TFAIL, "child process could not create mqueue\n"); umount(DEV_MQUEUE); tst_exit(); } else if (strcmp(buf, "mqopen")) { tst_resm(TFAIL, "child process could not create mqueue\n"); umount(DEV_MQUEUE); tst_exit(); } else { mqd = syscall(__NR_mq_open, SLASH_MQ1, O_RDONLY); if (mqd == -1) { tst_resm(TPASS, "Parent process can't see the mqueue\n"); } else { tst_resm(TFAIL, "Parent process found mqueue\n"); mq_close(mqd); } if (write(p1[1], "cont", 5)) { tst_resm(TBROK, "read(p1[0], ..) failed"); } } read(p2[0], buf, 7); tst_exit(); }
int main() { int status; pid_t pid = getpid(); tst_resm(TINFO, "Parent: Passing the pid of the process %d", pid); TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, kill_pid_in_childfun, (void *) &pid)); if (TEST_RETURN == -1) { tst_brkm(TFAIL|TERRNO, cleanup, "clone failed"); } else if (wait(&status) == -1) { tst_brkm(TFAIL|TERRNO, cleanup, "wait failed"); } cleanup(); tst_exit(); }
/* * create_nested_container() Recursively create MAX_DEPTH nested containers */ int create_nested_container(void *vtest) { int exit_val; int ret, count, *level; pid_t cpid, ppid; cpid = getpid(); ppid = getppid(); char mesg[] = "Nested Containers are created"; level = (int *)vtest; count = *level; /* Child process closes up read side of pipe */ close(fd[0]); /* Comparing the values to make sure pidns is created correctly */ if (cpid != CINIT_PID || ppid != PARENT_PID) { printf("Got unexpected cpid and/or ppid (cpid=%d ppid=%d)\n", cpid, ppid); exit_val = 1; } if (count > 1) { count--; ret = do_clone_unshare_test(T_CLONE, CLONE_NEWPID, create_nested_container, (void *)&count); if (ret == -1) { printf("clone failed; errno = %d : %s\n", ret, strerror(ret)); exit_val = 1; } else exit_val = 0; } else { /* Sending mesg, 'Nested containers created' through the pipe */ write(fd[1], mesg, (strlen(mesg) + 1)); exit_val = 0; } close(fd[1]); pause(); return exit_val; }
int main(int argc, char *argv[]) { int ret, status, nbytes; char readbuffer[80]; pipe(fd); ret = do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL); if ((wait(&status)) < 0) { tst_resm(TWARN, "wait() failed, skipping this test case"); /* Cleanup & continue with next test case */ CLEANUP(); } if (ret == -1) { tst_resm(TFAIL, "clone() Failed, errno = %d :" " %s", ret, strerror(ret)); /* Cleanup & continue with next test case */ CLEANUP(); } /* Parent process closes up write side of pipe */ close(fd[1]); /* Read in a string from the pipe */ nbytes = read(fd[0], readbuffer, sizeof(readbuffer)); if (nbytes !=0 ) { tst_resm(TPASS, "Container init : %s", readbuffer); } else { tst_resm(TFAIL, "Container init is killed by SIGKILL !!!"); } if (WTERMSIG(status)) { tst_resm(TFAIL, "Container init pid got killed by signal %d", WTERMSIG(status)); } /* cleanup and exit */ CLEANUP(); close(fd[0]); tst_exit(); } /* End main */
int main(int argc, char *argv[]) { int status; TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL)); if (TEST_RETURN == -1) { tst_brkm(TFAIL|TTERRNO, cleanup, "clone failed"); } else if ((wait(&status)) == -1) { tst_brkm(TWARN|TERRNO, cleanup, "wait failed"); } if (WIFEXITED(status) && WEXITSTATUS(status) != 0) tst_resm(TFAIL, "child exited abnormally"); else if (WIFSIGNALED(status)) { tst_resm(TFAIL, "child was killed with signal = %d", WTERMSIG(status)); } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int nbytes, status; char readbuffer[80]; setup(); pipe(fd); TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL)); if (TEST_RETURN == -1) { tst_brkm(TFAIL | TTERRNO, CLEANUP, "clone failed"); } else if (wait(&status) == -1) { tst_brkm(TFAIL | TERRNO, CLEANUP, "wait failed"); } /* Parent process closes up write side of pipe */ close(fd[1]); /* Read in a string from the pipe */ nbytes = read(fd[0], readbuffer, sizeof(readbuffer)); if (0 <= nbytes) { tst_resm(TPASS, "Container init : %s", readbuffer); } else { tst_brkm(TFAIL, CLEANUP, "Container init is killed by SIGKILL !!!"); } if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "Container init pid exited abnormally"); } else if (WIFSIGNALED(status)) { tst_resm(TFAIL, "Container init pid got killed by signal %d", WTERMSIG(status)); } CLEANUP(); tst_exit(); }
int main(int argc, char *argv[]) { int ret, nbytes, status; char readbuffer[80]; pid_t pid, pgid; int count = MAX_DEPTH; setup(); /* * XXX (garrcoop): why in the hell is this fork-wait written this way? * This doesn't add up with the pattern used for the rest of the tests, * so I'm pretty damn sure this test is written incorrectly. */ pid = fork(); if (pid == -1) { tst_brkm(TBROK | TERRNO, NULL, "fork failed"); } else if (pid != 0) { /* * NOTE: use waitpid so that we know we're waiting for the * _top-level_ child instead of a spawned subcontainer. * * XXX (garrcoop): Might want to mask SIGCHLD in the top-level * child too, or not *shrugs*. */ if (waitpid(pid, &status, 0) == -1) { perror("wait failed"); } if (WIFEXITED(status)) exit(WEXITSTATUS(status)); else exit(status); } /* To make all the containers share the same PGID as its parent */ setpgid(0, 0); pid = getpid(); pgid = getpgid(pid); ret = pipe(fd); if (ret == -1) tst_brkm(TBROK | TERRNO, cleanup, "pipe failed"); TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, create_nested_container, (void *)&count)); if (TEST_RETURN == -1) { tst_brkm(TFAIL | TTERRNO, cleanup, "clone failed"); } close(fd[1]); /* Waiting for the MAX_DEPTH number of containers to be created */ nbytes = read(fd[0], readbuffer, sizeof(readbuffer)); close(fd[0]); if (nbytes > 0) tst_resm(TINFO, " %d %s", MAX_DEPTH, readbuffer); else tst_brkm(TFAIL, cleanup, "unable to create %d containers", MAX_DEPTH); /* Kill the container created */ kill_nested_containers(); cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int ret, use_clone = T_NONE, id, n; char *tsttype = NONESTR; char buf[7]; if (argc != 2) { tst_resm(TFAIL, "Usage: %s <clone|unshare|none>\n", argv[0]); tst_resm(TFAIL, " where clone, unshare, or fork specifies" " unshare method."); tst_exit(); } /* Using PIPE's to sync between container and Parent */ if (pipe(p1) == -1) { perror("pipe"); exit(EXIT_FAILURE); } if (pipe(p2) == -1) { perror("pipe"); exit(EXIT_FAILURE); } tsttype = NONESTR; if (strcmp(argv[1], "clone") == 0) { use_clone = T_CLONE; tsttype = CLONESTR; } else if (strcmp(argv[1], "unshare") == 0) { use_clone = T_UNSHARE; tsttype = UNSHARESTR; } id = msgget(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600); if (id == -1) { perror("msgget"); /* Retry without attempting to create the MQ */ id = msgget(KEY_VAL, 0); if (id == -1) perror("msgget failure"), exit(1); } msg.mtype = 5; strcpy(msg.mtext, "Message of type 5!"); n = msgsnd(id, &msg, strlen( msg.mtext), 0); if (n == -1) perror("msgsnd"), tst_exit(); tst_resm(TINFO, "mesgq namespaces test : %s\n", tsttype); /* fire off the test */ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq, NULL); if (ret < 0) { tst_resm(TFAIL, "%s failed\n", tsttype); tst_exit(); } close(p1[0]); close(p2[1]); write(p1[1], "go", 3); read(p2[0], buf, 7); if (strcmp(buf, "exists") == 0) { if (use_clone == T_NONE) tst_resm(TPASS, "Plain cloned process found mesgq " "inside container\n"); else tst_resm(TFAIL, "%s: Container init process found mesgq\n", tsttype); } else { if (use_clone == T_NONE) tst_resm(TFAIL, "Plain cloned process didn't find mesgq\n"); else tst_resm(TPASS, "%s: Container didn't find mesgq", tsttype); } /* Delete the mesgQ */ id = msgget(KEY_VAL, 0); msgctl(id, IPC_RMID, NULL); tst_exit(); tst_exit(); }
int main(int argc, char *argv[]) { int ret, use_clone = T_NONE, id; char *tsttype = NONESTR; char buf[7]; setup(); if (argc != 2) { tst_resm(TFAIL, "Usage: %s <clone| unshare| none>", argv[0]); tst_resm(TFAIL, " where clone, unshare, or fork specifies" " unshare method."); tst_exit(); } /* Using PIPE's to sync between container and Parent */ if (pipe(p1) == -1) { perror("pipe"); exit(EXIT_FAILURE); } if (pipe(p2) == -1) { perror("pipe"); exit(EXIT_FAILURE); } if (strcmp(argv[1], "clone") == 0) { use_clone = T_CLONE; tsttype = CLONESTR; } else if (strcmp(argv[1], "unshare") == 0) { use_clone = T_UNSHARE; tsttype = UNSHARESTR; } /* 1. Create (or fetch if existing) the binary semaphore */ id = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666); if (id == -1) { perror("Semaphore create"); if (errno != EEXIST) { perror("semget failure"); tst_resm(TBROK, "Semaphore creation failed"); tst_exit(); } id = semget(MY_KEY, 1, 0); if (id == -1) { perror("Semaphore create"); tst_resm(TBROK, "Semaphore operation failed"); tst_exit(); } } tst_resm(TINFO, "Semaphore namespaces Isolation test : %s", tsttype); /* fire off the test */ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_semaphore, NULL); if (ret < 0) { tst_resm(TFAIL, "%s failed", tsttype); tst_exit(); } close(p1[0]); close(p2[1]); write(p1[1], "go", 3); read(p2[0], buf, 7); if (strcmp(buf, "exists") == 0) { if (use_clone == T_NONE) tst_resm(TPASS, "Plain cloned process found semaphore " "inside container"); else tst_resm(TFAIL, "%s: Container init process found semaphore", tsttype); } else { if (use_clone == T_NONE) tst_resm(TFAIL, "Plain cloned process didn't find semaphore"); else tst_resm(TPASS, "%s: Container didn't find semaphore", tsttype); } /* Delete the semaphore */ id = semget(MY_KEY, 1, 0); semctl(id, IPC_RMID, 0); tst_exit(); }
int main(int argc, char *argv[]) { int ret, use_clone = T_NONE; char *tsttype = NONESTR; char buf[7]; int id; setup(); if (argc != 2) { tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]); tst_resm(TINFO, " where clone, unshare, or fork specifies" " unshare method."); tst_exit(); } /* Using PIPE's to sync between containers and Parent */ SAFE_PIPE(NULL, p1); SAFE_PIPE(NULL, p2); if (strcmp(argv[1], "clone") == 0) { use_clone = T_CLONE; tsttype = CLONESTR; } else if (strcmp(argv[1], "unshare") == 0) { use_clone = T_UNSHARE; tsttype = UNSHARESTR; } tst_resm(TINFO, "Shared Memory namespace test : %s", tsttype); /* Create 2 containers */ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem1, NULL); if (ret < 0) tst_brkm(TFAIL, NULL, "clone/unshare failed"); ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem2, NULL); if (ret < 0) tst_brkm(TFAIL, NULL, "clone/unshare failed"); close(p2[1]); read(p2[0], buf, 7); if (strcmp(buf, "exists") == 0) { if (use_clone == T_NONE) tst_resm(TPASS, "Plain cloned process able to access shmem " "segment created"); else tst_resm(TFAIL, "%s : In namespace2 found the shmem segment " "created in Namespace1", tsttype); } else { if (use_clone == T_NONE) tst_resm(TFAIL, "Plain cloned process didn't find shmem seg"); else tst_resm(TPASS, "%s : In namespace2 unable to access the shmem seg " "created in Namespace1", tsttype); } /* destroy the key */ id = shmget(TESTKEY, 100, 0); shmctl(id, IPC_RMID, NULL); tst_exit(); }
int main(int argc, char *argv[]) { int ret, id, use_clone = T_NONE; char *tsttype = NONESTR; char buf[7]; if (argc != 2) { tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]); tst_resm(TINFO, " where clone, unshare, or fork specifies" " unshare method.\n"); tst_exit(); } /* Using PIPE's to sync between container and Parent */ if (pipe(p1) == -1) { perror("pipe1"); tst_exit(); } if (pipe(p2) == -1) { perror("pipe2"); tst_exit(); } if (strcmp(argv[1], "clone") == 0) { use_clone = T_CLONE; tsttype = CLONESTR; } else if (strcmp(argv[1], "unshare") == 0) { use_clone = T_UNSHARE; tsttype = UNSHARESTR; } tst_resm(TINFO, "Semaphore Namespaces Test : %s", tsttype); /* Create 2 containers */ ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem1, NULL); if (ret < 0) { tst_resm(TFAIL, "clone/unshare failed\n"); tst_exit(); } ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem2, NULL); if (ret < 0) { tst_resm(TFAIL, "clone/unshare failed\n"); tst_exit(); } close(p2[1]); read(p2[0], buf, 7); if (strcmp(buf, "exists") == 0) if (use_clone == T_NONE) tst_resm(TPASS, "Plain cloned process able to access the semaphore " "created\n"); else tst_resm(TFAIL, "%s : In namespace2 found the semaphore " "created in Namespace1\n", tsttype); else if (use_clone == T_NONE) tst_resm(TFAIL, "Plain cloned process didn't find semaphore\n"); else tst_resm(TPASS, "%s : In namespace2 unable to access the semaphore " "created in Namespace1\n", tsttype); /* Delete the semaphore */ id = semget(MY_KEY, 1, 0); semctl(id, IPC_RMID, 0); tst_exit(); return 0; }
int main(int argc, char *argv[]) { int r, use_clone = T_NONE; int id; char *tsttype = NONESTR; char buf[7]; setup(); if (argc != 2) { tst_resm(TFAIL, "Usage: %s <clone|unshare|none>", argv[0]); tst_brkm(TFAIL, NULL, " where clone, unshare, or fork specifies unshare method."); } if (pipe(p1) == -1) { perror("pipe"); exit(EXIT_FAILURE); } if (pipe(p2) == -1) { perror("pipe"); exit(EXIT_FAILURE); } tsttype = NONESTR; if (strcmp(argv[1], "clone") == 0) { use_clone = T_CLONE; tsttype = CLONESTR; } else if (strcmp(argv[1], "unshare") == 0) { use_clone = T_UNSHARE; tsttype = UNSHARESTR; } /* first create the key */ id = shmget(TESTKEY, 100, IPC_CREAT); if (id == -1) { perror("shmget"); tst_brkm(TFAIL, NULL, "shmget failed"); } tst_resm(TINFO, "shmid namespaces test : %s", tsttype); /* fire off the test */ r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmid, NULL); if (r < 0) { tst_brkm(TFAIL, NULL, "%s failed", tsttype); } close(p1[0]); close(p2[1]); write(p1[1], "go", 3); read(p2[0], buf, 7); if (strcmp(buf, "exists") == 0) { if (use_clone == T_NONE) tst_resm(TPASS, "plain cloned process found shmid"); else tst_resm(TFAIL, "%s: child process found shmid", tsttype); } else { if (use_clone == T_NONE) tst_resm(TFAIL, "plain cloned process didn't find shmid"); else tst_resm(TPASS, "%s: child process didn't find shmid", tsttype); } /* destroy the key */ shmctl(id, IPC_RMID, NULL); tst_exit(); }