Ignore:
Timestamp:
Oct 12, 2022, 4:32:49 PM (20 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master
Children:
38cc59f
Parents:
a51b8f6
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/configs/parsebools.cfa

    ra51b8f6 r481f882  
    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include <string.h>
    4 
    5 #include <errno.h>
    6 #include <signal.h>
    7 
    8 extern "C" {
    9         #include <sys/types.h>
    10         #include <sys/wait.h>
    11         #include <unistd.h>
    12 }
     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// configs/parsebools.cfa
     8// Testing parsing of boolean arguments
     9//
     10// Author           : Thierry Delisle
     11// Created On       : Wed Oct 12 15:28:01 2022
     12// Last Modified By :
     13// Last Modified On :
     14// Update Count     :
     15//
    1316
    1417#include <parseargs.hfa>
    1518#include <fstream.hfa>
    1619
    17 int true_main(const char * exec);
     20#include "../meta/fork+exec.hfa"
    1821
    1922int main(int argc, char * argv[]) {
    20         if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]);
     23        check_main(argv[0]);
    2124
    2225        bool YN = false;
     
    4851}
    4952
    50 int do_wait(pid_t pid) {
    51         int wstatus;
    52         int options = 0;
    53         pid_t ret = waitpid(pid, &wstatus, options);
    54         fflush(stdout);
    55         if(ret < 0) {
    56                 fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
    57                 exit(1);
    58         }
    59         return wstatus;
    60 }
    61 
    62 pid_t strict_fork(void) {
    63         fflush(stdout);
    64         pid_t ret = fork();
    65         if(ret < 0) {
    66                 fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno));
    67                 exit(1);
    68         }
    69         return ret;
    70 }
    71 
    72 void print_status(int wstatus) {
    73         printf("Child status:\n");
    74         printf("    WIFEXITED   : %d", WIFEXITED(wstatus));
    75         printf("    WEXITSTATUS : %d", WEXITSTATUS(wstatus));
    76         printf("    WIFSIGNALED : %d", WIFSIGNALED(wstatus));
    77         printf("    WTERMSIG    : %d", WTERMSIG(wstatus));
    78         printf("    WCOREDUMP   : %d", WCOREDUMP(wstatus));
    79         printf("    WIFSTOPPED  : %d", WIFSTOPPED(wstatus));
    80         printf("    WSTOPSIG    : %d", WSTOPSIG(wstatus));
    81         printf("    WIFCONTINUED: %d\n", WIFCONTINUED(wstatus));
    82 }
    83 
    84 int true_main(const char * path) {
    85         char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p };
    86 
     53int true_main(const char * path, char * env[]) {
    8754        printf("no arg:\n");
    8855        if(pid_t child = strict_fork(); child == 0) {
     
    9764                print_status(status);
    9865        }
    99         printf("\n");
    10066
    10167        printf("all true/set arg:\n");
     
    11177                print_status(status);
    11278        }
    113         printf("\n");
    11479
    11580        printf("all false/unset arg:\n");
     
    12590                print_status(status);
    12691        }
    127         printf("\n");
    12892
    12993        printf("gibberish arg 1:\n");
     
    139103                print_status(status);
    140104        }
    141         printf("\n");
    142105
    143106        printf("gibberish arg 2:\n");
     
    153116                print_status(status);
    154117        }
    155         printf("\n");
    156118
    157119        printf("gibberish arg 3:\n");
     
    167129                print_status(status);
    168130        }
    169         printf("\n");
    170131
    171132        printf("gibberish arg 4:\n");
     
    181142                print_status(status);
    182143        }
    183         printf("\n");
    184144
    185145        printf("All Done!\n");
Note: See TracChangeset for help on using the changeset viewer.