/** * Adds a child process to either the running-test or running-daemon * list. */ static void note_child(pid_t pid, char *fname, char type) { if (type == 'T') { note_process(pid, fname); } else if (type == 'D') { note_daemon(pid, fname); } else { pounder_fprintf(stdout, "Don't know what to do with child `%s' of type %c.\n", fname, type); } }
/** * Main program. Returns 1 if all programs run successfully, 0 if * something failed and -1 if there was an error running programs. */ int main(int argc, char *argv[]) { int retcode; struct sigaction zig; pid_t pid; char *c; /* Check parameters */ if (argc < 2) { fprintf(stderr, "Usage: %s test_prog\n", argv[0]); return 1; } if (argc > 2 && strcmp(argv[2], "--leader") == 0) { pounder_fprintf(stdout, "Logging this test output to %s/POUNDERLOG.\n", getenv("POUNDER_LOGDIR")); is_leader = 1; record_pid(); } progname = argv[0]; /* Set up signals */ memset(&zig, 0x00, sizeof(zig)); zig.sa_handler = jump_out; sigaction(SIGHUP, &zig, NULL); sigaction(SIGINT, &zig, NULL); sigaction(SIGTERM, &zig, NULL); if (is_directory(argv[1])) { retcode = process_dir(argv[1]); } else { if (is_executable(argv[1])) { c = rindex(argv[1], '/'); c++; // Start the test pid = spawn_test(argv[1]); if (pid < 0) { perror("fork"); retcode = -1; goto out; } // Track the test note_process(pid, argv[1]); if (wait_for_pids() == 0) { retcode = 1; } else { retcode = 0; } } else { pounder_fprintf(stderr, "%s: Not a directory or a test.\n", argv[1]); retcode = -1; } } out: kill_daemons(); wait_for_daemons(); if (is_leader) { if (retcode == 0) { pounder_fprintf(stdout, "%s: %s.\n", argv[1], pass_msg); } else if (retcode < 0 || retcode == 255) { pounder_fprintf(stdout, "%s: %s with code %d.\n", argv[1], abort_msg, retcode); } else { pounder_fprintf(stdout, "%s: %s with code %d.\n", argv[1], fail_msg, retcode); } unlink(pidfile); } exit(retcode); }