[ncplayer] block SIGWINCH from the beginning #1624

pull/1626/head
nick black 3 years ago
parent af093d397c
commit 584f394071
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -542,7 +542,7 @@ int main(int argc, char** argv){
// ensure SIGWINCH is delivered only to a thread doing input
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGWINCH);
pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
pthread_sigmask(SIG_BLOCK, &sigmask, NULL);
const char* spec;
FILE* json = NULL; // emit JSON summary to this file? (-J)
notcurses_options nopts = {};

@ -610,9 +610,6 @@ typedef struct notcurses {
int loglevel;
palette256 palette; // 256-indexed palette can be used instead of/with RGB
bool palette_damage[NCPALETTESIZE];
// we block many signals while writing out a frame, since interrupted escapes
// can lock up a terminal. this preserves the signal mask on entry.
sigset_t old_blocked_signals;
unsigned stdio_blocking_save; // was stdio blocking at entry? restore on stop.
} notcurses;
@ -1618,8 +1615,8 @@ int setup_signals(void* nc, bool no_quit_sigs, bool no_winch_sig,
int drop_signals(void* nc);
// block a few signals for the duration of a write to the terminal.
int block_signals(struct notcurses* nc);
int unblock_signals(struct notcurses* nc);
int block_signals(sigset_t* old_blocked_signals);
int unblock_signals(const sigset_t* old_blocked_signals);
void ncvisual_printbanner(const notcurses* nc);

@ -1145,11 +1145,12 @@ raster_and_write(notcurses* nc, ncpile* p, FILE* out){
}
int ret = 0;
//fflush(nc->ttyfp);
block_signals(nc);
sigset_t oldmask;
block_signals(&oldmask);
if(blocking_write(fileno(nc->ttyfp), nc->rstate.mstream, nc->rstate.mstrsize)){
ret = -1;
}
unblock_signals(nc);
unblock_signals(&oldmask);
//fprintf(stderr, "%lu/%lu %lu/%lu %lu/%lu %d\n", nc->stats.defaultelisions, nc->stats.defaultemissions, nc->stats.fgelisions, nc->stats.fgemissions, nc->stats.bgelisions, nc->stats.bgemissions, ret);
if(nc->renderfp){
fprintf(nc->renderfp, "%s\n", nc->rstate.mstream);

@ -30,17 +30,15 @@ static sigset_t wblock_signals;
static int(*fatal_callback)(void*); // fatal handler callback
int block_signals(notcurses* nc){
if(pthread_sigmask(SIG_BLOCK, &wblock_signals, &nc->old_blocked_signals)){
logerror(nc, "Couldn't block signals prior to write (%s)\n", strerror(errno));
int block_signals(sigset_t* old_blocked_signals){
if(pthread_sigmask(SIG_BLOCK, &wblock_signals, old_blocked_signals)){
return -1;
}
return 0;
}
int unblock_signals(notcurses* nc){
if(pthread_sigmask(SIG_SETMASK, &nc->old_blocked_signals, NULL)){
logerror(nc, "Error restoring signal mask after write (%s)\n", strerror(errno));
int unblock_signals(const sigset_t* old_blocked_signals){
if(pthread_sigmask(SIG_SETMASK, old_blocked_signals, NULL)){
return -1;
}
return 0;

@ -501,6 +501,11 @@ auto main(int argc, char** argv) -> int {
std::cerr << "Couldn't set locale based off LANG\n";
return EXIT_FAILURE;
}
sigset_t sigmask;
// ensure SIGWINCH is delivered only to a thread doing input
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGWINCH);
pthread_sigmask(SIG_BLOCK, &sigmask, NULL);
float timescale, displaytime;
ncscale_e scalemode;
notcurses_options ncopts{};

Loading…
Cancel
Save