summaryrefslogtreecommitdiff
path: root/tools/greylist.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-20 16:20:36 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-20 16:20:36 (GMT)
commit84867328ae43be14475b4fec15c54865e10e5cc7 (patch)
tree2db65fbffa33bb5fea0d4884ac940f25bd2abd80 /tools/greylist.c
parentdab77fecb82816abf82f3a4b72f67d2ed793e14b (diff)
greylist will now zap its program-group
Diffstat (limited to 'tools/greylist.c')
-rw-r--r--tools/greylist.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/tools/greylist.c b/tools/greylist.c
index 525fc9b..910b40c 100644
--- a/tools/greylist.c
+++ b/tools/greylist.c
@@ -11,7 +11,8 @@
#include <fstream> /* for ofstream() */
#include <fcntl.h> /* for creat() */
#include <sys/time.h> /* for gettimeofday() */
-#include <sstream>
+#include <sstream> /* for stringstream */
+#include <signal.h> /* for kill(), SIGUSR1 */
// requires apt-get install libboost-filesystem-dev:
#include <boost/filesystem.hpp>
@@ -43,10 +44,32 @@ void dump(const string var){
}
- // int stat(const char *path, struct stat *buf);
- // int fstat(int fd, struct stat *buf);
- // int lstat(const char *path, struct stat *buf);
+////////////////
+// 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);
+}
class whatsit{
public:
@@ -161,7 +184,8 @@ int main(int _argc, char** _argv){
return 0;
}
else {
- cerr << "Unrecognized arg, ignored: " << arg << endl;
+ cerr << "Unrecognized arg: " << arg << endl;
+ exeunt(sa_syserr);
}
}
@@ -172,7 +196,7 @@ int whatsit::doit(){
char* ipvar = getenv("TCPREMOTEIP");
if (!ipvar) {
cerr << progname << ": TCPREMOTEIP not set???" << endl;
- exit(sa_syserr);
+ exeunt(sa_syserr);
}
ipbase = ipvar;
char* hostvar = getenv("TCPREMOTEHOST");
@@ -194,7 +218,7 @@ int whatsit::doit(){
<< ": mkdir failed for '"
<< dirname << "' : ";
perror(0);
- exit(sa_syserr);
+ exeunt(sa_syserr);
}
}
@@ -216,7 +240,7 @@ int whatsit::doit(){
}
close(fd);
update("new customer", now, now);
- return(bug_bait_grey);
+ exeunt(bug_bait_grey);
}
// here if stat succeeded
mod_age = now.tv_sec - ipstat.st_mtime;
@@ -224,16 +248,16 @@ int whatsit::doit(){
timeval mod_orig = {ipstat.st_mtime, 0};
if (mod_age < minimum_age) {
update("early bird", mod_orig, now);
- return(bug_bait_grey);
+ exeunt(bug_bait_grey);
}
if (mod_age - ac_age < minimum_age // early bird, or completely unused
&& mod_age > probation) { // did not diligently resubmit
update("disprobation", now, now);
- return(bug_bait_grey);
+ exeunt(bug_bait_grey);
}
if (ac_age > maximum_age) {
update("too old, starting over", now, now);
- return(bug_bait_grey);
+ exeunt(bug_bait_grey);
}
// if all checks are passed, must be OK:
update("returning customer", mod_orig, now);