Page MenuHomeFreeBSD

D44167.id135411.diff
No OneTemporary

D44167.id135411.diff

diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1
--- a/usr.bin/script/script.1
+++ b/usr.bin/script/script.1
@@ -131,6 +131,8 @@
which is useful for both tools and humans to read, should be used.
Note that time-stamps will only be output when different from the
previous one.
+.It Fl w
+Forward terminal size changes on SIGWINCH.
.El
.Pp
The script ends when the forked shell (or command) exits (a
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c
--- a/usr.bin/script/script.c
+++ b/usr.bin/script/script.c
@@ -76,6 +76,7 @@
static int fflg, qflg, ttyflg;
static int usesleep, rawout, showexit;
static TAILQ_HEAD(, buf_elm) obuf_list = TAILQ_HEAD_INITIALIZER(obuf_list);
+static volatile sig_atomic_t doresize;
static struct termios tt;
@@ -93,11 +94,13 @@
static void consume(FILE *, off_t, char *, int);
static void playback(FILE *) __dead2;
static void usage(void) __dead2;
+static void resizeit(int);
int
main(int argc, char *argv[])
{
struct termios rtt, stt;
+ struct sigaction sa;
struct winsize win;
struct timeval tv, *tvp;
time_t tvec, start;
@@ -106,27 +109,35 @@
fd_set rfd, wfd;
struct buf_elm *be;
ssize_t cc;
- int aflg, Fflg, kflg, pflg, ch, k, n, fcm;
+ int aflg, Fflg, kflg, pflg, wflg, ch, k, n, fcm;
int flushtime, readstdin;
int fm_fd, fm_log;
- aflg = Fflg = kflg = pflg = 0;
+ aflg = Fflg = kflg = pflg = wflg = 0;
+ doresize = 0;
usesleep = 1;
rawout = 0;
flushtime = 30;
- fm_fd = -1; /* Shut up stupid "may be used uninitialized" GCC
- warning. (not needed w/clang) */
+
+ /*
+ * To shut up stupid "may be used uninitialized" GCC
+ * warning. (not needed w/clang)
+ */
+ fm_fd = -1;
showexit = 0;
- while ((ch = getopt(argc, argv, "adeFfkpqrT:t:")) != -1)
- switch(ch) {
+ while ((ch = getopt(argc, argv, "adeFfkpqrT:t:w")) != -1)
+ switch (ch) {
case 'a':
aflg = 1;
break;
case 'd':
usesleep = 0;
break;
- case 'e': /* Default behavior, accepted for linux compat */
+ /*
+ * Default behavior, accepted for linux compat
+ */
+ case 'e':
break;
case 'F':
Fflg = 1;
@@ -156,6 +167,9 @@
if (strchr(optarg, '%'))
tstamp_fmt = optarg;
break;
+ case 'w':
+ wflg = 1;
+ break;
case '?':
default:
usage();
@@ -257,6 +271,14 @@
}
close(slave);
+ if (wflg) {
+ sa.sa_flags = 0;
+ sa.sa_handler = resizeit;
+ sigemptyset(&sa.sa_mask);
+
+ sigaction(SIGWINCH, &sa, NULL);
+ }
+
start = tvec = time(0);
readstdin = 1;
for (;;) {
@@ -282,6 +304,14 @@
n = select(master + 1, &rfd, &wfd, NULL, tvp);
if (n < 0 && errno != EINTR)
break;
+
+ if (doresize) {
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) != -1) {
+ ioctl(master, TIOCSWINSZ, &win);
+ }
+ doresize = 0;
+ }
+
if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) {
cc = read(STDIN_FILENO, ibuf, BUFSIZ);
if (cc < 0)
@@ -331,7 +361,7 @@
}
}
if (n > 0 && FD_ISSET(master, &rfd)) {
- cc = read(master, obuf, sizeof (obuf));
+ cc = read(master, obuf, sizeof(obuf));
if (cc <= 0)
break;
(void)write(STDOUT_FILENO, obuf, cc);
@@ -356,7 +386,7 @@
usage(void)
{
(void)fprintf(stderr,
- "usage: script [-aeFfkpqr] [-t time] [file [command ...]]\n");
+ "usage: script [-aeFfkpqrw] [-t time] [file [command ...]]\n");
(void)fprintf(stderr,
" script -p [-deq] [-T fmt] [file]\n");
exit(1);
@@ -417,7 +447,7 @@
if (showexit)
(void)fprintf(fscript, "\nCommand exit status:"
" %d", eno);
- (void)fprintf(fscript,"\nScript done on %s",
+ (void)fprintf(fscript, "\nScript done on %s",
ctime(&tvec));
}
(void)printf("\nScript done, output file is %s\n", fname);
@@ -459,8 +489,7 @@
if (reg) {
if (fseeko(fp, len, SEEK_CUR) == -1)
err(1, NULL);
- }
- else {
+ } else {
while (len > 0) {
l = MIN(DEF_BUF, len);
if (fread(buf, sizeof(char), l, fp) != l)
@@ -603,3 +632,9 @@
(void)fclose(fp);
exit(0);
}
+
+static void
+resizeit(int __unused signo)
+{
+ doresize = 1;
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 9, 10:17 AM (3 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28544264
Default Alt Text
D44167.id135411.diff (3 KB)

Event Timeline