aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2024-09-19 14:18:52 +1000
committerSteve Bennett <steveb@workware.net.au>2024-09-20 11:15:50 +1000
commit04faf00753541dd414074e7589d92e93d765f034 (patch)
treedbeefb68dadd693c41718c657347b03cb9fa5064
parent5039667299909e872e921a1cd8a7a7c275aa1816 (diff)
downloadjimtcl-04faf00753541dd414074e7589d92e93d765f034.zip
jimtcl-04faf00753541dd414074e7589d92e93d765f034.tar.gz
jimtcl-04faf00753541dd414074e7589d92e93d765f034.tar.bz2
aio: write: on EPIPE, discard the write buffer
If SIGPIPE is blocked, write may return EPIPE. On interpreter shutdown we try to flush write buffers and in this case we are likely to get an unexpected SIGPIPE since the signal may no longer be blocked. Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-aio.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/jim-aio.c b/jim-aio.c
index 4c59e1d..e25af18 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -194,9 +194,17 @@ typedef struct AioFile
Jim_Obj *writebuf; /* Contains any buffered write data. refcount=1 */
} AioFile;
+static void aio_consume(Jim_Obj *objPtr, int n);
+
static int stdio_writer(struct AioFile *af, const char *buf, int len)
{
- return write(af->fd, buf, len);
+ int ret = write(af->fd, buf, len);
+ if (ret < 0 && errno == EPIPE) {
+ /* Also discard the write buffer since otherwise when
+ * we try to flush on shutdown we may get SIGPIPE */
+ aio_consume(af->writebuf, Jim_Length(af->writebuf));
+ }
+ return ret;
}
static int stdio_reader(struct AioFile *af, char *buf, int len, int nb)