From ad30ce51bf609c35cd99a9ca46dd859b17d8164a Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Tue, 24 Aug 2004 08:38:50 +0000 Subject: [PATCH] First cut at cleanup infrastructure. Due to the fact that db4 is incredibly fragile in the fact of abnormal termination and that Apache (and presumably other web servers) will merrily kill CGI as and when they see fit, we need to try and catch any signal we can and clean ourselves up. --- Makefile.in | 4 ++-- add.c | 3 ++- gpgwww.c | 4 +++- lookup.c | 2 ++ onak.c | 2 ++ stats.c | 7 ++++--- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile.in b/Makefile.in index de1420b..95e24f2 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,12 +15,12 @@ prefix ?= @prefix@ PROGS = add lookup gpgwww onak splitkeys onak-mail.pl CORE_OBJS = armor.o charfuncs.o decodekey.o getcgi.o hash.o keydb_$(DBTYPE).o \ keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha1.o md5.o \ - log.o photoid.o wordlist.o + log.o photoid.o wordlist.o cleanup.o OBJS = merge.o stats.o sendsync.o cleankey.o $(CORE_OBJS) SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha1.c main.c getcgi.c mem.c \ keyindex.c stats.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \ gpgwww.c onak-conf.c charfuncs.c sendsync.c log.c photoid.c \ - wordlist.c cleankey.c + wordlist.c cleankey.c cleanup.c all: .depend $(PROGS) testparse maxpath sixdegrees splitkeys diff --git a/add.c b/add.c index 2d38624..189444e 100644 --- a/add.c +++ b/add.c @@ -13,6 +13,7 @@ #include "armor.h" #include "cleankey.h" +#include "cleanup.h" #include "charfuncs.h" #include "getcgi.h" #include "keydb.h" @@ -70,6 +71,7 @@ int main(int argc, char *argv[]) end_html(); fclose(stdout); fclose(stderr); + catchsignals(); initdb(false); count = cleankeys(keys); @@ -77,7 +79,6 @@ int main(int argc, char *argv[]) count); count = update_keys(&keys); - printf("Got %d new keys.\n", count); logthing(LOGTHING_NOTICE, "Got %d new keys.", count); if (keys != NULL) { diff --git a/gpgwww.c b/gpgwww.c index cd3e096..87fe4ce 100644 --- a/gpgwww.c +++ b/gpgwww.c @@ -13,6 +13,7 @@ #include "armor.h" #include "charfuncs.h" +#include "cleanup.h" #include "getcgi.h" #include "hash.h" #include "keydb.h" @@ -75,7 +76,7 @@ int getkeyspath(uint64_t have, uint64_t want, int count) return 1; } - while (pathlen < count) { + while ((!cleanup()) && (pathlen < count)) { /* * Fill the tree info up. */ @@ -165,6 +166,7 @@ int main(int argc, char *argv[]) readconfig(NULL); initlogthing("gpgwww", config.logfile); + catchsignals(); initdb(true); inithash(); logthing(LOGTHING_NOTICE, "Looking for path from 0x%llX to 0x%llX.", diff --git a/lookup.c b/lookup.c index d5392d5..e4cab46 100644 --- a/lookup.c +++ b/lookup.c @@ -16,6 +16,7 @@ #include "armor.h" #include "charfuncs.h" #include "cleankey.h" +#include "cleanup.h" #include "getcgi.h" #include "keydb.h" #include "keyindex.h" @@ -156,6 +157,7 @@ int main(int argc, char *argv[]) } else { readconfig(NULL); initlogthing("lookup", config.logfile); + catchsignals(); initdb(true); switch (op) { case OP_GET: diff --git a/onak.c b/onak.c index 9af2c43..1dacae6 100644 --- a/onak.c +++ b/onak.c @@ -17,6 +17,7 @@ #include "armor.h" #include "charfuncs.h" #include "cleankey.h" +#include "cleanup.h" #include "keydb.h" #include "keyid.h" #include "keyindex.h" @@ -113,6 +114,7 @@ int main(int argc, char *argv[]) readconfig(configfile); initlogthing("onak", config.logfile); + catchsignals(); if ((argc - optind) < 1) { usage(); diff --git a/stats.c b/stats.c index 7b516c6..da1f13c 100644 --- a/stats.c +++ b/stats.c @@ -9,6 +9,7 @@ #include #include +#include "cleanup.h" #include "getcgi.h" #include "hash.h" #include "keydb.h" @@ -66,10 +67,10 @@ unsigned long findpath(struct stats_key *have, struct stats_key *want) keys = lladd(NULL, want); oldkeys = keys; - while (keys != NULL && have->colour == 0) { + while ((!cleanup()) && keys != NULL && have->colour == 0) { sigs = cached_getkeysigs(((struct stats_key *) keys->object)->keyid); - while (sigs != NULL && have->colour == 0) { + while ((!cleanup()) && sigs != NULL && have->colour == 0) { /* * Check if we've seen this key before and if not mark * it and add its sigs to the list we want to look at. @@ -147,7 +148,7 @@ void dofindpath(uint64_t have, uint64_t want, bool html, int count) pathnum = 0; - while (pathnum < count) { + while ((!cleanup()) && (pathnum < count)) { /* * Fill the tree info up. */ -- 2.30.2