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