summaryrefslogtreecommitdiff
path: root/tools/hi-test.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-15 12:35:46 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-15 12:35:46 (GMT)
commitb0f78b272c97b7cc3ff1fbe6c48fd2151d039613 (patch)
tree09c46bbacbc71a7ff86af98ccd50fc0aedffb829 /tools/hi-test.c
parentf96288efc416089567dac7bcfa674b1cd6931c97 (diff)
more complete implementation, including test fixtures
Diffstat (limited to 'tools/hi-test.c')
-rw-r--r--tools/hi-test.c85
1 files changed, 84 insertions, 1 deletions
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);
}