Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: vdavydov.dev@gmail.com
Cc: kostja@tarantool.org, tarantool-patches@freelists.org,
	Serge Petrenko <sergepetrenko@tarantool.org>
Subject: [PATCH v4 1/2] box: get rid of atexit() for calling cleanup routines
Date: Sat, 29 Dec 2018 16:45:39 +0300	[thread overview]
Message-ID: <6349a23d064aeaf7e13246deff1f164009933ceb.1546090754.git.sergepetrenko@tarantool.org> (raw)
In-Reply-To: <cover.1546090754.git.sergepetrenko@tarantool.org>
In-Reply-To: <cover.1546090754.git.sergepetrenko@tarantool.org>

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)

  reply	other threads:[~2018-12-29 13:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-29 13:45 [PATCH v4 0/2] box: implement on_shutdown triggers Serge Petrenko
2018-12-29 13:45 ` Serge Petrenko [this message]
2018-12-29 13:45 ` [PATCH v4 2/2] " Serge Petrenko
2019-01-09 10:14   ` Vladimir Davydov
2019-01-09 14:01     ` [tarantool-patches] " Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6349a23d064aeaf7e13246deff1f164009933ceb.1546090754.git.sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v4 1/2] box: get rid of atexit() for calling cleanup routines' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox