diff options
| author | Jordan K. Hubbard <jkh@FreeBSD.org> | 1998-02-15 11:32:27 +0000 |
|---|---|---|
| committer | Jordan K. Hubbard <jkh@FreeBSD.org> | 1998-02-15 11:32:27 +0000 |
| commit | 2232ea795e402360483ae2e52a85b485f081e4dc (patch) | |
| tree | 530245f7ff5efa9301fcffcccb04966250424965 /bin | |
| parent | b9572e1d0c8c089910e9137a2f4787cf15926925 (diff) | |
Notes
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/sh/cd.h | 2 | ||||
| -rw-r--r-- | bin/sh/jobs.c | 3 | ||||
| -rw-r--r-- | bin/sh/miscbltin.c | 67 | ||||
| -rw-r--r-- | bin/sh/sh.1 | 11 | ||||
| -rw-r--r-- | bin/sh/trap.c | 18 | ||||
| -rw-r--r-- | bin/sh/trap.h | 4 |
6 files changed, 89 insertions, 16 deletions
diff --git a/bin/sh/cd.h b/bin/sh/cd.h index 2b00fc2b7c73..feb6d8156e41 100644 --- a/bin/sh/cd.h +++ b/bin/sh/cd.h @@ -29,6 +29,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ char *getpwd __P((void)); diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index 5578f7fefe74..cc4649e474b2 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: jobs.c,v 1.8.2.2 1997/08/17 14:47:33 joerg Exp $ + * $Id: jobs.c,v 1.8.2.3 1997/08/25 09:10:00 jkh Exp $ */ #ifndef lint @@ -45,7 +45,6 @@ static char const sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #include <errno.h> #include <unistd.h> #include <stdlib.h> -#include <sys/types.h> #include <sys/param.h> #ifdef BSD #include <sys/wait.h> diff --git a/bin/sh/miscbltin.c b/bin/sh/miscbltin.c index eedf55a0771a..dcff8f4ce7e0 100644 --- a/bin/sh/miscbltin.c +++ b/bin/sh/miscbltin.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: miscbltin.c,v 1.8 1996/09/03 14:24:44 peter Exp $ + * $Id: miscbltin.c,v 1.8.2.1 1997/08/25 09:10:10 jkh Exp $ */ #ifndef lint @@ -52,6 +52,7 @@ static char const sccsid[] = "@(#)miscbltin.c 8.4 (Berkeley) 5/4/95"; #include <ctype.h> #include <errno.h> #include <stdio.h> +#include <termios.h> #include "shell.h" #include "options.h" @@ -88,14 +89,43 @@ readcmd(argc, argv) int startword; int status; int i; + struct timeval tv; + char *tvptr; + fd_set ifds; + struct termios told, tnew; + int tsaved; eflag = 0; prompt = NULL; - while ((i = nextopt("ep:")) != '\0') { - if (i == 'p') + tv.tv_sec = -1; + tv.tv_usec = 0; + while ((i = nextopt("ep:t:")) != '\0') { + switch(i) { + case 'p': prompt = optarg; - else + break; + case 'e': eflag = 1; + break; + case 't': + tv.tv_sec = strtol(optarg, &tvptr, 0); + if (tvptr == optarg) + error("timeout value"); + switch(*tvptr) { + case 0: + case 's': + break; + case 'h': + tv.tv_sec *= 60; + /* FALLTHROUGH */ + case 'm': + tv.tv_sec *= 60; + break; + default: + error("timeout unit"); + } + break; + } } if (prompt && isatty(0)) { out2str(prompt); @@ -105,6 +135,35 @@ readcmd(argc, argv) error("arg count"); if ((ifs = bltinlookup("IFS", 1)) == NULL) ifs = nullstr; + + 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); + tcsetattr(0, TCSANOW, &tnew); + tsaved = 1; + } + /* + * Wait for something to become available. + */ + FD_ZERO(&ifds); + FD_SET(0, &ifds); + status = select(1, &ifds, NULL, NULL, &tv); + if (tsaved) + tcsetattr(0, TCSANOW, &told); + /* + * If there's nothing ready, return an error. + */ + if (status <= 0) + return(1); + } + status = 0; startword = 1; backslash = 0; diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index 4847e9c35de1..484121416406 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -33,7 +33,7 @@ .\" SUCH DAMAGE. .\" .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 -.\" $Id: sh.1,v 1.9.2.6 1998/01/02 19:25:11 steve Exp $ +.\" $Id: sh.1,v 1.9.2.7 1998/02/12 01:25:29 jdp Exp $ .\" .Dd May 5, 1995 .Dt SH 1 @@ -1136,7 +1136,7 @@ is rather than recomputing it each time. This makes it faster. However, if the current directory is renamed, the builtin version of pwd will continue to print the old name for the directory. -.It read [ -p prompt ] [ -e ] variable ... +.It Li "read [ -p prompt ] [ -t timeout ] [ -e ] variable ... The prompt is printed if the -p option is specified and the standard input is a terminal. Then a line is read from the standard input. The trailing newline @@ -1149,6 +1149,13 @@ separated them) are assigned to the last variable. If there are more variables than pieces, the remaining variables are assigned the null string. .Pp +If the -t option is specified the timeout elapses +before any input is supplied, the read command will +return without assigning any values. The timeout value +may optionally be followed by one of 's', 'm' or 'h' to +explicitly specify seconds, minutes or or hours. If none +is supplied, 's' is assumed. +.Pp The -e option causes any backslashes in the input to be treated specially. If a backslash is followed by a newline, the backslash and the newline will be diff --git a/bin/sh/trap.c b/bin/sh/trap.c index abfff4b9b0c5..e5f8c92c2d3a 100644 --- a/bin/sh/trap.c +++ b/bin/sh/trap.c @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: trap.c,v 1.4 1996/09/01 10:21:47 peter Exp $ + * $Id: trap.c,v 1.4.2.1 1997/08/25 09:10:46 jkh Exp $ */ #ifndef lint @@ -205,12 +205,12 @@ clear_traps() * Set the signal handler for the specified signal. The routine figures * out what it should be set to. */ -long +void setsignal(signo) int signo; { int action; - sig_t sigact = SIG_DFL; + sig_t sig, sigact = SIG_DFL; char *t; if ((t = trap[signo]) == NULL) @@ -260,7 +260,7 @@ setsignal(signo) * here, but other shells don't. We don't alter * sigmode, so that we retry every time. */ - return 0; + return; } if (sigact == SIG_IGN) { if (mflag && (signo == SIGTSTP || @@ -273,14 +273,18 @@ setsignal(signo) } } if (*t == S_HARD_IGN || *t == action) - return 0; + return; switch (action) { case S_DFL: sigact = SIG_DFL; break; case S_CATCH: sigact = onsig; break; case S_IGN: sigact = SIG_IGN; break; } *t = action; - return (long)signal(signo, sigact); + sig = signal(signo, sigact); +#ifdef BSD + if (sig != SIG_ERR && action == S_CATCH) + siginterrupt(signo, 1); +#endif } @@ -340,7 +344,9 @@ onsig(signo) int signo; { +#ifndef BSD signal(signo, onsig); +#endif if (signo == SIGINT && trap[SIGINT] == NULL) { onint(); return; diff --git a/bin/sh/trap.h b/bin/sh/trap.h index e57b6f2564e2..cfa05f196fce 100644 --- a/bin/sh/trap.h +++ b/bin/sh/trap.h @@ -34,14 +34,14 @@ * SUCH DAMAGE. * * @(#)trap.h 8.3 (Berkeley) 6/5/95 - * $Id: trap.h,v 1.3 1996/09/01 10:21:50 peter Exp $ + * $Id: trap.h,v 1.3.2.1 1997/08/25 09:10:48 jkh Exp $ */ extern int pendingsigs; int trapcmd __P((int, char **)); void clear_traps __P((void)); -long setsignal __P((int)); +void setsignal __P((int)); void ignoresig __P((int)); void onsig __P((int)); void dotrap __P((void)); |
