bin/59036: Possible patch for PR's bin/56166 and bin/57414
Ken Smith
kensmith at cse.Buffalo.EDU
Fri Nov 7 05:20:02 PST 2003
>Number: 59036
>Category: bin
>Synopsis: Possible patch for PR's bin/56166 and bin/57414
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Nov 07 05:20:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: Ken Smith
>Release: FreeBSD 5.1-RELEASE-p10 i386
>Organization:
U. Buffalo CSE
>Environment:
System: FreeBSD opus.cse.buffalo.edu 5.1-RELEASE-p10 FreeBSD 5.1-RELEASE-p10 #1: Sat Oct 4 22:57:49 EDT 2003 root at opus.cse.buffalo.edu:/usr/obj/usr/src/sys/OPUS i386
>Description:
script(1) behaves badly if stdin is not a terminal.
>How-To-Repeat:
See PR's bin/56166 and bin/57414
>Fix:
This patch seems to fix at least 56166, has not been tested to see
if it fixes 57414 but problems seem related. The patch changes
script(1) so it does not try to do terminal-specific things to
stdin if it is not a terminal, and it does not immediately exit
if end-of-file is read from stdin when stdin is not a terminal.
--- script.c_orig Wed Sep 4 19:29:06 2002
+++ script.c Thu Oct 16 22:18:48 2003
@@ -67,9 +67,9 @@
int master, slave;
int child;
const char *fname;
-int qflg;
+int qflg, ttyflg;
-struct termios tt;
+struct termios tt, *ttptr;
void done(int) __dead2;
void dooutput(void);
@@ -83,7 +83,7 @@
{
int cc;
struct termios rtt, stt;
- struct winsize win;
+ struct winsize win, *winptr;
int aflg, kflg, ch, n;
struct timeval tv, *tvp;
time_t tvec, start;
@@ -93,6 +93,7 @@
int flushtime = 30;
aflg = kflg = 0;
+ winptr = NULL;
while ((ch = getopt(argc, argv, "aqkt:")) != -1)
switch(ch) {
case 'a':
@@ -126,9 +127,19 @@
if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL)
err(1, "%s", fname);
- (void)tcgetattr(STDIN_FILENO, &tt);
- (void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win);
- if (openpty(&master, &slave, NULL, &tt, &win) == -1)
+ if (ttyflg = isatty(STDIN_FILENO)) {
+ if (tcgetattr(STDIN_FILENO, &tt) == -1) {
+ err(1, "tcgetattr");
+ } else {
+ ttptr = &tt;
+ }
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) {
+ err(1, "ioctl");
+ } else {
+ winptr = &win;
+ }
+ }
+ if (openpty(&master, &slave, NULL, ttptr, winptr) == -1)
err(1, "openpty");
if (!qflg) {
@@ -137,10 +148,12 @@
(void)fprintf(fscript, "Script started on %s", ctime(&tvec));
fflush(fscript);
}
- rtt = tt;
- cfmakeraw(&rtt);
- rtt.c_lflag &= ~ECHO;
- (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt);
+ if (ttyflg) {
+ rtt = tt;
+ cfmakeraw(&rtt);
+ rtt.c_lflag &= ~ECHO;
+ (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt);
+ }
child = fork();
if (child < 0) {
@@ -169,7 +182,9 @@
break;
if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) {
cc = read(STDIN_FILENO, ibuf, BUFSIZ);
- if (cc <= 0)
+ if (cc < 0)
+ break;
+ if (cc == 0 && ttyflg)
break;
if (cc > 0) {
(void)write(master, ibuf, cc);
@@ -260,7 +275,8 @@
{
time_t tvec;
- (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt);
+ if (ttyflg)
+ (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, ttptr);
tvec = time(NULL);
if (!qflg) {
(void)fprintf(fscript,"\nScript done on %s", ctime(&tvec));
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list