diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-28 12:29:39 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-04-28 12:29:39 +0200 |
commit | d96fe9be9824c8be3837ce2d2707baf98c00b162 (patch) | |
tree | ca93d031aa1924a9b7e8a223cd48f2eec15b9d8f /src | |
parent | c78fabde1f572f28e0b1f2f71f358606ac943c01 (diff) | |
download | weechat-d96fe9be9824c8be3837ce2d2707baf98c00b162.zip |
Fixed infinite loop when closing terminal without using /quit command (bug #23078)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/curses/gui-curses-keyboard.c | 59 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 53 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-window.c | 10 | ||||
-rw-r--r-- | src/gui/curses/gui-curses.h | 1 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 8 | ||||
-rw-r--r-- | src/gui/gui-keyboard.h | 2 |
6 files changed, 85 insertions, 48 deletions
diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index 713c4d388..154fb2dbf 100644 --- a/src/gui/curses/gui-curses-keyboard.c +++ b/src/gui/curses/gui-curses-keyboard.c @@ -23,6 +23,7 @@ #include "config.h" #endif +#include <unistd.h> #include <stdlib.h> #include <string.h> #include <time.h> @@ -334,7 +335,8 @@ gui_keyboard_flush () int gui_keyboard_read_cb (void *data) { - int key, accept_paste, cancel_paste, text_added_to_buffer, paste_lines; + int ret, i, accept_paste, cancel_paste, text_added_to_buffer, paste_lines; + unsigned char buffer[4096]; /* make C compiler happy */ (void) data; @@ -342,35 +344,44 @@ gui_keyboard_read_cb (void *data) accept_paste = 0; cancel_paste = 0; text_added_to_buffer = 0; - - while (1) + + if (gui_keyboard_paste_pending) { - key = getch (); + ret = read (STDIN_FILENO, buffer, 1); + if (ret == 0) + { + /* no data on stdin, terminal lost */ + quit_weechat = 1; + return WEECHAT_RC_OK; + } + if (ret <= 0) + return WEECHAT_RC_OK; - if (key == ERR) - break; + /* ctrl-Y: accept paste */ + if (buffer[0] == 25) + accept_paste = 1; -#ifdef KEY_RESIZE - if (key == KEY_RESIZE) - continue; -#endif - if (gui_keyboard_paste_pending) + /* ctrl-N: cancel paste */ + if (buffer[0] == 14) + cancel_paste = 1; + } + else + { + ret = read (STDIN_FILENO, buffer, sizeof (buffer)); + if (ret == 0) { - /* ctrl-Y: accept paste */ - if (key == 25) - { - accept_paste = 1; - break; - } - /* ctrl-N: cancel paste */ - else if (key == 14) - { - cancel_paste = 1; - break; - } + /* no data on stdin, terminal lost */ + quit_weechat = 1; + return WEECHAT_RC_OK; + } + if (ret < 0) + return WEECHAT_RC_OK; + + for (i = 0; i < ret; i++) + { + gui_keyboard_buffer_add (buffer[i]); } - gui_keyboard_buffer_add (key); text_added_to_buffer = 1; } diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index ee60b7487..2933ddec6 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -33,6 +33,7 @@ #include "../../core/wee-command.h" #include "../../core/wee-config.h" #include "../../core/wee-hook.h" +#include "../../core/wee-log.h" #include "../../core/wee-string.h" #include "../../core/wee-utf8.h" #include "../../core/wee-util.h" @@ -52,6 +53,9 @@ #include "gui-curses.h" +int gui_reload_config = 0; + + /* * gui_main_pre_init: pre-initialize GUI (called before gui_init) */ @@ -150,23 +154,48 @@ gui_main_init () } /* - * gui_main_quit: quit WeeChat + * gui_main_signal_sigquit: quit WeeChat + */ + +void +gui_main_signal_sigquit () +{ + log_printf (_("Signal %s received, quitting WeeChat..."), + "SIGQUIT"); + quit_weechat = 1; +} + +/* + * gui_main_signal_sigterm: quit WeeChat */ void -gui_main_quit () +gui_main_signal_sigterm () { + log_printf (_("Signal %s received, quitting WeeChat..."), + "SIGTERM"); quit_weechat = 1; } /* - * gui_main_reload: reload WeeChat configuration + * gui_main_signal_sighup: reload WeeChat configuration */ void -gui_main_reload () +gui_main_signal_sighup () { - command_reload (NULL, NULL, 0, NULL, NULL); + log_printf (_("Signal SIGHUP received, reloading configuration files")); + gui_reload_config = 1; +} + +/* + * gui_main_signal_sigwinch: called when signal SIGWINCH is received + */ + +void +gui_main_signal_sigwinch () +{ + gui_window_refresh_needed = 1; } /* @@ -187,13 +216,14 @@ gui_main_loop () quit_weechat = 0; /* catch SIGTERM signal: quit program */ - util_catch_signal (SIGTERM, &gui_main_quit); + util_catch_signal (SIGTERM, &gui_main_signal_sigterm); + util_catch_signal (SIGQUIT, &gui_main_signal_sigquit); /* catch SIGHUP signal: reload configuration */ - util_catch_signal (SIGHUP, &gui_main_reload); + util_catch_signal (SIGHUP, &gui_main_signal_sighup); /* catch SIGWINCH signal: redraw screen */ - util_catch_signal (SIGWINCH, &gui_window_refresh_screen_sigwinch); + util_catch_signal (SIGWINCH, &gui_main_signal_sigwinch); /* hook stdin (read keyboard) */ hook_fd_keyboard = hook_fd (NULL, STDIN_FILENO, 1, 0, 0, @@ -201,6 +231,13 @@ gui_main_loop () while (!quit_weechat) { + /* reload config, if SIGHUP reveived */ + if (gui_reload_config) + { + gui_reload_config = 0; + command_reload (NULL, NULL, 0, NULL, NULL); + } + /* execute hook timers */ hook_timer_exec (); diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index adff0e7fb..77a8ece29 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -1753,16 +1753,6 @@ gui_window_refresh_screen () } /* - * gui_window_refresh_screen_sigwinch: called when signal SIGWINCH is received - */ - -void -gui_window_refresh_screen_sigwinch () -{ - gui_window_refresh_needed = 1; -} - -/* * gui_window_title_set: set terminal title */ diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 4d8981fa2..87d1f2675 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -103,7 +103,6 @@ extern void gui_window_set_custom_color_fg_bg (WINDOW *window, int fg, int bg); extern void gui_window_set_custom_color_fg (WINDOW *window, int fg); extern void gui_window_set_custom_color_bg (WINDOW *window, int bg); extern void gui_window_clrtoeol_with_current_bg (WINDOW *window); -extern void gui_window_refresh_screen_sigwinch (); extern void gui_window_title_set (); extern void gui_window_title_reset (); diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index 12a33c33f..6d94d8268 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -762,7 +762,7 @@ gui_keyboard_buffer_reset () */ void -gui_keyboard_buffer_add (int key) +gui_keyboard_buffer_add (unsigned char key) { if (!gui_keyboard_buffer) gui_keyboard_buffer_reset (); @@ -774,9 +774,9 @@ gui_keyboard_buffer_add (int key) if (gui_keyboard_buffer) { gui_keyboard_buffer[gui_keyboard_buffer_size - 1] = key; - if ((key == 10) + if ((key == 13) && (gui_keyboard_buffer_size > 1) - && (gui_keyboard_buffer[gui_keyboard_buffer_size - 2] != 10)) + && (gui_keyboard_buffer[gui_keyboard_buffer_size - 2] != 13)) gui_keyboard_paste_lines++; } else @@ -797,7 +797,7 @@ int gui_keyboard_get_paste_lines () { if ((gui_keyboard_buffer_size > 0) - && (gui_keyboard_buffer[gui_keyboard_buffer_size - 1] != 10)) + && (gui_keyboard_buffer[gui_keyboard_buffer_size - 1] != 13)) return gui_keyboard_paste_lines + 1; return gui_keyboard_paste_lines; diff --git a/src/gui/gui-keyboard.h b/src/gui/gui-keyboard.h index b726ec4b5..515b755c1 100644 --- a/src/gui/gui-keyboard.h +++ b/src/gui/gui-keyboard.h @@ -77,7 +77,7 @@ extern void gui_keyboard_free (struct t_gui_key **keys, extern void gui_keyboard_free_all (struct t_gui_key **keys, struct t_gui_key **last_key); extern void gui_keyboard_buffer_reset (); -extern void gui_keyboard_buffer_add (int key); +extern void gui_keyboard_buffer_add (unsigned char key); extern int gui_keyboard_get_paste_lines (); extern void gui_keyboard_paste_accept (); extern void gui_keyboard_paste_cancel (); |