summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-16 16:26:54 -0700
committerJohn Denker <jsd@av8n.com>2012-07-16 16:26:54 -0700
commitc347d77edbad50abdc1229a07097601a75ce13c3 (patch)
tree994b1a6c4e28284b147b8cdd9bbdf07ec1896bd9
parent14b7add3c77a79fd46ad55a43a4051a10ebfc0b4 (diff)
less verbose but more informative progress logging
-rw-r--r--tools/hi-q.c22
-rw-r--r--tools/hi-test.conf2
2 files changed, 20 insertions, 4 deletions
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 <string>
#include <vector>
#include <sstream>
+#include <map>
// 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<int,int> 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) {
diff --git a/tools/hi-test.conf b/tools/hi-test.conf
index df3f8bb..630e2bb 100644
--- a/tools/hi-test.conf
+++ b/tools/hi-test.conf
@@ -1,3 +1,3 @@
hi-test x0 -snooze 10
-hi-test x1 -snooze 1 -exit 3 -kill
+hi-test x1 -snooze 1 -exit 1 -kill
hi-test x2 -snooze 10