summaryrefslogtreecommitdiffstats
path: root/term-utils
diff options
context:
space:
mode:
authorSami Kerola2011-04-09 21:40:45 +0200
committerKarel Zak2011-04-12 14:21:36 +0200
commit7ca59ef25f8ebed37ddcf51155954077e2654d1c (patch)
tree7cbc53a8dd2c64b85a2f63191a1ca1a4619877a2 /term-utils
parentdocs: scriptreplay add note about new options (diff)
downloadkernel-qcow2-util-linux-7ca59ef25f8ebed37ddcf51155954077e2654d1c.tar.gz
kernel-qcow2-util-linux-7ca59ef25f8ebed37ddcf51155954077e2654d1c.tar.xz
kernel-qcow2-util-linux-7ca59ef25f8ebed37ddcf51155954077e2654d1c.zip
script: optional timing output file argument added
And update to manual page accordingly. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'term-utils')
-rw-r--r--term-utils/script.18
-rw-r--r--term-utils/script.c19
2 files changed, 18 insertions, 9 deletions
diff --git a/term-utils/script.1 b/term-utils/script.1
index f411dc6e7..725bdb290 100644
--- a/term-utils/script.1
+++ b/term-utils/script.1
@@ -44,7 +44,7 @@
.Op Fl e
.Op Fl f
.Op Fl q
-.Op Fl t
+.Op Fl t[=FILE]
.Op Fl V
.Op Fl h
.Op Ar file
@@ -86,12 +86,16 @@ One person does `mkfifo foo; script -f foo' and another can
supervise real-time what is being done using `cat foo'.
.It Fl q, Fl Fl quiet
Be quiet.
-.It Fl t, Fl Fl timing
+.It Fl t, Fl Fl timing[=FILE]
Output timing data to standard error. This data contains two fields,
separated by a space. The first field indicates how much time elapsed since
the previous output. The second field indicates how many characters were
output this time. This information can be used to replay typescripts with
realistic typing and output delays.
+
+The timing option is able to take file path as an argument. The
+file is used as output detination instead of standard error when
+it is supplied.
.It Fl V, Fl Fl version
Output version information and exit.
.It Fl h, Fl Fl help
diff --git a/term-utils/script.c b/term-utils/script.c
index d57d44186..603d392d3 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -76,7 +76,7 @@ void fixtty(void);
void getmaster(void);
void getslave(void);
void doinput(void);
-void dooutput(void);
+void dooutput(FILE *timingfd);
void doshell(void);
char *shell;
@@ -133,7 +133,7 @@ usage(FILE *out)
" -r, --return return exit code of the child process\n"
" -f, --flush run flush after each write\n"
" -q, --quiet be quiet\n"
- " -t, --timing output timing data to stderr\n"
+ " -t, --timing=FILE output timing data to stderr, or to file\n"
" -V, --version output version information and exit\n"
" -h, --help display this help and exit\n\n"));
@@ -155,6 +155,7 @@ main(int argc, char **argv) {
struct sigaction sa;
extern int optind;
int ch;
+ FILE *timingfd = stderr;
static const struct option longopts[] = {
{ "append", no_argument, 0, 'a' },
@@ -162,7 +163,7 @@ main(int argc, char **argv) {
{ "return", no_argument, 0, 'e' },
{ "flush", no_argument, 0, 'f' },
{ "quiet", no_argument, 0, 'q' },
- { "timing", no_argument, 0, 't' },
+ { "timing", optional_argument, 0, 't' },
{ "version", no_argument, 0, 'V' },
{ "help", no_argument, 0, 'h' },
{ NULL, 0, 0, 0 }
@@ -173,7 +174,7 @@ main(int argc, char **argv) {
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((ch = getopt_long(argc, argv, "ac:efqtVh", longopts, NULL)) != -1)
+ while ((ch = getopt_long(argc, argv, "ac:efqt::Vh", longopts, NULL)) != -1)
switch((char)ch) {
case 'a':
aflg++;
@@ -191,6 +192,9 @@ main(int argc, char **argv) {
qflg++;
break;
case 't':
+ if (optarg)
+ if ((timingfd = fopen(optarg, "w")) == NULL)
+ err(EXIT_FAILURE, _("cannot open timing file %s"), optarg);
tflg++;
break;
case 'V':
@@ -260,7 +264,7 @@ main(int argc, char **argv) {
fail();
}
if (child)
- dooutput();
+ dooutput(timingfd);
else
doshell();
} else {
@@ -269,6 +273,7 @@ main(int argc, char **argv) {
}
doinput();
+ fclose(timingfd);
return EXIT_SUCCESS;
}
@@ -328,7 +333,7 @@ my_strftime(char *buf, size_t len, const char *fmt, const struct tm *tm) {
}
void
-dooutput() {
+dooutput(FILE *timingfd) {
register ssize_t cc;
time_t tvec;
char obuf[BUFSIZ];
@@ -370,7 +375,7 @@ dooutput() {
break;
if (tflg) {
newtime = tv.tv_sec + (double) tv.tv_usec / 1000000;
- fprintf(stderr, "%f %zd\n", newtime - oldtime, cc);
+ fprintf(timingfd, "%f %zd\n", newtime - oldtime, cc);
oldtime = newtime;
}
wrt = write(1, obuf, cc);