int main(int argc, char **argv) { int lc; char *msg; int fail = 0; int pid; int status; msg = parse_opts(argc, argv, NULL, NULL); if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX argv0 = argv[0]; maybe_run_child(&do_child_1, "n", 1); maybe_run_child(&do_child_2_uclinux, "n", 2); #endif setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; pid = FORK_OR_VFORK(); if (pid < 0) { tst_resm(TINFO, "Fork Failed, may be OK under stress"); exit(pid); } else if (pid == 0) { /* * Child: * Set up to catch SIGINT. The kids will wait till a * SIGINT has been received before they proceed. */ #ifdef UCLINUX if (self_exec(argv[0], "n", 1) < 0) { tst_resm(TINFO, "self_exec failed"); exit(pid); } #else do_child_1(); #endif } else { /* parent */ fail = 0; waitpid(pid, &status, 0); if (WEXITSTATUS(status) != 0) { tst_resm(TFAIL, "child returned bad status"); fail = 1; } if (fail) tst_resm(TFAIL, "%s FAILED", TCID); else tst_resm(TPASS, "%s PASSED", TCID); } } cleanup(); tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; pid_t pid, pid1; int retval = 3, status; char *argv[1], *env[1]; if ((msg = parse_opts(ac, av, options, &help)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); #ifdef UCLINUX maybe_run_child(&do_child_1, "nS", 1, &test_app); #endif if (!Fflag) tst_brkm(TBROK, NULL, "You must specify an executable file with the -F option."); setup(*av); TEST_EXP_ENOS(exp_enos); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; if (sync_pipe_create(start_sync_pipes, PIPE_NAME_START) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); if (sync_pipe_create(end_sync_pipes, PIPE_NAME_END) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); /* * to test whether execve(2) sets ETXTBSY when a second * child process attempts to execve the executable opened * by the first child process */ if ((pid = FORK_OR_VFORK()) == -1) tst_brkm(TBROK, cleanup, "fork #1 failed"); else if (pid == 0) { #ifdef UCLINUX if (self_exec(av[0], "nS", 1, test_app) < 0) tst_brkm(TBROK, cleanup, "self_exec failed"); #else do_child_1(); #endif } if (sync_pipe_wait(start_sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_wait failed"); if (sync_pipe_close(start_sync_pipes, PIPE_NAME_START) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); if ((pid1 = FORK_OR_VFORK()) == -1) tst_brkm(TBROK, cleanup, "fork #2 failed"); if (pid1 == 0) { retval = 3; argv[0] = 0; env[0] = 0; /* do not interfere with end synchronization of first * child */ sync_pipe_close(end_sync_pipes, PIPE_NAME_END); TEST(execve(test_app, argv, env)); TEST_ERROR_LOG(TEST_ERRNO); if (TEST_ERRNO != ETXTBSY) { retval = 1; perror("didn't get ETXTBSY\n"); } else printf("execve failed with ETXTBSY as " "expected\n"); exit(retval); } /* wait for the child to finish */ if (waitpid(pid1, &status, 0) == -1) tst_brkm(TBROK|TERRNO, cleanup, "waitpid failed"); if (WIFEXITED(status) && WEXITSTATUS(status) == 3) tst_resm(TPASS, "execve failed as expected"); else tst_resm(TFAIL, "execve succeeded, expected failure"); /* terminate first child */ sync_pipe_notify(end_sync_pipes); (void) waitpid(pid, NULL, 0); } cleanup(); tst_exit(); }
int main(int ac, char **av) { int pid; int fail = 0; int ret, status; int exno = 0; int lc; tst_parse_opts(ac, av, NULL, NULL); #ifdef UCLINUX argv0 = av[0]; maybe_run_child(&do_child_1, "n", 1); maybe_run_child(&do_child_2, "n", 2); #endif /* * perform global setup for the test */ setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; /* * When the process group having forked of a child * and then it attached itself to another process * group and tries to setsid */ pid = FORK_OR_VFORK(); if (pid == 0) { if ((pid = FORK_OR_VFORK()) == -1) { tst_resm(TFAIL, "Fork failed"); } if (pid == 0) { #ifdef UCLINUX if (self_exec(argv0, "n", 1) < 0) { tst_resm(TFAIL, "self_exec failed"); } #else do_child_1(); #endif } else { if (setpgid(0, 0) < 0) { tst_resm(TFAIL, "setpgid(parent) failed: %s", strerror(errno)); fail = 1; } if ((ret = wait(&status)) > 0) { if (status != 0) { tst_resm(TFAIL, "Test {%d} exited " "status 0x%0x (wanted 0x0)", ret, status); fail = 1; } } } exit(0); } else { if ((ret = wait(&status)) > 0) { if (status != 0) { tst_resm(TFAIL, "Test {%d} exited " "status 0x%0x (wanted 0x0)", ret, status); fail = 1; } } } if (!(fail || exno)) { tst_resm(TPASS, "all misc tests passed"); } } cleanup(); tst_exit(); }