]> the.earth.li Git - onak.git/commitdiff
First cut at cleanup infrastructure.
authorJonathan McDowell <noodles@earth.li>
Tue, 24 Aug 2004 08:38:50 +0000 (08:38 +0000)
committerJonathan McDowell <noodles@earth.li>
Tue, 24 Aug 2004 08:38:50 +0000 (08:38 +0000)
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
add.c
gpgwww.c
lookup.c
onak.c
stats.c

index de1420b96b10a3d126e6c0bb50f0c0c0e0039cd5..95e24f23fb66d596c7c6774cab8dc25a9a90782d 100644 (file)
@@ -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 2d38624d3f43dea1ac8e186b388d05ffe016e255..189444e294fb2d83af8869b3c943504c30fba810 100644 (file)
--- 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) {
index cd3e0960f0fd3eda58508a1ac5b16caae7a03877..87fe4ce67d3462a5dd8944ef3c73b76e3165538c 100644 (file)
--- 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.",
index d5392d599d318f806b059dd1e6fc043e0bfbed53..e4cab46f2ad362030db60c9f5cde4274dfa4b513 100644 (file)
--- 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 9af2c4310b21959d100ab0f9b987ae8acec2b940..1dacae627ac29508f4ffbb0491fb5191fca08141 100644 (file)
--- 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 7b516c6355aa1b284b85eecd807dca057db11454..da1f13c54e007b70fd8046b95b62f327fd58b602 100644 (file)
--- a/stats.c
+++ b/stats.c
@@ -9,6 +9,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#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.
                 */