From 0b70bbd66f3938fc153730e55c041d3c08a1fab1 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 02:38:53 -0400 Subject: [PATCH] tty_emit(): loop on EAGAIN #894 --- src/lib/internal.h | 20 ++++++++++++++------ src/lib/notcurses.c | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 1f142663c..aa3377dbb 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -464,15 +464,23 @@ tty_emit(const char* name __attribute__ ((unused)), const char* seq, int fd){ if(!seq){ return -1; } - ssize_t ret = write(fd, seq, strlen(seq)); - if(ret < 0){ + size_t slen = strlen(seq); + size_t written = 0; + do{ + ssize_t ret = write(fd, seq, slen); + if(ret > 0){ + written += ret; + } + if(ret < 0){ + if(errno != EAGAIN){ + break; + } + } + }while(written < slen); + if(written < slen){ //fprintf(stderr, "Error emitting %zub %s escape (%s)\n", strlen(seq), name, strerror(errno)); return -1; } - if((size_t)ret != strlen(seq)){ -//fprintf(stderr, "Short write (%db) for %zub %s sequence\n", ret, strlen(seq), name); - return -1; - } return 0; } diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 8c60ec345..c42390782 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -87,7 +87,7 @@ notcurses_stop_minimal(notcurses* nc){ } // this wildly unsafe handler will attempt to restore the screen upon -// reception of SIG{INT, SEGV, ABRT, QUIT}. godspeed you, black emperor! +// reception of SIG{INT, SEGV, ABRT, QUIT, TERM}. godspeed you, black emperor! static void fatal_handler(int signo){ notcurses* nc = atomic_load(&signal_nc);