Page MenuHomeFreeBSD

D34511.id103689.diff
No OneTemporary

D34511.id103689.diff

Index: usr.bin/script/script.1
===================================================================
--- usr.bin/script/script.1
+++ usr.bin/script/script.1
@@ -28,7 +28,7 @@
.\" @(#)script.1 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd January 5, 2021
+.Dd March 9, 2022
.Dt SCRIPT 1
.Os
.Sh NAME
@@ -38,6 +38,7 @@
.Nm
.Op Fl aefkqr
.Op Fl F Ar pipe
+.Op Fl T Ar fmt
.Op Fl t Ar time
.Op Ar file Op Ar command ...
.Nm
@@ -119,6 +120,19 @@
to flush after every character I/O event.
The default interval is
30 seconds.
+.It Fl T Ar fmt
+Implies
+.Fl p ,
+but just reports the time-stamp of each output.
+This is very useful for assessing the timing of events.
+.Pp
+If
+.Ar fmt
+does not contain any
+.Ql %
+characters, it indicates the default format:
+.Ql %n@ %s [%Y-%m-%d %T]\ ,
+which is useful for both tools and humans to read, should be used.
.El
.Pp
The script ends when the forked shell (or command) exits (a
Index: usr.bin/script/script.c
===================================================================
--- usr.bin/script/script.c
+++ usr.bin/script/script.c
@@ -89,6 +89,13 @@
static struct termios tt;
+#ifndef TSTAMP_FMT
+/* useful for tool and human reading */
+# define TSTAMP_FMT "%n@ %s [%Y-%m-%d %T] "
+#endif
+static const char *tstamp_fmt = TSTAMP_FMT;
+static int tflg;
+
static void done(int) __dead2;
static void doshell(char **);
static void finish(void);
@@ -121,7 +128,7 @@
warning. (not needed w/clang) */
showexit = 0;
- while ((ch = getopt(argc, argv, "adeFfkpqrt:")) != -1)
+ while ((ch = getopt(argc, argv, "adeFfkpqrT:t:")) != -1)
switch(ch) {
case 'a':
aflg = 1;
@@ -154,6 +161,11 @@
if (flushtime < 0)
err(1, "invalid flush time %d", flushtime);
break;
+ case 'T':
+ tflg = pflg = 1;
+ if (strchr(optarg, '%'))
+ tstamp_fmt = optarg;
+ break;
case '?':
default:
usage();
@@ -559,15 +571,23 @@
(void)consume(fp, stamp.scr_len, buf, reg);
break;
case 'o':
- tsi.tv_sec = tso.tv_sec - tsi.tv_sec;
- tsi.tv_nsec = tso.tv_nsec - tsi.tv_nsec;
- if (tsi.tv_nsec < 0) {
- tsi.tv_sec -= 1;
- tsi.tv_nsec += 1000000000;
+ if (tflg) {
+ if (stamp.scr_len == 0)
+ continue;
+ l = strftime(buf, sizeof buf, tstamp_fmt,
+ localtime(&tclock));
+ (void)write(STDOUT_FILENO, buf, l);
+ } else {
+ tsi.tv_sec = tso.tv_sec - tsi.tv_sec;
+ tsi.tv_nsec = tso.tv_nsec - tsi.tv_nsec;
+ if (tsi.tv_nsec < 0) {
+ tsi.tv_sec -= 1;
+ tsi.tv_nsec += 1000000000;
+ }
+ if (usesleep)
+ (void)nanosleep(&tsi, NULL);
+ tsi = tso;
}
- if (usesleep)
- (void)nanosleep(&tsi, NULL);
- tsi = tso;
while (stamp.scr_len > 0) {
l = MIN(DEF_BUF, stamp.scr_len);
if (fread(buf, sizeof(char), l, fp) != l)

File Metadata

Mime Type
text/plain
Expires
Mon, Aug 31, 9:33 AM (7 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37673862
Default Alt Text
D34511.id103689.diff (2 KB)

Event Timeline