summaryrefslogtreecommitdiff
path: root/tools/skrewt.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-22 21:44:49 (GMT)
committerJohn Denker <jsd@av8n.com>2012-07-29 22:32:35 (GMT)
commit6c56d656bd407bc5fc4dd713aacb553ebefee892 (patch)
tree9a562b01b1fa906ae4d534ee6334e78158f031a3 /tools/skrewt.c
parentabb71cf6b1145588827d04de4da3bb48ecb06965 (diff)
regularize log/progress messages
Diffstat (limited to 'tools/skrewt.c')
-rw-r--r--tools/skrewt.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/tools/skrewt.c b/tools/skrewt.c
index 44e885b..6de3dd9 100644
--- a/tools/skrewt.c
+++ b/tools/skrewt.c
@@ -11,6 +11,7 @@
#include <signal.h>
#include <stdio.h> /* perror */
+#include <sstream>
using namespace std;
@@ -134,6 +135,15 @@ void exeunt(const int sts){
exit(sts);
}
+string basename(const string path){
+ size_t where = path.rfind("/");
+ if (where != string::npos) return path.substr(1+where);
+ return path;
+}
+
+string progname, progid;
+int mypid;
+
////////////////////////////////////////////////////////////
int main(int _argc, const char** _argv){
//// pid_t pid = getpid();
@@ -141,7 +151,14 @@ int main(int _argc, const char** _argv){
//// cout << getpgid(pid) << endl;
int argc(_argc);
const char **argv(_argv);
- string progname(*argv); argv++; argc--;
+ {
+ progname = *argv++; argc--;
+ mypid = getpid();
+ stringstream binder;
+ binder << basename(progname) << "[" << mypid << "]";
+ progid = binder.str();
+ }
+
int maxsize(1000000);
@@ -183,7 +200,7 @@ int main(int _argc, const char** _argv){
if (getline(cin, header).fail()) continue;
msgsize += header.length()+1;
if (msgsize > maxsize) {
- cerr << "skrewt rejection: bigger than " << maxsize << endl;
+ cerr << progid << " rejection: bigger than " << maxsize << endl;
exeunt(ex_spam);
}
for (;;) {
@@ -197,7 +214,7 @@ int main(int _argc, const char** _argv){
if (getline(cin, line).fail()) continue;
msgsize += line.length()+1;
if (msgsize > maxsize) {
- cerr << "skrewt rejection: bigger than " << maxsize << endl;
+ cerr << progid << " rejection: bigger than " << maxsize << endl;
exeunt(ex_spam);
}
header += "\n" + line;
@@ -206,7 +223,7 @@ int main(int _argc, const char** _argv){
if (len && header[len-1] == '\r') len--; // reduced length, not counting <cr>
if (len == 0) {
if (!gotdate) {
- cerr << "skrewt rejection: no date" << endl;
+ cerr << progid << " rejection: no date" << endl;
exeunt(ex_spam); // disallow mail with no date
}
inheads = 0;
@@ -256,7 +273,7 @@ int main(int _argc, const char** _argv){
gotdate++;
} else if (headword == "subject") {
if (rest.find("-please-bounce-this-") != string::npos) {
- cerr << "skrewt rejection: by request" << endl;
+ cerr << progid << " rejection: by request" << endl;
exeunt(ex_spam);
}
}
@@ -268,7 +285,7 @@ int main(int _argc, const char** _argv){
if (!getline(cin, line).fail()) {
msgsize += line.length()+1;
if (msgsize > maxsize) {
- cerr << "skrewt rejection: bigger than " << maxsize << endl;
+ cerr << progid << " rejection: bigger than " << maxsize << endl;
exeunt(ex_spam);
}
if (line == "--" + boundary) {
@@ -284,9 +301,9 @@ int main(int _argc, const char** _argv){
}
if (0) cerr << "textlines: " << textlines << endl;
if (!textlines) {
- cerr << "skrewt rejection: no text" << endl;
+ cerr << progid << " rejection: no text" << endl;
exeunt(ex_spam);
}
- cerr << "skrewt normal completion" << endl;
+ cerr << progid << " normal completion" << endl;
exit(ex_good);
}