summaryrefslogtreecommitdiff
path: root/src/c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c')
-rw-r--r--src/c/driver.c28
-rw-r--r--src/c/urweb.c2
2 files changed, 20 insertions, 10 deletions
diff --git a/src/c/driver.c b/src/c/driver.c
index 52999da3..44465cc3 100644
--- a/src/c/driver.c
+++ b/src/c/driver.c
@@ -67,15 +67,14 @@ static int try_rollback(uw_context ctx) {
return r;
}
-static void *worker(void *data) {
- int me = *(int *)data, retries_left = MAX_RETRIES;
+static uw_context new_context() {
uw_context ctx = uw_init();
-
+ int retries_left = MAX_RETRIES;
+
while (1) {
failure_kind fk = uw_begin_init(ctx);
if (fk == SUCCESS) {
- uw_db_init(ctx);
printf("Database connection initialized.\n");
break;
} else if (fk == BOUNDED_RETRY) {
@@ -94,12 +93,19 @@ static void *worker(void *data) {
uw_free(ctx);
return NULL;
} else {
- printf("Unknown uw_handle return code!\n");
+ printf("Unknown uw_begin_init return code!\n");
uw_free(ctx);
return NULL;
}
}
+ return ctx;
+}
+
+static void *worker(void *data) {
+ int me = *(int *)data, retries_left = MAX_RETRIES;
+ uw_context ctx = new_context();
+
while (1) {
char buf[uw_bufsize+1], *back = buf, *s;
int sock, dont_close = 0;
@@ -278,8 +284,10 @@ static void *worker(void *data) {
}
static void *client_pruner(void *data) {
- uw_context ctx = uw_init();
- uw_db_init(ctx);
+ uw_context ctx = new_context();
+
+ if (!ctx)
+ exit(1);
while (1) {
uw_prune_clients(ctx);
@@ -297,9 +305,11 @@ static void sigint(int signum) {
}
static void initialize() {
- uw_context ctx = uw_init();
+ uw_context ctx = new_context();
+
+ if (!ctx)
+ exit(1);
- uw_db_init(ctx);
if (uw_initialize(ctx) != SUCCESS) {
printf("Failed to initialize database!\n");
uw_db_rollback(ctx);
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 9915219d..1b3cfb1d 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -322,7 +322,7 @@ uw_context uw_init() {
buf_init(&ctx->outHeaders, 0);
buf_init(&ctx->page, 0);
buf_init(&ctx->heap, 0);
- buf_init(&ctx->script, 0);
+ buf_init(&ctx->script, 1);
ctx->script.start[0] = 0;
ctx->inputs = calloc(uw_inputs_len, sizeof(char *));