Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH] clear terminal state on panic
Date: Tue, 26 Nov 2019 18:15:58 +0300	[thread overview]
Message-ID: <20191126151557.25754-1-sergepetrenko@tarantool.org> (raw)

The tarantool_free() call in the end of main() works all the time except
when we exit due to a panic. We need to clear terminal state in this
case also, so return to using atexit() to clear readline state.

Closes #4466
---
https://github.com/tarantool/tarantool/issues/4466
https://github.com/tarantool/tarantool/tree/sp/gh-4466-clear-rl-state

 src/main.cc | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/main.cc b/src/main.cc
index 0ff2213b6..014958a17 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -588,6 +588,28 @@ load_cfg()
 	box_cfg();
 }
 
+void
+free_rl_state(void)
+{
+	/* Same checks as in tarantool_free() */
+	if (getpid() != master_pid)
+		return;
+
+	if (!cord_is_main())
+		return;
+
+	/* 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)
 {
@@ -622,16 +644,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
 	/*
@@ -836,6 +848,8 @@ main(int argc, char **argv)
 		trigger_create(&break_loop_trigger, break_loop, NULL, NULL);
 		trigger_add(&box_on_shutdown, &break_loop_trigger);
 
+		atexit(free_rl_state);
+
 		if (!loop())
 			panic("%s", "can't init event loop");
 
-- 
2.21.0 (Apple Git-122)

             reply	other threads:[~2019-11-26 15:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26 15:15 Serge Petrenko [this message]
2019-11-26 20:56 ` Konstantin Osipov
2019-11-27 16:07   ` Cyrill Gorcunov
2019-11-27 21:51     ` Konstantin Osipov
2019-11-27 22:31       ` Cyrill Gorcunov
2019-11-29 11:06         ` Serge Petrenko
2019-11-29 11:15           ` Cyrill Gorcunov
2019-11-29 12:20             ` Serge Petrenko
2019-11-29 13:00               ` Cyrill Gorcunov
2019-11-29 14:53                 ` Konstantin Osipov
2019-12-10 14:03 ` Kirill Yukhin
2019-12-23 14:29   ` Alexander Turenko
2020-01-13 11:14     ` Alexander Turenko

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=20191126151557.25754-1-sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] clear terminal state on panic' \
    /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