[Tarantool-patches] [PATCH] clear terminal state on panic

Serge Petrenko sergepetrenko at tarantool.org
Fri Nov 29 15:20:16 MSK 2019


> 29 нояб. 2019 г., в 14:15, Cyrill Gorcunov <gorcunov at gmail.com> написал(а):
> 
> On Fri, Nov 29, 2019 at 02:06:56PM +0300, Serge Petrenko wrote:
>> Hi! Thanks for your replies!
>> 
> 
> I meant different, something like
> 
> void
> tarantool_atexit(void)
> {
> 	/*
> 	 * Terminal settings might be screwed
> 	 * when exit on panic, restore the
> 	 * normal one.
> 	 */
> 	free_rl_state(void);
> }
> 
> ...
> 	at_exit(tarantool_atexit);
> 
> This will allow us to extend tarantool_atexit()
> with other cleanup routines if we need to.
> Sounds reasonable?

Well, we can append other routines to tarantool_atexit anyway.
I wrapped the code into free_rl_state() in the previous patch, but
it was inlined into tarantool_free «as_is» previously.
I mean

tarantool_free(void)
{
	/* Other cleanup routines */
	if (isatty(…)) {
		/* Clean rl state. */
	}
	/* Other cleanup routines */
}

But no problem, here’s the incremental diff
 
diff --git a/src/main.cc b/src/main.cc
index a1572b81e..e674d85b1 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -589,15 +589,8 @@ load_cfg()
 }
 
 void
-tarantool_atexit(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
         */
@@ -610,6 +603,19 @@ tarantool_atexit(void)
        }
 }
 
+void
+tarantool_atexit(void)
+{
+       /* Same checks as in tarantool_free() */
+       if (getpid() != master_pid)
+               return;
+
+       if (!cord_is_main())
+               return;
+
+       free_rl_state();
+}
+
 void
 tarantool_free(void)
 {


--
Serge Petrenko
sergepetrenko at tarantool.org



More information about the Tarantool-patches mailing list