diff --git a/data.c b/data.c index 0d7765c..0d497bf 100644 --- a/data.c +++ b/data.c @@ -1064,8 +1064,6 @@ void purge_all(void) xs *list = user_list(); char *p, *uid; - srv_debug(1, xs_fmt("purge start")); - p = list; while (xs_list_iter(&p, &uid)) { if (user_open(&snac, uid)) { @@ -1073,6 +1071,4 @@ void purge_all(void) user_free(&snac); } } - - srv_debug(1, xs_fmt("purge end")); } diff --git a/httpd.c b/httpd.c index 4233057..a365b4d 100644 --- a/httpd.c +++ b/httpd.c @@ -207,18 +207,37 @@ void term_handler(int s) } +static void *purge_thread(void *arg) +/* spawned purge */ +{ + srv_log(xs_dup("purge start")); + + purge_all(); + + srv_log(xs_dup("purge end")); + + return NULL; +} + + static void *queue_thread(void *arg) /* queue thread (queue management) */ { pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER; + time_t purge_time; + + /* first purge time */ + purge_time = time(NULL) + 15 * 60; srv_log(xs_fmt("queue thread start")); while (srv_running) { xs *list = user_list(); char *p, *uid; + time_t t; + /* process queues for all users */ p = list; while (xs_list_iter(&p, &uid)) { snac snac; @@ -229,6 +248,16 @@ static void *queue_thread(void *arg) } } + /* time to purge? */ + if ((t = time(NULL)) > purge_time) { + pthread_t pth; + + pthread_create(&pth, NULL, purge_thread, NULL); + + /* next purge time is tomorrow */ + purge_time = t + 24 * 60 * 60; + } + /* sleep 3 seconds */ struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts);