except.c (760B)
1 #include "fork.h" 2 #include "strerr.h" 3 #include "wait.h" 4 #include "error.h" 5 #include "exit.h" 6 7 #define FATAL "except: fatal: " 8 9 int main(int argc, char **argv) 10 { 11 int pid; 12 int wstat; 13 14 if (argc == 1) 15 strerr_die1x(100,"except: usage: except program [ arg ... ]"); 16 17 pid = fork(); 18 if (pid == -1) 19 strerr_die2sys(111,FATAL,"unable to fork: "); 20 if (pid == 0) { 21 execvp(argv[1],argv + 1); 22 if (error_temp(errno)) _exit(111); 23 _exit(100); 24 } 25 26 if (wait_pid(&wstat,pid) == -1) 27 strerr_die2x(111,FATAL,"wait failed"); 28 if (wait_crashed(wstat)) 29 strerr_die2x(111,FATAL,"child crashed"); 30 switch(wait_exitcode(wstat)) { 31 case 0: _exit(100); 32 case 111: strerr_die2x(111,FATAL,"temporary child error"); 33 default: _exit(0); 34 } 35 }