Commit | Line | Data |
---|---|---|
212b6f5d MW |
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 | void main(argc,argv) | |
11 | int argc; | |
12 | char **argv; | |
13 | { | |
14 | int pid; | |
15 | int wstat; | |
16 | ||
17 | if (!argv[1]) | |
18 | strerr_die1x(100,"bouncesaying: usage: bouncesaying error [ program [ arg ... ] ]"); | |
19 | ||
20 | if (argv[2]) { | |
21 | pid = fork(); | |
22 | if (pid == -1) | |
23 | strerr_die2sys(111,FATAL,"unable to fork: "); | |
24 | if (pid == 0) { | |
25 | execvp(argv[2],argv + 2); | |
26 | if (error_temp(errno)) _exit(111); | |
27 | _exit(100); | |
28 | } | |
29 | if (wait_pid(&wstat,pid) == -1) | |
30 | strerr_die2x(111,FATAL,"wait failed"); | |
31 | if (wait_crashed(wstat)) | |
32 | strerr_die2x(111,FATAL,"child crashed"); | |
33 | switch(wait_exitcode(wstat)) { | |
34 | case 0: break; | |
35 | case 111: strerr_die2x(111,FATAL,"temporary child error"); | |
36 | default: _exit(0); | |
37 | } | |
38 | } | |
39 | ||
40 | strerr_die1x(100,argv[1]); | |
41 | } |