diff options
Diffstat (limited to 'tools/hi-q.c')
-rw-r--r-- | tools/hi-q.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c index 9d85b7a..8107e27 100644 --- a/tools/hi-q.c +++ b/tools/hi-q.c @@ -22,7 +22,8 @@ using namespace std; #include <vector> #include <sstream> -// error exit codes, as stated in qmail.c +// error exit codes, mostly as stated in qmail.c +const int ex_good = 0; const int ex_spam = 21; const int ex_syserr = 71; const int ex_comerr = 74; @@ -392,7 +393,7 @@ int main(int argc, char** argv) { close(sync[rEnd]); close(0); // Housecleaning: the reading end of stdin was - // delegated to the first child, + // delegated to the first child, // so we don't need it. if (verbose) for (unsigned int ii = 0; ii < nkids; ii++) { @@ -406,33 +407,44 @@ int main(int argc, char** argv) { cerr << endl; } - for (unsigned int ii=0; ii<nkids-1; ii++){ /* loop over N-1 kids */ - /* _not_ including last kid */ +// loop over N-1 kids ... _not_ including last kid + for (unsigned int ii=0; ii<nkids-1; ii++){ #ifdef testing blurb(ii, kidpid); #else - somekid = waitpid(kidpid[ii], &kidstatus, WUNTRACED); - if (somekid) {} // avoid silly compiler warning - if (WIFEXITED(kidstatus)) { - int sts = WEXITSTATUS(kidstatus); - if (sts == 1) { - cerr << "hi-q says: kid " << ii - << " i.e. '" << filter[ii][0] << "' reports spam." - << endl; - panic(ex_spam); - } - if (sts != 0) { - cerr << "hi-q says: kid " << ii - << " i.e. '" << filter[ii][0] << "'" - << " suffered an error: " << sts - << endl; - panic(ex_syserr); + for (;;){ + somekid = waitpid(kidpid[ii], &kidstatus, WUNTRACED); + if (somekid) {} // avoid silly compiler warning + if (WIFEXITED(kidstatus)) { + int sts = WEXITSTATUS(kidstatus); + if (sts == 1) { + cerr << "hi-q says: kid " << ii + << " i.e. '" << filter[ii][0] << "' reports spam." + << endl; + panic(ex_spam); + } + if (sts != 0) { + cerr << "hi-q says: kid " << ii + << " i.e. '" << filter[ii][0] << "'" + << " exited with bad status: " << sts + << endl; + panic(ex_syserr); + } + break; // kidstatus==0 means clean exit; + // go check other kids + } else if (WIFSIGNALED(kidstatus)) { + cerr << "hi-q says: kid " << ii + << " i.e. '" << filter[ii][0] << "'" + << " was killed by signal: " << WTERMSIG(kidstatus) + << endl; + + panic(ex_syserr); // any kill, not a normal exit + } else { + // some status change other than exit or kill + // perhaps stopped for terminal input } - /* otherwise kidstatus==0 and we fall through */ } - else panic(ex_syserr); // any kill, not a normal exit #endif - } //xx fprintf(stderr, "slurping %d %d\n", 1, loose_end); |