From 972681e708c1125efcdbc9b260854f10a9df37bd Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 30 Dec 2021 12:05:30 +0900 Subject: [PATCH] Call finalize synchronously when app termination is requested by app fw Current code always calls finalize using ecore timer, so finalize codes must be called on next event loop. However, finalize can not be worked because there is no event loop when app is terminated by outside app terminate request. This behavior can make unintended problem. To resolve this problem this patch makes server call finalize synchronously when app is terminated by outside request. By this change, finalize must be called in the case. Change-Id: Ib22cf36fd16e227ad606b78dbbfbd660242335bf Signed-off-by: Suyeon Hwang --- server/ttsd_server.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/server/ttsd_server.c b/server/ttsd_server.c index aae83d7..d6bd0ca 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -59,6 +59,8 @@ static GList *g_proc_list = NULL; static bool g_is_paused; +static bool g_is_terminated = false; + /* Function definitions */ static int __synthesis(unsigned int uid, const char* credential); @@ -443,9 +445,40 @@ bool __terminate_client(int pid, unsigned int uid, app_tts_state_e state, void* return true; } +static void __terminate_server() +{ + if (g_is_terminated) { + SLOG(LOG_INFO, tts_tag(), "[INFO] ttsd_terminate() is already invoked."); + return; + } + + g_is_terminated = true; + + ttsd_ipc_close_connection(); + ttsd_network_finalize(); + ttsd_finalize(); +} + +static Eina_Bool __quit_ecore_loop(void *data) +{ + __terminate_server(); + ecore_main_loop_quit(); + + return EINA_FALSE; +} + Eina_Bool ttsd_terminate_daemon(void *data) { ttsd_data_foreach_clients(__terminate_client, NULL); + + if (g_quit_loop_timer) { + ecore_timer_del(g_quit_loop_timer); + g_quit_loop_timer = NULL; + SLOG(LOG_INFO, tts_tag(), "[INFO] Delete ecore quit loop timer handle"); + } + + __terminate_server(); + g_terminate_timer = NULL; return EINA_FALSE; } @@ -485,6 +518,7 @@ int ttsd_send_all_stop() int ttsd_initialize(ttse_request_callback_s *callback) { SLOG(LOG_INFO, tts_tag(), "[Server] Initialize"); + g_is_terminated = false; if (ttsd_config_initialize(__config_changed_cb)) { SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config."); @@ -670,17 +704,6 @@ int ttsd_server_initialize(int pid, unsigned int uid, tts_ipc_method_e method, b return TTSD_ERROR_NONE; } -static Eina_Bool __quit_ecore_loop(void *data) -{ - ttsd_ipc_close_connection(); - ttsd_network_finalize(); - ttsd_finalize(); - ecore_main_loop_quit(); - - return EINA_FALSE; -} - - static void __read_proc() { DIR *dp = NULL; -- 2.7.4