int main(int argc, char **argv) { int lc, status; int *bufsz_arr; tst_parse_opts(argc, argv, options, &help); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if (pipe(pipe_fd) < 0) tst_brkm(TBROK | TERRNO, cleanup, "pipe"); bufsz_arr = SAFE_MALLOC(cleanup, nr_iovecs * sizeof(int)); gen_random_arr(bufsz_arr, nr_iovecs); /* the start of child_alloc and child_invoke is already * synchronized via pipe */ pids[0] = fork(); switch (pids[0]) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork #0"); case 0: child_alloc(bufsz_arr); exit(0); } pids[1] = fork(); switch (pids[1]) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork #1"); case 0: child_invoke(bufsz_arr); exit(0); } /* wait until child_invoke reads from child_alloc's VM */ if (waitpid(pids[1], &status, 0) == -1) tst_brkm(TBROK | TERRNO, cleanup, "waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) tst_resm(TFAIL, "child 1 returns %d", status); /* child_alloc is free to exit now */ safe_semop(semid, 0, 1); if (waitpid(pids[0], &status, 0) == -1) tst_brkm(TBROK | TERRNO, cleanup, "waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) tst_resm(TFAIL, "child 0 returns %d", status); free(bufsz_arr); } cleanup(); tst_exit(); }
int main(int argc, char **argv) { int lc, status; char *msg; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; len = strlen(tst_string); if (pipe(pipe_fd) < 0) tst_brkm(TBROK | TERRNO, cleanup, "pipe"); /* the start of child_alloc and child_invoke is already * synchronized via pipe */ pids[0] = fork(); switch (pids[0]) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork #0"); case 0: child_alloc(); exit(0); } pids[1] = fork(); switch (pids[1]) { case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork #1"); case 0: child_invoke(); exit(0); } /* wait until child_invoke reads from child_alloc's VM */ if (waitpid(pids[1], &status, 0) == -1) tst_brkm(TBROK | TERRNO, cleanup, "waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) tst_resm(TFAIL, "child 1 returns %d", status); /* child_alloc is free to exit now */ safe_semop(semid, 0, 1); if (waitpid(pids[0], &status, 0) == -1) tst_brkm(TBROK | TERRNO, cleanup, "waitpid"); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) tst_resm(TFAIL, "child 0 returns %d", status); } cleanup(); tst_exit(); }