Add all handled signals to ppoll() set

This addresses an issue where callers of notcurses_getc_blocking()
wouldn't exit on SIGINT etc. until another keystroke was received.
The exit is now immediate, and the proper exit code is propagated.
This commit is contained in:
nick black 2019-12-04 21:45:52 -05:00 committed by Nick Black
parent 6f2c45a0ef
commit 04e067c202

View File

@ -3,13 +3,17 @@
sig_atomic_t resize_seen = 0;
// add the keypress we just read to our input queue (assuming there is room).
// if there is a full UTF8 codepoint or keystroke (composed or otherwise),
// return it, and pop it from the queue.
static int
handle_getc(const notcurses* nc __attribute__ ((unused)), cell* c, int kpress,
ncspecial_key* special){
// fprintf(stderr, "KEYPRESS: %d\n", kpress);
fprintf(stderr, "KEYPRESS: %d\n", kpress);
if(kpress < 0){
return -1;
}
// FIXME add it to the queue, then consult queue
*special = 0;
if(kpress == 0x04){ // ctrl-d
return -1;
@ -30,6 +34,7 @@ int notcurses_getc(const notcurses* nc, cell* c, ncspecial_key* special){
*special = NCKEY_RESIZE;
return 1;
}
// FIXME check queue
int r = getc(nc->ttyinfp);
if(r < 0){
return r;
@ -49,15 +54,18 @@ int notcurses_getc_blocking(const notcurses* nc, cell* c, ncspecial_key* special
sigset_t smask;
sigfillset(&smask);
sigdelset(&smask, SIGWINCH);
sigdelset(&smask, SIGINT);
sigdelset(&smask, SIGQUIT);
sigdelset(&smask, SIGSEGV);
while((pret = ppoll(&pfd, 1, NULL, &smask)) >= 0){
if(pret == 0){
continue;
}
r = getc(nc->ttyinfp);
r = notcurses_getc(nc, c, special);
if(r < 0){
break; // want EINTR handling below
}
return handle_getc(nc, c, r, special);
return r;
}
if(errno == EINTR){
if(resize_seen){