source: tests/meta/fork+exec.hfa @ 93c86ac

Last change on this file since 93c86ac was 481f882, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Added some missing headers and cleaned up some of the fork+exec stuff.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// fork+exec.hfa -- tools for using fork + exec
8//
9// Author           : Thierry Delisle
10// Created On       : Thu Oct 06 14:02:46 2022
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#include <stdarg.h>                                                                             // va_start, va_end
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20
21#include <errno.h>
22#include <signal.h>
23
24extern "C" {
25        #include <sys/types.h>
26        #include <sys/wait.h>
27        #include <unistd.h>
28}
29
30static int true_main(const char * path, char * env[]);
31
32static int do_wait(pid_t pid) {
33        int wstatus;
34        int options = 0;
35        pid_t ret = waitpid(pid, &wstatus, options);
36        fflush(stdout);
37        if(ret < 0) {
38                fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
39                exit(1);
40        }
41        return wstatus;
42}
43
44static pid_t strict_fork(void) {
45        fflush(stdout);
46        pid_t ret = fork();
47        if(ret < 0) {
48                fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
49                exit(1);
50        }
51        if(ret == 0) dup2(1, 2);
52        return ret;
53}
54
55static void print_status(int wstatus) {
56        printf("Child status:\n");
57        printf("IFEXITED   : %d, ", WIFEXITED(wstatus));
58        printf("EXITSTATUS : %d, ", WEXITSTATUS(wstatus));
59        printf("IFSIGNALED : %d, ", WIFSIGNALED(wstatus));
60        printf("TERMSIG    : %d, ", WTERMSIG(wstatus));
61        printf("COREDUMP   : %d, ", WCOREDUMP(wstatus));
62        printf("IFSTOPPED  : %d, ", WIFSTOPPED(wstatus));
63        printf("STOPSIG    : %d, ", WSTOPSIG(wstatus));
64        printf("IFCONTINUED: %d", WIFCONTINUED(wstatus));
65        printf("\n");
66        printf("\n");
67}
68
69static void check_main(const char * path) {
70        if(getenv("CFATEST_FORK_EXEC_TEXT")) return;
71
72        char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p };
73        exit( true_main(path, env) );
74}
Note: See TracBrowser for help on using the repository browser.