// // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // fork+exec.hfa -- tools for using fork + exec // // Author : Thierry Delisle // Created On : Thu Oct 06 14:02:46 2022 // Last Modified By : // Last Modified On : // Update Count : // #include // va_start, va_end #include #include #include #include #include extern "C" { #include #include #include } static int true_main(const char * path, const char * env[]); static int do_wait(pid_t pid) { int wstatus; int options = 0; pid_t ret = waitpid(pid, &wstatus, options); fflush(stdout); if(ret < 0) { fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno)); exit(1); } return wstatus; } static pid_t strict_fork(void) { fflush(stdout); pid_t ret = fork(); if(ret < 0) { fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno)); exit(1); } if(ret == 0) dup2(1, 2); return ret; } static void print_status(int wstatus) { printf("Child status:\n"); printf("IFEXITED : %d, ", WIFEXITED(wstatus)); printf("EXITSTATUS : %d, ", WEXITSTATUS(wstatus)); printf("IFSIGNALED : %d, ", WIFSIGNALED(wstatus)); printf("TERMSIG : %d, ", WTERMSIG(wstatus)); printf("COREDUMP : %d, ", WCOREDUMP(wstatus)); printf("IFSTOPPED : %d, ", WIFSTOPPED(wstatus)); printf("STOPSIG : %d, ", WSTOPSIG(wstatus)); printf("IFCONTINUED: %d", WIFCONTINUED(wstatus)); printf("\n"); printf("\n"); } static void check_main(const char * path) { if(getenv("CFATEST_FORK_EXEC_TEXT")) return; const char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", (char*)0 }; exit( true_main(path, env) ); }