From 1563b706580ae2359f232c48e91514ee51add39a Mon Sep 17 00:00:00 2001 From: tg Date: Sat, 25 Jun 2016 23:52:46 +0000 Subject: [PATCH] abort read builtin in case of read(2) errors noticed by arekm, persuaded by jilles, compared with other equivalent pieces of code reading in mksh --- funcs.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/funcs.c b/funcs.c index ef4ab7e..741e9ad 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.295 2016/02/26 20:56:43 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.296 2016/06/25 23:52:46 tg Exp $"); #if HAVE_KILLPG /* @@ -2004,20 +2004,20 @@ c_read(const char **wp) } #endif - bytesread = blocking_read(fd, xp, bytesleft); - if (bytesread == (size_t)-1) { - /* interrupted */ - if (errno == EINTR && fatal_trap_check()) { - /* - * Was the offending signal one that would - * normally kill a process? If so, pretend - * the read was killed. - */ - rv = 2; - goto c_read_out; + if ((bytesread = blocking_read(fd, xp, bytesleft)) == (size_t)-1) { + if (errno == EINTR) { + /* check whether the signal would normally kill */ + if (!fatal_trap_check()) { + /* no, just ignore the signal */ + goto c_read_readloop; + } + /* pretend the read was killed */ + } else { + /* unexpected error */ + bi_errorf("%s", cstrerror(errno)); } - /* just ignore the signal */ - goto c_read_readloop; + rv = 2; + goto c_read_out; } c_read_didread: