summaryrefslogtreecommitdiff
path: root/tools/hi-q.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-15 12:22:05 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-15 12:22:05 (GMT)
commitf96288efc416089567dac7bcfa674b1cd6931c97 (patch)
tree2ffe080000ad1306bf5d3337ce27c9ec829fa8ed /tools/hi-q.c
parent5b14bc41824ae70d33f1e7cd1486aec32b46b3e1 (diff)
untested possible implementation of exeunt ... kill peers
as soon as we know the msg is spam
Diffstat (limited to 'tools/hi-q.c')
-rw-r--r--tools/hi-q.c58
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);