From 75fe626aa60a4175c5b833ab8afe271120d88106 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 19 Sep 2016 19:53:08 +0200 Subject: [PATCH] terminal-unix: don't send quit command on terminal_uninit() Until now, the terminal thread always sent a quit command if the terminal thread was torn down (whether it happened via terminal_uninit() or a quit signal). This is not so good if we want to enable toggling terminal use at runtime, since disabling the terminal would always make the player quit. So we want terminal_uninit() not to send quit. This can be easily fixed by using the "death byte" sent to the pipe used for thread tear-down to indicate whether it was caused by a signal or terminal_uninit(). --- osdep/terminal-unix.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index e62903055a..64d6df3f37 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -378,7 +378,7 @@ static void quit_request_sighandler(int signum) { do_deactivate_getch2(); - (void)write(death_pipe[1], &(char){0}, 1); + (void)write(death_pipe[1], &(char){1}, 1); } static void *terminal_thread(void *ptr) @@ -397,10 +397,14 @@ static void *terminal_thread(void *ptr) if (fds[1].revents) stdin_ok = getch2(input_ctx); } + char c; + bool quit = read(death_pipe[0], &c, 1) == 1 && c == 1; // Important if we received SIGTERM, rather than regular quit. - struct mp_cmd *cmd = mp_input_parse_cmd(input_ctx, bstr0("quit 4"), ""); - if (cmd) - mp_input_queue_cmd(input_ctx, cmd); + if (quit) { + struct mp_cmd *cmd = mp_input_parse_cmd(input_ctx, bstr0("quit 4"), ""); + if (cmd) + mp_input_queue_cmd(input_ctx, cmd); + } return NULL; }