sfeed_curses

[fork] sfeed (atom feed) reader
Log | Files | Refs | README | LICENSE

commit 27d1130c82989d2773c5b4b3957c66ae0ed20706
parent 951c9714bff19a8919af72d2e0e837b2a6521ce5
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 29 Jun 2020 19:46:39 +0200

use sigaction instead of signal and enforce BSD signal semantics (SA_RESTART)

Noticed while testing on Void Linux (glibc) and compiling without _BSD_SOURCE.
SIGWINCH is an extension but it will compile.
It will (silently) use different Linux semantics and cause issues on SIGWINCH.

So use sigaction and make sure to set SA_RESTART.

Diffstat:
Msfeed_curses.c | 16++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/sfeed_curses.c b/sfeed_curses.c @@ -353,6 +353,8 @@ mousemode(int on) void cleanup(void) { + struct sigaction sa; + if (!needcleanup) return; @@ -369,7 +371,11 @@ cleanup(void) resettitle(); fflush(stdout); - signal(SIGWINCH, SIG_DFL); + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; + sa.sa_handler = SIG_DFL; + if (sigaction(SIGWINCH, &sa, NULL) == -1) + err(1, "sigaction: SIGWINCH"); needcleanup = 0; } @@ -396,6 +402,8 @@ getwinsize(void) void init(void) { + struct sigaction sa; + tcgetattr(ttyfd, &tsave); memcpy(&tcur, &tsave, sizeof(tcur)); tcur.c_lflag &= ~(ECHO|ICANON); @@ -415,7 +423,11 @@ init(void) fflush(stdout); - signal(SIGWINCH, sighandler); + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART; /* require BSD signal semantics */ + sa.sa_handler = sighandler; + if (sigaction(SIGWINCH, &sa, NULL) == -1) + err(1, "sigaction: SIGWINCH"); needcleanup = 1; }