sh: Make read's timeout (-t) apply to the entire line, not only the first
character. This avoids using non-standard behaviour of the old (upto FreeBSD 7) TTY layer: it reprocesses the input queue when switching to canonical mode. The new TTY layer does not provide this functionality and so read -t worked very poorly (first character is not echoed, cannot be backspaced but is still read). This also agrees with what most other shells with read -t do. PR: bin/129566 Reviewed by: stefanf Approved by: ed (mentor)
This commit is contained in:
parent
d5a70a77bc
commit
5abe4e352a
@ -103,8 +103,6 @@ readcmd(int argc __unused, char **argv __unused)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char *tvptr;
|
char *tvptr;
|
||||||
fd_set ifds;
|
fd_set ifds;
|
||||||
struct termios told, tnew;
|
|
||||||
int tsaved;
|
|
||||||
|
|
||||||
rflag = 0;
|
rflag = 0;
|
||||||
prompt = NULL;
|
prompt = NULL;
|
||||||
@ -150,27 +148,12 @@ readcmd(int argc __unused, char **argv __unused)
|
|||||||
ifs = " \t\n";
|
ifs = " \t\n";
|
||||||
|
|
||||||
if (tv.tv_sec >= 0) {
|
if (tv.tv_sec >= 0) {
|
||||||
/*
|
|
||||||
* See if we can disable input processing; this will
|
|
||||||
* not give the desired result if we are in a pipeline
|
|
||||||
* and someone upstream is still in line-by-line mode.
|
|
||||||
*/
|
|
||||||
tsaved = 0;
|
|
||||||
if (tcgetattr(0, &told) == 0) {
|
|
||||||
memcpy(&tnew, &told, sizeof(told));
|
|
||||||
cfmakeraw(&tnew);
|
|
||||||
tnew.c_iflag |= told.c_iflag & ICRNL;
|
|
||||||
tcsetattr(0, TCSANOW, &tnew);
|
|
||||||
tsaved = 1;
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* Wait for something to become available.
|
* Wait for something to become available.
|
||||||
*/
|
*/
|
||||||
FD_ZERO(&ifds);
|
FD_ZERO(&ifds);
|
||||||
FD_SET(0, &ifds);
|
FD_SET(0, &ifds);
|
||||||
status = select(1, &ifds, NULL, NULL, &tv);
|
status = select(1, &ifds, NULL, NULL, &tv);
|
||||||
if (tsaved)
|
|
||||||
tcsetattr(0, TCSANOW, &told);
|
|
||||||
/*
|
/*
|
||||||
* If there's nothing ready, return an error.
|
* If there's nothing ready, return an error.
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
|
.\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd October 7, 2006
|
.Dd May 31, 2009
|
||||||
.Dt SH 1
|
.Dt SH 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -1949,7 +1949,7 @@ If the
|
|||||||
.Fl t
|
.Fl t
|
||||||
option is specified and the
|
option is specified and the
|
||||||
.Ar timeout
|
.Ar timeout
|
||||||
elapses before any input is supplied,
|
elapses before a complete line of input is supplied,
|
||||||
the
|
the
|
||||||
.Ic read
|
.Ic read
|
||||||
command will return an exit status of 1 without assigning any values.
|
command will return an exit status of 1 without assigning any values.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user