Subject: Re: script(1) regression
To: None <current-users@netbsd.org>
From: Jukka Salmi <j+nbsd@2007.salmi.ch>
List: current-users
Date: 08/19/2007 16:21:30
--qcHopEYAB45HaUaB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Jukka Salmi --> current-users (2007-08-19 10:53:45 +0200):
> the following regression was introduced with usr.bin/script/script.c
> rev. 1.12 which fixed PR [1]bin/26363.
[...]

Christos Zoulas --> source-changes (2007-08-19 10:31:13 +0000):
> 
> Module Name:	src
> Committed By:	christos
> Date:		Sun Aug 19 10:31:13 UTC 2007
> 
> Modified Files:
> 	src/usr.bin/script: script.c
> 
> Log Message:
> deal with non-regular files.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -r1.12 -r1.13 src/usr.bin/script/script.c

Thanks! But this is not enough, script(1) still fseek(2)s on the fifo...
The attached patch should fix this.


Cheers, Jukka

-- 
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~

--qcHopEYAB45HaUaB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: usr.bin/script/script.c
===================================================================
RCS file: /cvsroot/src/usr.bin/script/script.c,v
retrieving revision 1.13
diff -u -p -r1.13 script.c
--- usr.bin/script/script.c	19 Aug 2007 10:31:13 -0000	1.13
+++ usr.bin/script/script.c	19 Aug 2007 13:58:10 -0000
@@ -90,6 +90,7 @@ void	finish(int);
 int	main(int, char **);
 void	scriptflush(int);
 void	record(FILE *, char *, size_t, int);
+void	consume(FILE *, off_t, char *, int);
 void	playback(FILE *);
 
 int
@@ -303,6 +304,25 @@ record(FILE *fscript, char *buf, size_t 
 		err(1, "writev");
 }
 
+void
+consume(FILE *fscript, off_t len, char *buf, int reg)
+{
+	size_t l;
+
+	if (reg) {
+		if (fseek(fscript, len, SEEK_CUR) == -1)
+			err(1, NULL);
+	}
+	else {
+		while (len > 0) {
+			l = MIN(DEF_BUF, len);
+			if (fread(buf, sizeof(char), l, fscript) != l)
+				err(1, "cannot read buffer");
+			len -= l;
+		}
+	}
+}
+
 #define swapstamp(stamp) do { \
 	if (stamp.scr_direction > 0xff) { \
 		stamp.scr_len = bswap64(stamp.scr_len); \
@@ -352,15 +372,15 @@ playback(FILE *fscript)
 		case 's':
 			(void)printf("Script started on %s", ctime(&clock));
 			tsi = tso;
-			fseek(fscript, stamp.scr_len, SEEK_CUR);
+			(void)consume(fscript, stamp.scr_len, buf, reg);
 			break;
 		case 'e':
 			(void)printf("\nScript done on %s", ctime(&clock));
-			fseek(fscript, stamp.scr_len, SEEK_CUR);
+			(void)consume(fscript, stamp.scr_len, buf, reg);
 			break;
 		case 'i':
 			/* throw input away */
-			fseek(fscript, stamp.scr_len, SEEK_CUR);
+			(void)consume(fscript, stamp.scr_len, buf, reg);
 			break;
 		case 'o':
 			tsi.tv_sec = tso.tv_sec - tsi.tv_sec;

--qcHopEYAB45HaUaB--