mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix Ctrl+D after ksh receives SIGWINCH (#208)
src/cmd/ksh93/edit/edit.c: ed_read(): - The loop that handles SIGWINCH assumes sfpkrd will return and set errno to EINTR if ksh is sent SIGWINCH. This only occurs when select(2) is used to wait for input, so tell sfpkrd to use select if possible. This is only done if the last argument given to sfpkrd is '2', which should avoid regressions. src/lib/libast/sfio/sfpkrd.c: sfpkrd(): - Always use select if the last argument is 2. This allows sfpkrd() to intercept SIGWINCH when necessary. Fixes: https://github.com/ksh93/ksh/issues/202
This commit is contained in:
parent
9f2389ed93
commit
c1986c4e1a
3 changed files with 17 additions and 8 deletions
3
NEWS
3
NEWS
|
@ -9,6 +9,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
did not perform an assignment and yielded the value 0 if 'var' was typeset as
|
did not perform an assignment and yielded the value 0 if 'var' was typeset as
|
||||||
numeric (integer or float) but had not yet been assigned a value.
|
numeric (integer or float) but had not yet been assigned a value.
|
||||||
|
|
||||||
|
- Fixed a bug introduced on 2020-08-19: Ctrl+D would break after an
|
||||||
|
interactive shell received SIGWINCH.
|
||||||
|
|
||||||
2021-03-05:
|
2021-03-05:
|
||||||
|
|
||||||
- Unbalanced quotes and backticks now correctly produce a syntax error
|
- Unbalanced quotes and backticks now correctly produce a syntax error
|
||||||
|
|
|
@ -833,15 +833,14 @@ static void ed_nputchar(register Edit_t *ep, int n, int c)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do read, restart on interrupt unless SH_SIGSET or SH_SIGTRAP is set
|
* Do read, restart on interrupt unless SH_SIGSET or SH_SIGTRAP is set
|
||||||
* Use sfpkrd() to poll() or select() to wait for input if possible
|
* Use select(2) (via sfpkrd()) to wait for input if possible
|
||||||
*
|
*
|
||||||
* The return value is the number of bytes read, or < 0 for EOF.
|
* The return value is the number of bytes read, or < 0 for EOF.
|
||||||
*
|
*
|
||||||
* Unfortunately, systems that get interrupted from slow reads update
|
* Unfortunately, systems that get interrupted from slow reads update
|
||||||
* this access time for the terminal (in violation of POSIX).
|
* this access time for the terminal (in violation of POSIX).
|
||||||
* The fixtime() macro resets the time to the time at entry in
|
* The fixtime() macro resets the time to the time at entry in
|
||||||
* this case. This is not necessary for systems that can handle
|
* this case. This is not necessary for systems that have select().
|
||||||
* sfpkrd() correctly (i.e., those that support poll() or select()).
|
|
||||||
*/
|
*/
|
||||||
int ed_read(void *context, int fd, char *buff, int size, int reedit)
|
int ed_read(void *context, int fd, char *buff, int size, int reedit)
|
||||||
{
|
{
|
||||||
|
@ -851,11 +850,12 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
|
||||||
Shell_t *shp = ep->sh;
|
Shell_t *shp = ep->sh;
|
||||||
int mode = -1;
|
int mode = -1;
|
||||||
int (*waitevent)(int,long,int) = shp->gd->waitevent;
|
int (*waitevent)(int,long,int) = shp->gd->waitevent;
|
||||||
|
/* sfpkrd must use select(2) to intercept SIGWINCH for ed_read */
|
||||||
if(ep->e_raw==ALTMODE)
|
if(ep->e_raw==ALTMODE)
|
||||||
mode = 1;
|
mode = 2;
|
||||||
if(size < 0)
|
if(size < 0)
|
||||||
{
|
{
|
||||||
mode = 1;
|
mode = 2;
|
||||||
size = -size;
|
size = -size;
|
||||||
}
|
}
|
||||||
sh_onstate(SH_TTYWAIT);
|
sh_onstate(SH_TTYWAIT);
|
||||||
|
|
|
@ -24,11 +24,12 @@
|
||||||
/*
|
/*
|
||||||
* The preferred method is POSIX recv(2) with MSG_PEEK, which is detected as 'socket_peek'.
|
* The preferred method is POSIX recv(2) with MSG_PEEK, which is detected as 'socket_peek'.
|
||||||
* On Solaris/Illumos (__sun), _stream_peek and _lib_select are needed, as _socket_peek doesn't work correctly.
|
* On Solaris/Illumos (__sun), _stream_peek and _lib_select are needed, as _socket_peek doesn't work correctly.
|
||||||
* On at least macOS and Linux, sfpkrd() runs significantly faster if we disable these.
|
* On at least macOS and Linux, sfpkrd() runs significantly faster if we disable these. However,
|
||||||
|
* ed_read() still needs to use select to intercept SIGWINCH, so if the last argument given
|
||||||
|
# to sfpkrd is '2' select is always used when available.
|
||||||
*/
|
*/
|
||||||
#if _socket_peek && !__sun
|
#if _socket_peek && !__sun
|
||||||
#undef _stream_peek
|
#undef _stream_peek
|
||||||
#undef _lib_select
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __APPLE__ && !_socket_peek
|
#if __APPLE__ && !_socket_peek
|
||||||
|
@ -55,6 +56,7 @@ long tm; /* time-out */
|
||||||
int action; /* >0: peeking, if rc>=0, get action records,
|
int action; /* >0: peeking, if rc>=0, get action records,
|
||||||
<0: no peeking, if rc>=0, get -action records,
|
<0: no peeking, if rc>=0, get -action records,
|
||||||
=0: no peeking, if rc>=0, must get a single record
|
=0: no peeking, if rc>=0, must get a single record
|
||||||
|
=2: same as >0, but always use select(2)
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -118,7 +120,11 @@ int action; /* >0: peeking, if rc>=0, get action records,
|
||||||
(t&SOCKET_PEEK) )
|
(t&SOCKET_PEEK) )
|
||||||
{ r = -2;
|
{ r = -2;
|
||||||
#if _lib_select
|
#if _lib_select
|
||||||
if(r == -2)
|
if(r == -2
|
||||||
|
#if !__sun /* select(2) is always used on Solaris or if action == 2 on other OSes */
|
||||||
|
&& action == 2
|
||||||
|
#endif
|
||||||
|
)
|
||||||
{ fd_set rd;
|
{ fd_set rd;
|
||||||
struct timeval tmb, *tmp;
|
struct timeval tmb, *tmp;
|
||||||
FD_ZERO(&rd);
|
FD_ZERO(&rd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue