Mon, 25 Sep 2017 00:35:58 +0200
Respect the original SIGWINCH's handler SA_SIGINFO field
Imported from https://developer.pidgin.im/ticket/16680 , authored by
marcus. When chaining the original SIGWINCH, make sure to optionally
call it with the extra arguments that are available when it was
installed with SA_SIGINFO.
| finch/libgnt/gntmain.c | file | annotate | diff | comparison | revisions |
--- a/finch/libgnt/gntmain.c Thu Sep 21 22:28:07 2017 -0500 +++ b/finch/libgnt/gntmain.c Mon Sep 25 00:35:58 2017 +0200 @@ -407,10 +407,11 @@ #ifdef SIGWINCH static void (*org_winch_handler)(int); +static void (*org_winch_handler_sa)(int, siginfo_t *, void *); #endif static void -sighandler(int sig) +sighandler(int sig, siginfo_t *info, void *data) { switch (sig) { #ifdef SIGWINCH @@ -419,16 +420,15 @@ g_idle_add((GSourceFunc)refresh_screen, NULL); if (org_winch_handler) org_winch_handler(sig); - signal(SIGWINCH, sighandler); + if (org_winch_handler_sa) + org_winch_handler_sa(sig, info, data); break; #endif case SIGCHLD: clean_pid(); - signal(SIGCHLD, sighandler); break; case SIGINT: ask_before_exit(); - signal(SIGINT, sighandler); break; } } @@ -456,6 +456,10 @@ { char *filename; const char *locale; + struct sigaction act; +#ifdef SIGWINCH + struct sigaction oact; +#endif if (channel) return; @@ -501,11 +505,25 @@ werase(stdscr); wrefresh(stdscr); + act.sa_sigaction = sighandler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + #ifdef SIGWINCH - org_winch_handler = signal(SIGWINCH, sighandler); + org_winch_handler = NULL; + org_winch_handler_sa = NULL; + sigaction(SIGWINCH, &act, &oact); + if (oact.sa_flags & SA_SIGINFO) + { + org_winch_handler_sa = oact.sa_sigaction; + } + else if (oact.sa_handler != SIG_DFL && oact.sa_handler != SIG_IGN) + { + org_winch_handler = oact.sa_handler; + } #endif - signal(SIGCHLD, sighandler); - signal(SIGINT, sighandler); + sigaction(SIGCHLD, &act, NULL); + sigaction(SIGINT, &act, NULL); signal(SIGPIPE, SIG_IGN); #if !GLIB_CHECK_VERSION(2, 36, 0)