Skip to content

Commit

Permalink
I/O: Properly handle EIO error (Solaris patch 275-20855453)
Browse files Browse the repository at this point in the history
This change is pulled from here:
https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/275-20855453.patch
att#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.
  • Loading branch information
McDutchie committed Jan 8, 2021
1 parent 3f38f8a commit 7c47ab5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cmd/ksh93/sh/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/lib/libast/include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down

0 comments on commit 7c47ab5

Please sign in to comment.