diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/hi-q.c | 10 | ||||
-rw-r--r-- | tools/hi-test.c | 85 | ||||
-rw-r--r-- | tools/hi-test.conf | 6 |
3 files changed, 93 insertions, 8 deletions
diff --git a/tools/hi-q.c b/tools/hi-q.c index 8107e27..914bb57 100644 --- a/tools/hi-q.c +++ b/tools/hi-q.c @@ -433,11 +433,13 @@ int main(int argc, char** argv) { 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) + int sig = WTERMSIG(kidstatus); + cerr << "hi-q says: kid " << ii + << " == " << kidpid[ii] + << " == '" << filter[ii][0] << "'" + << " was killed by signal " << sig << endl; - + if (sig == SIGUSR1) exit(ex_spam); panic(ex_syserr); // any kill, not a normal exit } else { // some status change other than exit or kill diff --git a/tools/hi-test.c b/tools/hi-test.c index d74b3c9..50e4a76 100644 --- a/tools/hi-test.c +++ b/tools/hi-test.c @@ -1,11 +1,94 @@ #include <iostream> #include <stdlib.h> +#include <string> +#include <signal.h> + +#include <stdio.h> /* perror() */ using namespace std; -int main(){ + +// exit codes, compatible with spamassassin (not with qmail-queue) +const int sa_good(0); +const int sa_spam(1); +const int sa_usage(64); + +//////////////// +// little utility to help with argument parsing: +// +int prefix(const string shorter, const string longer){ + return shorter == longer.substr(0, shorter.length()); +} + +void exeunt(const int sts){ + if (sts == sa_good) exit(sts); + + const char* foo = getenv("HI_Q_GROUP"); + if (!foo) exit(sts); + +// No point in signalling ourself: + sighandler_t rslt = signal(SIGUSR1, SIG_IGN); + if (rslt == SIG_ERR) { + cerr << "error setting signal" << endl; + } + int k = kill(-atoi(foo), SIGUSR1); + if (k) { + cerr << "kill failed on group " << atoi(foo) << " ... "; + perror(0); + } + exit(sts); +} + +using namespace std; + +int main(int _argc, const char** _argv){ + int snooze(0); + int status(0); + int argc(_argc); + const char **argv(_argv); + string progname(*argv); argv++; argc--; + + while (argc) { + string arg(*argv); argv++; argc--; + if (arg.substr(0,2) == "--") arg = arg.substr(1); + if (prefix(arg, "-help")) { +// usage(0); + } + if (prefix(arg, "-snooze")) { + if (!argc) { + cerr << "Option -snooze requires an argument" << endl; + exit(sa_usage); + } + snooze = atoi(*argv); argv++; argc--; + continue; + } + if (prefix(arg, "-kill")) { + if (!argc) { + cerr << "Option -kill requires an argument" << endl; + exit(sa_usage); + } + status = atoi(*argv); argv++; argc--; + continue; + } + if (arg.substr(0,1) == "x") { + continue; + } + if (arg.substr(0,1) == "-") { + cerr << "Unrecognized option '" << arg << "'" << endl; + cerr << "For help, try: " << progname << " -help" << endl; + exit(sa_usage); + } else { + cerr << "Extraneous verbiage '" << arg << "'" << endl; + cerr << "For help, try: " << progname << " -help" << endl; + exit(sa_usage); + } + } + + cerr << "++++ hi-test pid: " << getpid() << " group: " << getpgid(0); char* foo = getenv("HI_Q_GROUP"); if (foo) cerr << " HI_Q_GROUP: " << foo; cerr << endl; + sleep(snooze); + exeunt(status); } diff --git a/tools/hi-test.conf b/tools/hi-test.conf index 6c697c2..8addf21 100644 --- a/tools/hi-test.conf +++ b/tools/hi-test.conf @@ -1,3 +1,3 @@ -hi-test x0 -hi-test x1 -hi-test x2 +hi-test x0 -snooze 10 +hi-test x1 -snooze 1 -kill 10 +hi-test x2 -snooze 10 |