From 7c47ab56fe1def28ac9977841fe70135df8c0d0c Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 8 Jan 2021 13:24:03 +0000 Subject: [PATCH] I/O: Properly handle EIO error (Solaris patch 275-20855453) This change is pulled from here: https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/275-20855453.patch https://github.com/att/ast/issues/30 George Lijo wrote on 17 Feb 2017: > Here's a reproducible testcase on a Solaris11 host running > ksh93u+(2012-08-01). > $ cat a.sh > #!/bin/sh > > AAA="aaa" > echo 'insert character' > BBB=`echo ${AAA} | sed "s/aaa/bbb/g"` > logger "variable BBB = ${BBB}" > > $ cat t.sh > #!/bin/ksh > > sleep 10 > /bin/ksh ./a.sh > exit 0 > > $ > > $ ./t.sh > > The expected result is: > > Apr 9 12:43:34 lab user: [ID 702911 user.notice] variable BBB = bbb > > because variable "BBB" is supposed to be set to 'bbb' in a.sh. > > But if the parent shell is terminated, the variable is wrongly set. > > user@xxxxx$ telnet lab > ... > $ ./t.sh & <--- Run t.sh in background. > [1] 2067 > $ logout <--- CTRL + D to exit while t.sh is running. > Connection to lab closed by foreign host. > > Again, access the system and check the output: > > user@xxxxx$ telnet lab > ... > $ tail -f /var/adm/messages > : > Apr 9 12:47:47 lab user: [ID 702911 user.notice] variable BBB = > insert character <--- !!! > Apr 9 12:47:47 lab bbb > <--- !!! > > Thus the variable is wrongly set. (The previous echo string was > not cleared.) > > The issue happens because the EIO error during the logout is not > handled properly. src/cmd/ksh93/sh/io.c, src/lib/libast/include/error.h: - Amend the ERROR_PIPE() macro to check for EIO as well as EPIPE and ECONNRESET. --- src/cmd/ksh93/sh/io.c | 4 ++-- src/lib/libast/include/error.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 6636e027fdb6..a433fff5177d 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -64,9 +64,9 @@ #ifndef ERROR_PIPE #ifdef ECONNRESET -#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET) +#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET||(e)==EIO) #else -#define ERROR_PIPE(e) ((e)==EPIPE) +#define ERROR_PIPE(e) ((e)==EPIPE||(e)==EIO) #endif #endif diff --git a/src/lib/libast/include/error.h b/src/lib/libast/include/error.h index 99c8899bf4cf..6baaf0d321f3 100644 --- a/src/lib/libast/include/error.h +++ b/src/lib/libast/include/error.h @@ -85,9 +85,9 @@ #define ERROR_SET 0x0080 /* set context */ #ifdef ECONNRESET -#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET) +#define ERROR_PIPE(e) ((e)==EPIPE||(e)==ECONNRESET||(e)==EIO) #else -#define ERROR_PIPE(e) ((e)==EPIPE) +#define ERROR_PIPE(e) ((e)==EPIPE||(e)==EIO) #endif /*