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