From c347d77edbad50abdc1229a07097601a75ce13c3 Mon Sep 17 00:00:00 2001 From: John Denker Date: Mon, 16 Jul 2012 16:26:54 -0700 Subject: less verbose but more informative progress logging --- tools/hi-q.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'tools/hi-q.c') diff --git a/tools/hi-q.c b/tools/hi-q.c index 1896bf4..7215b0c 100644 --- a/tools/hi-q.c +++ b/tools/hi-q.c @@ -2,6 +2,9 @@ // lightweight connection from qmail to filters e.g. spamassassin // (hi-q filter, get it?) +// Hint: For testing, see also hi-test.conf which invokes ./hi-test: +// ./hi-q hi-test.conf + // TODO: Panic stop should signal all children. // TODO: Possibly: Wait for all kids in parallel? // That's because they might finish out of order. @@ -21,6 +24,7 @@ using namespace std; #include #include #include +#include // error exit codes, mostly as stated in qmail.c const int ex_good = 0; @@ -131,7 +135,7 @@ int xclose(int arg){ extern char** environ; int main(int argc, char** argv) { - int verbose(1); + int verbose(0); int kidstatus; int rslt; @@ -238,6 +242,7 @@ int main(int argc, char** argv) { // doesn't choose it. That allows N-1 of the kids // to close it and dup() something useful onto it. + map iiofpid; for (unsigned int ii=0; ii < nkids; ii++){ /* loop starting all kids */ int datapipe[2]; int kid_end; @@ -275,6 +280,12 @@ int main(int argc, char** argv) { kid_end = datapipe[flip(wEnd, rEnd)]; kidpid[ii] = fork(); + if (kidpid[ii] == -1) { + cerr << "hi-q: fork failed : "; + perror(0); + exit(ex_syserr); + } + iiofpid[kidpid[ii]] = ii; if (!kidpid[ii]) { /*** child code ***/ pid_t kidgroup(0); // process group for all kids is @@ -314,6 +325,7 @@ int main(int argc, char** argv) { ssize_t rslt = read(resync[rEnd], &junk, 1); if (rslt < 0 ) { cerr << "bad sync ... " << rslt << endl; + // FIXME (maybe?) should this be fatal? } else { // cerr << "back from read resync, good: " << rslt << endl; } @@ -458,11 +470,15 @@ int main(int argc, char** argv) { /////////////////// // decode the best reason why the filter-chain terminated if (best_blame) { + string short_name(""); + int kidno(iiofpid[argbest_blame]); if (WIFEXITED(best_blame)) { int sts = WEXITSTATUS(best_blame); if (sts == 1) { - cerr << "hi-q says: kid " << argbest_blame - << " reports spam." << endl; + cerr << "hi-q says: kid[" << kidno << "]" + << " pid " << argbest_blame + << " i.e. '" << filter[kidno][0] << "'" + << " reports spam." << endl; panic(ex_spam); } if (sts != 0) { -- cgit v1.2.3