]> the.earth.li Git - onak.git/blobdiff - keydb_db3.c
cscvs to tla changeset 59
[onak.git] / keydb_db3.c
index de24f750d2656ad04c6c53fc7367fdbbbb601eb2..21977193fd41cf9fb2f1b72d5b439e378becb7c2 100644 (file)
@@ -25,6 +25,7 @@
 #include "decodekey.h"
 #include "keystructs.h"
 #include "mem.h"
+#include "log.h"
 #include "onak-conf.h"
 #include "parsekey.h"
 
@@ -111,20 +112,22 @@ void initdb(void)
 
        ret = db_env_create(&dbenv, 0);
        if (ret != 0) {
-               fprintf(stderr, "db_env_create: %s\n", db_strerror(ret));
+               logthing(LOGTHING_CRITICAL,
+                       "db_env_create: %s", db_strerror(ret));
                exit(1);
        }
 
        /*
-        * This is a bit of a kludge. Either we run a separate process for
-        * deadlock detection or we do this every time we run. What we really
-        * want to do is specify that our locks are exclusive locks when we
-        * start to do an update.
+        * Enable deadlock detection so that we don't block indefinitely on
+        * anything. What we really want is simple 2 state locks, but I'm not
+        * sure how to make the standard DB functions do that yet.
         */
-       ret = lock_detect(dbenv,
-                       0, /* flags */
-                       DB_LOCK_RANDOM,
-                       NULL); /* If non null int* for number broken */
+       ret = dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT);
+       if (ret != 0) {
+               logthing(LOGTHING_CRITICAL,
+                       "db_env_create: %s", db_strerror(ret));
+               exit(1);
+       }
 
        ret = dbenv->open(dbenv, config.db_dir,
                        DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_LOCK |
@@ -138,7 +141,8 @@ void initdb(void)
 
        ret = db_create(&dbconn, dbenv, 0);
        if (ret != 0) {
-               fprintf(stderr, "db_create: %s\n", db_strerror(ret));
+               logthing(LOGTHING_CRITICAL,
+                               "db_create: %s", db_strerror(ret));
                exit(1);
        }
 
@@ -154,7 +158,7 @@ void initdb(void)
 
        ret = db_create(&worddb, dbenv, 0);
        if (ret != 0) {
-               fprintf(stderr, "db_create: %s\n", db_strerror(ret));
+               logthing(LOGTHING_CRITICAL, "db_create: %s", db_strerror(ret));
                exit(1);
        }
        ret = worddb->set_flags(worddb, DB_DUP);