diff --git a/src/base/commands.c b/src/base/commands.c index 2795b388fd78ffe8aeec9e72c42c83e668eeaea7..5fc5b0ac8eedd10e6ee2078d0400252c00fc4d60 100644 --- a/src/base/commands.c +++ b/src/base/commands.c @@ -71,15 +71,18 @@ command_rescan(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX] return ! MOD_PROC(srv->repo_mod, "rescan"); } -inline bool +bool command_kill(struct lkt_state *srv, size_t c, char __attribute__((unused)) *argv[LKT_MESSAGE_ARGS_MAX]) { RETURN_UNLESS(lkt_client_auth(srv, c, false), "Failed to authentificate user", false); LOG_INFO("GENERAL", "Stopping lektord"); + MOD_PROC(srv->repo_mod, "free"); + MOD_PROC(srv->window_mod, "free"); close(srv->fds[0].fd); lkt_queue_free(&srv->queue); database_close_all(); + LOG_INFO("GENERAL", "lektord will now exit"); exit(EXIT_SUCCESS); } diff --git a/src/module/module_repo.c b/src/module/module_repo.c index 348756da15f2ffcd30e2f8c35fa8b5d153e72f3c..2e08eedd2ced0ba27c96af79294d7d3b4930487d 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -401,10 +401,12 @@ __worker_rescan(void *__repo) static inline void module_repo_close(struct module_repo_internal *repo) { + LOG_INFO("REPO", "Waiting for workers to finish"); worker_pool_waitall(&repo->workers); + LOG_INFO("REPO", "All workers have finished"); } -static bool +static inline bool module_repo_new(struct module_repo_internal *repo_, struct queue *queue, volatile sqlite3 *db) { RETURN_UNLESS(repo_ && queue && db, "Invalid argument", 1); @@ -504,6 +506,7 @@ mod_free(va_list *va) repo = (struct module_repo_internal **) va_arg(copy, void **); module_repo_close(*repo); + worker_pool_free(&(*repo)->workers); --__curl_init; if (!__curl_init) curl_global_cleanup(); @@ -513,6 +516,7 @@ mod_free(va_list *va) free((*repo)->base_url); free((*repo)->get_all_json); + LOG_INFO("REPO", "Repo module terminated"); va_end(copy); return 0; } diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index 6b4d4e2460093f9b5d843758d5b2715ae1fec29d..874756c32aedc89fd6f965f04c50366ec578a2bb 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -452,6 +452,7 @@ module_sdl2_close(struct module_sdl2_window *win) RETURN_UNLESS(win->mpv, "Missing mpv ctx", NOTHING); static const char *cmd[] = { "stop", NULL }; mpv_command_async((mpv_handle *) win->mpv, 0, cmd); + LOG_INFO("SDL2", "Module closed"); /* TODO: make the SDL window background be black. */ } @@ -459,10 +460,13 @@ static void module_sdl2_free(struct module_sdl2_window *win) { RETURN_UNLESS(win, "Invalid arguments", NOTHING); + module_sdl2_close(win); + LOG_INFO("SDL2", "Waiting for window thread"); win->launched = 2; while (win->launched) sched_yield(); poller_join(&win->self, NULL); + LOG_INFO("SDL2", "Module terminated"); } static bool