diff --git a/src/linked.c b/src/linked.c index b7415ca..686326b 100644 --- a/src/linked.c +++ b/src/linked.c @@ -2,6 +2,8 @@ #include #include +#include + #include "linked.h" linkedList_t linked_create() { @@ -228,12 +230,29 @@ void linked_destroy(linkedList_t* list) { link_t* link = list->first; + link_t** first = &(list->first); + while(link != NULL) { pthread_mutex_lock(&(link->lock)); link_t* next = link->next; - // no new links can be added, so we can unlock link (next can't be changed) - pthread_mutex_unlock(&(link->lock)); - linked_unlink(link); + + if (next != NULL) { + pthread_mutex_lock(&(next->lock)); + *first = next; + next->prev = NULL; + pthread_mutex_unlock(&(next->lock)); + } + + // no need to keep, we are going to clear the list anyway + link->next = NULL; + link->unlinked = true; + + if (link->inUse == 0) { + linked_free(link); + } else { + pthread_mutex_unlock(&(link->lock)); + } + link = next; } diff --git a/src/test.c b/src/test.c index a63ee7a..4ffc198 100644 --- a/src/test.c +++ b/src/test.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "networking.h" #include "linked.h" @@ -133,9 +134,25 @@ void testLinkedList() { checkInt(linked_length(&list), 2, "list length"); + if (pthread_mutex_trylock(&(list.lock)) != 0) { + checkBool(false, "list unlocked"); + } else { + checkBool(true, "list unlocked"); + pthread_mutex_unlock(&(list.lock)); + } + link = list.first; while(link != NULL) { checkInt(link->inUse, 0, "raw inUse"); + + if (pthread_mutex_trylock(&(link->lock)) != 0) { + checkBool(false, "raw unlocked"); + } else { + checkBool(true, "raw unlocked"); + pthread_mutex_unlock(&(link->lock)); + } + + link = link->next; } @@ -261,12 +278,12 @@ void testConfig() { checkInt(config->binds[0]->nrSites, 1, "site no check"); checkInt(config->binds[0]->sites[0]->nrHostnames, 1, "site hostname no check"); checkString(config->binds[0]->sites[0]->hostnames[0], "example.com", "site hostname check"); - checkString(config->binds[0]->sites[0]->documentRoot, "/var/www", "site document root check"); + checkString(config->binds[0]->sites[0]->documentRoot, "/", "site document root check"); checkInt(config->binds[0]->sites[0]->nrHandlers, 1, "handler no check"); checkString(config->binds[0]->sites[0]->handlers[0]->dir, "/", "handler dir check"); checkInt(config->binds[0]->sites[0]->handlers[0]->type, FILE_HANDLER_NO, "handler type no check"); checkVoid(config->binds[0]->sites[0]->handlers[0]->handler, &fileHandler, "handler ptr check"); - checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/var/www", "handler settings root check"); + checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/", "handler settings root check"); checkInt(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.number, 1, "handler settings index no"); checkString(config->binds[0]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.files[0], "index.html", "handler settings index check"); checkString(config->logging.accessLogfile, "access.log", "access log file check"); @@ -283,12 +300,12 @@ void testConfig() { checkInt(config->binds[1]->nrSites, 1, "site no check"); checkInt(config->binds[1]->sites[0]->nrHostnames, 1, "site hostname no check"); checkString(config->binds[1]->sites[0]->hostnames[0], "example.com", "site hostname check"); - checkString(config->binds[1]->sites[0]->documentRoot, "/var/www", "site document root check"); + checkString(config->binds[1]->sites[0]->documentRoot, "/", "site document root check"); checkInt(config->binds[1]->sites[0]->nrHandlers, 1, "handler no check"); checkString(config->binds[1]->sites[0]->handlers[0]->dir, "/", "handler dir check"); checkInt(config->binds[1]->sites[0]->handlers[0]->type, FILE_HANDLER_NO, "handler type no check"); checkVoid(config->binds[1]->sites[0]->handlers[0]->handler, &fileHandler, "handler ptr check"); - checkString(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/var/www", "handler settings root check"); + checkString(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.documentRoot, "/", "handler settings root check"); checkInt(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.number, 1, "handler settings index no"); checkString(config->binds[1]->sites[0]->handlers[0]->settings.fileSettings.indexfiles.files[0], "index.html", "handler settings index check"); #endif diff --git a/tests/test-with-ssl.conf b/tests/test-with-ssl.conf index 8929070..a953017 100644 --- a/tests/test-with-ssl.conf +++ b/tests/test-with-ssl.conf @@ -1,7 +1,7 @@ bind 0.0.0.0:80 { site { hostname = example.com - root = /var/www + root = / handler / { type = file index = index.html @@ -15,7 +15,7 @@ bind 0.0.0.0:443 { } site { hostname = example.com - root = /var/www + root = / handler / { type = file index = index.html diff --git a/tests/test.conf b/tests/test.conf index 504d574..5bf9027 100644 --- a/tests/test.conf +++ b/tests/test.conf @@ -1,7 +1,7 @@ bind 0.0.0.0:80 { site { hostname = example.com - root = /var/www + root = / handler / { type = file index = index.html