From bd4d543d507eae887e72d5503e6bc6e1aa1a76de Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 8 Sep 2006 13:51:32 +0000 Subject: [PATCH] New signals handled: SIGTERM and SIGHUP (received when terminal is closed): clean WeeChat quit (send quit to irc servers then quit WeeChat) --- ChangeLog | 4 +++- src/gui/curses/gui-curses-main.c | 23 +++++++++++++++++++++++ weechat/ChangeLog | 4 +++- weechat/src/gui/curses/gui-curses-main.c | 23 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe7cb7c29..1f29a5a8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,12 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2006-09-02 +ChangeLog - 2006-09-08 Version 0.2.1 (under dev!): + * new signals handled: SIGTERM and SIGHUP (received when terminal is closed): + clean WeeChat quit (send quit to irc servers then quit WeeChat) * added some new default key bindings for existing keys (for some OS) * command /key now ok with one arg (key name): display key if found * fixed bug with CTCP VERSION sent on channels (bug #17547) diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 5e3c4425e..2e6306a3b 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -36,6 +36,7 @@ #include "../../common/utf8.h" #include "../../common/util.h" #include "../../common/weeconfig.h" +#include "../../irc/irc.h" #include "gui-curses.h" #ifdef PLUGINS @@ -43,6 +44,20 @@ #endif +int send_irc_quit = 0; + + +/* + * gui_main_quit: quit weechat (signal received) + */ + +void +gui_main_quit () +{ + quit_weechat = 1; + send_irc_quit = 1; +} + /* * gui_main_loop: main loop for WeeChat with ncurses GUI */ @@ -61,6 +76,7 @@ gui_main_loop () struct tm *local_time; quit_weechat = 0; + send_irc_quit = 0; new_time = time (NULL); gui_last_activity_time = new_time; @@ -70,6 +86,11 @@ gui_main_loop () old_min = -1; old_sec = -1; check_away = 0; + + /* if SIGTERM or SIGHUP received => quit */ + signal (SIGTERM, gui_main_quit); + signal (SIGHUP, gui_main_quit); + while (!quit_weechat) { /* refresh needed ? */ @@ -261,6 +282,8 @@ gui_main_loop () /* manages active DCC */ dcc_handle (); } + if (send_irc_quit) + irc_cmd_send_quit (NULL, NULL, NULL); } /* diff --git a/weechat/ChangeLog b/weechat/ChangeLog index fe7cb7c29..1f29a5a8e 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -1,10 +1,12 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2006-09-02 +ChangeLog - 2006-09-08 Version 0.2.1 (under dev!): + * new signals handled: SIGTERM and SIGHUP (received when terminal is closed): + clean WeeChat quit (send quit to irc servers then quit WeeChat) * added some new default key bindings for existing keys (for some OS) * command /key now ok with one arg (key name): display key if found * fixed bug with CTCP VERSION sent on channels (bug #17547) diff --git a/weechat/src/gui/curses/gui-curses-main.c b/weechat/src/gui/curses/gui-curses-main.c index 5e3c4425e..2e6306a3b 100644 --- a/weechat/src/gui/curses/gui-curses-main.c +++ b/weechat/src/gui/curses/gui-curses-main.c @@ -36,6 +36,7 @@ #include "../../common/utf8.h" #include "../../common/util.h" #include "../../common/weeconfig.h" +#include "../../irc/irc.h" #include "gui-curses.h" #ifdef PLUGINS @@ -43,6 +44,20 @@ #endif +int send_irc_quit = 0; + + +/* + * gui_main_quit: quit weechat (signal received) + */ + +void +gui_main_quit () +{ + quit_weechat = 1; + send_irc_quit = 1; +} + /* * gui_main_loop: main loop for WeeChat with ncurses GUI */ @@ -61,6 +76,7 @@ gui_main_loop () struct tm *local_time; quit_weechat = 0; + send_irc_quit = 0; new_time = time (NULL); gui_last_activity_time = new_time; @@ -70,6 +86,11 @@ gui_main_loop () old_min = -1; old_sec = -1; check_away = 0; + + /* if SIGTERM or SIGHUP received => quit */ + signal (SIGTERM, gui_main_quit); + signal (SIGHUP, gui_main_quit); + while (!quit_weechat) { /* refresh needed ? */ @@ -261,6 +282,8 @@ gui_main_loop () /* manages active DCC */ dcc_handle (); } + if (send_irc_quit) + irc_cmd_send_quit (NULL, NULL, NULL); } /*