changeset 700:db6ab16cd8f3

Initialize contexts a little more vigorously
author Adam Chlipala <adamc@hcoop.net>
date Sun, 05 Apr 2009 12:05:19 -0400
parents 4e260887d8f2
children f963356b53fd
files src/c/driver.c src/c/urweb.c
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/driver.c	Sun Apr 05 11:48:55 2009 -0400
+++ b/src/c/driver.c	Sun Apr 05 12:05:19 2009 -0400
@@ -306,12 +306,19 @@
 
 static void initialize() {
   uw_context ctx = new_context();
+  failure_kind fk;
 
   if (!ctx)
     exit(1);
 
-  if (uw_initialize(ctx) != SUCCESS) {
-    printf("Failed to initialize database!\n");
+  for (fk = uw_initialize(ctx); fk == UNLIMITED_RETRY; fk = uw_initialize(ctx)) {
+    printf("Unlimited retry during init: %s\n", uw_error_message(ctx));
+    uw_db_rollback(ctx);
+    uw_reset(ctx);
+  }
+
+  if (fk != SUCCESS) {
+    printf("Failed to initialize database!  %s\n", uw_error_message(ctx));
     uw_db_rollback(ctx);
     exit(1);
   }
--- a/src/c/urweb.c	Sun Apr 05 11:48:55 2009 -0400
+++ b/src/c/urweb.c	Sun Apr 05 12:05:19 2009 -0400
@@ -346,6 +346,10 @@
 
   ctx->timeout = uw_timeout;
 
+  ctx->client = NULL;
+
+  ctx->error_message[0] = 0;
+
   return ctx;
 }
 
@@ -1872,7 +1876,7 @@
 void uw_commit(uw_context ctx) {
   unsigned i;
 
-  if (uw_db_commit(ctx))
+  if (uw_db_commit(ctx)) 
     uw_error(ctx, FATAL, "Error running SQL COMMIT");
 
   for (i = 0; i < ctx->used_deltas; ++i) {