diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-04-02 11:42:26 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-04-02 11:42:26 -0400 |
commit | 410f5f902ea5b94ef79c8c4e01fd2eb35a971184 (patch) | |
tree | 242dec8599fcb0beb86ed1a7554c4210413f1a04 /src/c | |
parent | 6d5d1a66b3d72515ea14167be005a9a3faf19b0e (diff) |
On start-up, delete/nullify rows mentioning clients or channels
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/driver.c | 19 | ||||
-rw-r--r-- | src/c/urweb.c | 26 |
2 files changed, 38 insertions, 7 deletions
diff --git a/src/c/driver.c b/src/c/driver.c index 14d08b57..52999da3 100644 --- a/src/c/driver.c +++ b/src/c/driver.c @@ -69,7 +69,7 @@ static int try_rollback(uw_context ctx) { static void *worker(void *data) { int me = *(int *)data, retries_left = MAX_RETRIES; - uw_context ctx = uw_init(0, 0, 1024, 0); + uw_context ctx = uw_init(); while (1) { failure_kind fk = uw_begin_init(ctx); @@ -278,7 +278,7 @@ static void *worker(void *data) { } static void *client_pruner(void *data) { - uw_context ctx = uw_init(0, 0, 0, 0); + uw_context ctx = uw_init(); uw_db_init(ctx); while (1) { @@ -296,6 +296,19 @@ static void sigint(int signum) { exit(0); } +static void initialize() { + uw_context ctx = uw_init(); + + uw_db_init(ctx); + if (uw_initialize(ctx) != SUCCESS) { + printf("Failed to initialize database!\n"); + uw_db_rollback(ctx); + exit(1); + } + + uw_free(ctx); +} + int main(int argc, char *argv[]) { // The skeleton for this function comes from Beej's sockets tutorial. int sockfd; // listen on sock_fd @@ -342,6 +355,8 @@ int main(int argc, char *argv[]) { } } + initialize(); + names = calloc(nthreads, sizeof(int)); sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking! diff --git a/src/c/urweb.c b/src/c/urweb.c index 62d5be1b..1165c5d1 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -308,15 +308,15 @@ struct uw_context { extern int uw_inputs_len, uw_timeout; -uw_context uw_init(size_t outHeaders_len, size_t script_len, size_t page_len, size_t heap_len) { +uw_context uw_init() { uw_context ctx = malloc(sizeof(struct uw_context)); ctx->headers = ctx->headers_end = NULL; - buf_init(&ctx->outHeaders, outHeaders_len); - buf_init(&ctx->page, page_len); - buf_init(&ctx->heap, heap_len); - buf_init(&ctx->script, script_len); + buf_init(&ctx->outHeaders, 0); + buf_init(&ctx->page, 0); + buf_init(&ctx->heap, 0); + buf_init(&ctx->script, 0); ctx->script.start[0] = 0; ctx->inputs = calloc(uw_inputs_len, sizeof(char *)); @@ -1931,3 +1931,19 @@ void uw_prune_clients(uw_context ctx) { pthread_mutex_unlock(&clients_mutex); } + +void uw_initializer(uw_context ctx); + +failure_kind uw_initialize(uw_context ctx) { + int r = setjmp(ctx->jmp_buf); + + if (r == 0) { + if (uw_db_begin(ctx)) + uw_error(ctx, FATAL, "Error running SQL BEGIN"); + uw_initializer(ctx); + if (uw_db_commit(ctx)) + uw_error(ctx, FATAL, "Error running SQL COMMIT"); + } + + return r; +} |