summaryrefslogtreecommitdiff
path: root/tools/hi-q.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-20 18:05:02 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-20 18:05:02 (GMT)
commitd77d56ab050f7763f06461787cc862b6ec0095c4 (patch)
treea88976156764ecdd57b8a1a314cb5dd4551265ed /tools/hi-q.c
parentefd833cb48f0181c20d9c85466126540fa46c859 (diff)
add some exit-code processing; require TCPREMOTEHOST
Diffstat (limited to 'tools/hi-q.c')
-rw-r--r--tools/hi-q.c67
1 files changed, 51 insertions, 16 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c
index 21724a1..f195508 100644
--- a/tools/hi-q.c
+++ b/tools/hi-q.c
@@ -27,11 +27,42 @@ using namespace std;
#include <map>
// error exit codes, mostly as stated in qmail.c
-const int ex_good = 0;
-const int ex_spam = 21;
-const int ex_grey = 70;
-const int ex_syserr = 71;
-const int ex_comerr = 74;
+#define bar \
+foo(good, 0) ;\
+foo(spam, 21) ;\
+foo(permerr, 31) ;\
+foo(greylisting, 70) ;\
+foo(syserr, 71) ;\
+foo(comerr, 74) ;
+
+#define foo(name, num) const int ex_ ## name = num
+bar
+#undef foo
+
+map<int,string> codemap;
+
+
+#define bar_sa \
+foo_sa(GOOD, 0, "ham") ;\
+foo_sa(SPAM, 1, "spam") ;\
+foo_sa(USAGE, 64, "command line usage error") ;\
+foo_sa(DATAERR, 65, "data format error") ;\
+foo_sa(NOINPUT, 66, "cannot open input") ;\
+foo_sa(NOUSER, 67, "addressee unknown") ;\
+foo_sa(NOHOST, 68, "host name unknown") ;\
+foo_sa(UNAVAILABLE, 69, "service unavailable") ;\
+foo_sa(SOFTWARE, 70, "internal software error") ;\
+foo_sa(OSERR, 71, "system error (e.g., can't fork)") ;\
+foo_sa(OSFILE, 72, "critical OS file missing") ;\
+foo_sa(CANTCREAT, 73, "can't create (user) output file") ;\
+foo_sa(IOERR, 74, "input/output error") ;\
+foo_sa(TEMPFAIL, 75, "temp failure; user is invited to retry") ;\
+foo_sa(PROTOCOL, 76, "remote error in protocol") ;\
+foo_sa(NOPERM, 77, "permission denied") ;\
+foo_sa(CONFIG, 78, "configuration error") ;\
+foo_sa(TOOBIG, 98, "message was too big to process (see --max-size)"
+
+
#define bufsize 16384
@@ -176,8 +207,11 @@ public:
int main(int argc, char** argv) {
progname = *argv;
mypid = getpid();
-// dump("TCPREMOTEIP");
-// dump("TCPREMOTEHOST");
+
+#define foo(name, num) codemap[num] = #name ;
+bar
+#undef foo
+
int verbose(0);
int kidstatus;
@@ -502,15 +536,15 @@ int main(int argc, char** argv) {
if (best_blame) {
string short_name("");
int kidno(iiofpid[argbest_blame]);
- string exword = "spam";
- int excode = ex_spam;
- if (filter[kidno].mode == grey) {
- exword = "greylisting";
- excode = ex_grey;
- }
if (WIFEXITED(best_blame)) {
+ string exword = "spam"; // default, for non-modern status codes
+ int excode = ex_spam; // default, for non-modern status codes
int sts = WEXITSTATUS(best_blame);
- if (sts == 1) {
+ if (filter[kidno].mode == grey) {
+ exword = codemap[sts];
+ excode = sts;
+ }
+ if (exword.length()) {
cerr << "hi-q says: kid[" << kidno << "]"
<< " pid " << argbest_blame
<< " i.e. '" << filter[kidno].cmd[0] << "'"
@@ -523,8 +557,9 @@ int main(int argc, char** argv) {
<< endl;
panic(ex_syserr);
} else {
- // should never get here unless exit status was nonzero
- cerr << "hi-q: should never happen" << endl;
+ // should never get here
+ // should be no accounting for blame if there was no blame
+ cerr << "hi-q: should never happen: no child to blame" << endl;
panic(ex_syserr);
}
} else if (WIFSIGNALED(best_blame)) {