On 07/16/18 18:11, bijan wrote:
On 07/13/18 22:35, bijan wrote:
Hi tech.
While trying to test liveshell[1], I noticed the script(1) from base is
missing the -f option, flushing the output after each write, which is
kinda critical for monitoring the output file by another process. the
Linux script utility uses fflush(3) after each write (duhh) but I'm not
sure if anything more than removing buffering operation from
the stream is necessary.
So here's the diff which is working for me
ping! no one is interested or am I missing something? added -f for quiet
option out of boredom
Now that I noticed my mail client was messing with the diff's format (after
hitting send), I should first apologize for the unnecessary noise on the
list.
Just checked that attaching the Diff is safe to call it a day for now.
Thank you
--
Bijan Ebrahimi
diff --git usr.bin/script/script.1 usr.bin/script/script.1
index f10ec2d4b..55e7e6868 100644
--- usr.bin/script/script.1
+++ usr.bin/script/script.1
@@ -38,7 +38,7 @@
.Nd make typescript of terminal session
.Sh SYNOPSIS
.Nm script
-.Op Fl a
+.Op Fl afq
.Op Fl c Ar command
.Op Ar file
.Sh DESCRIPTION
@@ -71,6 +71,10 @@ Run
.Ar command
instead of an interactive shell.
To run a command with arguments, enclose both in quotes.
+.It Fl f
+Flush the output after each write.
+.It Fl q
+Only print errors and warnings.
.El
.Pp
The script ends when the forked program exits (a control-D
diff --git usr.bin/script/script.c usr.bin/script/script.c
index 2e4173941..a58b618d5 100644
--- usr.bin/script/script.c
+++ usr.bin/script/script.c
@@ -85,7 +85,7 @@ volatile sig_atomic_t sigdeadstatus;
volatile sig_atomic_t flush;
struct termios tt;
-int istty;
+int istty, qflg;
__dead void done(int);
void dooutput(void);
@@ -104,11 +104,11 @@ main(int argc, char *argv[])
char ibuf[BUFSIZ];
char *cmd;
ssize_t cc, off;
- int aflg, ch;
+ int aflg, fflg, ch;
cmd = NULL;
- aflg = 0;
- while ((ch = getopt(argc, argv, "ac:")) != -1)
+ aflg = fflg = 0;
+ while ((ch = getopt(argc, argv, "ac:fq")) != -1)
switch(ch) {
case 'a':
aflg = 1;
@@ -116,8 +116,14 @@ main(int argc, char *argv[])
case 'c':
cmd = optarg;
break;
+ case 'f':
+ fflg = 1;
+ break;
+ case 'q':
+ qflg = 1;
+ break;
default:
- fprintf(stderr, "usage: %s [-a] [-c command] [file]\n",
+ fprintf(stderr, "usage: %s [-afq] [-c command] [file]\n",
__progname);
exit(1);
}
@@ -132,6 +138,9 @@ main(int argc, char *argv[])
if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL)
err(1, "%s", fname);
+ if (fflg)
+ setvbuf(fscript, NULL, _IONBF, 0);
+
if (isatty(0)) {
if (tcgetattr(STDIN_FILENO, &tt) == 0 &&
ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == 0)
@@ -140,7 +149,8 @@ main(int argc, char *argv[])
if (openpty(&master, &slave, NULL, &tt, &win) == -1)
err(1, "openpty");
- (void)printf("Script started, output file is %s\n", fname);
+ if (qflg)
+ (void)printf("Script started, output file is %s\n", fname);
if (istty) {
struct termios rtt = tt;
@@ -350,7 +360,8 @@ done(int eval)
} else {
if (istty)
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt);
- (void)printf("Script done, output file is %s\n", fname);
+ if (qflg)
+ (void)printf("Script done, output file is %s\n", fname);
}
exit(eval);
}