From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Serge Petrenko Subject: [PATCH v4 1/2] box: get rid of atexit() for calling cleanup routines Date: Sat, 29 Dec 2018 16:45:39 +0300 Message-Id: <6349a23d064aeaf7e13246deff1f164009933ceb.1546090754.git.sergepetrenko@tarantool.org> In-Reply-To: References: In-Reply-To: References: To: vdavydov.dev@gmail.com Cc: kostja@tarantool.org, tarantool-patches@freelists.org, Serge Petrenko List-ID: Move a call to tarantool_free() to the end of main(). Only wal_thread_stop() is left in atexit() to make sure we close the journal in case the user exits by typing os.exit() to the console. --- src/box/box.cc | 8 ++++++++ src/box/box.h | 7 +++++++ src/main.cc | 32 ++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 9f2fd6da1..9642364f6 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -1693,9 +1693,17 @@ box_free(void) gc_free(); engine_shutdown(); wal_thread_stop(); + is_box_configured = false; } } +void +box_shutdown_wal(void) +{ + if (is_box_configured) + wal_thread_stop(); +} + static void engine_init() { diff --git a/src/box/box.h b/src/box/box.h index 6c6c319fc..cb9a512be 100644 --- a/src/box/box.h +++ b/src/box/box.h @@ -77,6 +77,13 @@ box_init(void); void box_free(void); +/** + * Kill WAL thread and close journal. + * Called at exit. + */ +void +box_shutdown_wal(void); + /** * Load configuration for box library. * Panics on error. diff --git a/src/main.cc b/src/main.cc index 993355ac4..4303fb32c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -534,6 +534,24 @@ load_cfg() box_cfg(); } +void +tarantool_atexit(void) +{ + box_shutdown_wal(); + + /* tarantool_lua_free() was formerly reponsible for terminal reset, + * but it is no longer called + */ + if (isatty(STDIN_FILENO)) { + /* + * Restore terminal state. Doesn't hurt if exiting not + * due to a signal. + */ + rl_cleanup_after_signal(); + } + +} + void tarantool_free(void) { @@ -568,16 +586,6 @@ tarantool_free(void) #ifdef ENABLE_GCOV __gcov_flush(); #endif - /* tarantool_lua_free() was formerly reponsible for terminal reset, - * but it is no longer called - */ - if (isatty(STDIN_FILENO)) { - /* - * Restore terminal state. Doesn't hurt if exiting not - * due to a signal. - */ - rl_cleanup_after_signal(); - } cbus_free(); #if 0 /* @@ -752,8 +760,7 @@ main(int argc, char **argv) box_init(); box_lua_init(tarantool_L); - /* main core cleanup routine */ - atexit(tarantool_free); + atexit(tarantool_atexit); if (!loop()) panic("%s", "can't init event loop"); @@ -793,5 +800,6 @@ main(int argc, char **argv) if (start_loop) say_crit("exiting the event loop"); /* freeing resources */ + tarantool_free(); return 0; } -- 2.17.2 (Apple Git-113)