From 2e5fd4d4c10ac4e37233174908ad1f6853d21f7a Mon Sep 17 00:00:00 2001 From: atheik <14833674+atheik@users.noreply.github.com> Date: Wed, 23 Feb 2022 05:39:15 +0200 Subject: [PATCH] slowread(): Turn off O_NONBLOCK for stdin if it is on (#471) This change turns off O_NONBLOCK for stdin if a previously ran program left it on so that interactive programs that expect it to be off work properly. src/cmd/ksh93/sh/io.c: slowread(): - Turn off O_NONBLOCK for stdin if it is on. Fixes: https://github.com/ksh93/ksh/issues/469 --- COPYRIGHT | 1 + NEWS | 6 ++++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/io.c | 10 +++++++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/COPYRIGHT b/COPYRIGHT index 094009660..7bff14f9c 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -18,6 +18,7 @@ ksh 93u+m general copyright notice # Johnothan King # # hyenias <58673227+hyenias@users.noreply.github.com> # # Anuradha Weeraman # +# atheik # # Chase # # Finnbarr P. Murphy # # Govind Kamat # diff --git a/NEWS b/NEWS index ddf09b3e4..4cd349e44 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0 Any uppercase BUG_* names are modernish shell bug IDs. +2022-08-23: + +- When reading input from the keyboard, ksh now turns off nonblocking I/O + mode for standard input if a previously ran program left it on, so that + interactive programs that expect it to be off work properly. + 2022-02-18: - Fixed a regression introduced on 2021-04-11 that caused the += operator in diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index d5d23c617..a7e2ac1de 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -21,7 +21,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2022-02-18" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2022-02-23" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 20215585d..a3b749238 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -1944,7 +1944,7 @@ static ssize_t piperead(Sfio_t *iop,void *buff,register size_t size,Sfdisc_t *ha static ssize_t slowread(Sfio_t *iop,void *buff,register size_t size,Sfdisc_t *handle) { int (*readf)(void*, int, char*, int, int); - int reedit=0, rsize; + int reedit=0, rsize, n, fno; #if SHOPT_HISTEXPAND char *xp=0; #endif /* SHOPT_HISTEXPAND */ @@ -1969,6 +1969,14 @@ static ssize_t slowread(Sfio_t *iop,void *buff,register size_t size,Sfdisc_t *ha errno = EINTR; return(-1); } + fno = sffileno(iop); +#ifdef O_NONBLOCK + if((n=fcntl(fno,F_GETFL,0))!=-1 && n&O_NONBLOCK) + { + n &= ~O_NONBLOCK; + fcntl(fno, F_SETFL, n); + } +#endif /* O_NONBLOCK */ while(1) { if(io_prompt(iop,sh.nextprompt)<0 && errno==EIO)