diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 00:08:53 +0100 |
| commit | 69aec538b456402170dc723af417ba5c05389c32 (patch) | |
| tree | e6f34c543f17c6392447ea337b2e2868212424d1 /except.c | |
| download | qmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2 qmail-69aec538b456402170dc723af417ba5c05389c32.zip | |
qmail 1.03 import
Diffstat (limited to 'except.c')
| -rw-r--r-- | except.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/except.c b/except.c new file mode 100644 index 0000000..c553b3b --- /dev/null +++ b/except.c | |||
| @@ -0,0 +1,37 @@ | |||
| 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 | } | ||
