ttyrex

ttyrec with more options
git clone https://a3nm.net/git/ttyrex/
Log | Files | Refs | README

commit b1d49c1a66d383fe03893e155c24068c8434241d
parent 6c3c9a304c570c4c3852dfb6db37e13573bdbcd7
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Wed,  3 Oct 2012 00:25:31 +0200

Merge branch 'mine'

Conflicts:
	ttyrec.1

Diffstat:
ttyrec | 0
ttyrec.1 | 10+++++++---
ttyrec.c | 50++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/ttyrec b/ttyrec Binary files differ. diff --git a/ttyrec.1 b/ttyrec.1 @@ -7,7 +7,7 @@ ttyrec \- a tty recorder .SH SYNOPSIS .br .B ttyrec -.I "[\-a] [\-u] [\-e command] [file]" +.I "[\-a] [\-f] [\-u] [\-e command] [\-l limit] [file]" .br .SH DESCRIPTION .B Ttyrec @@ -36,6 +36,9 @@ or .IR ttyrecord , rather than overwriting it. .TP +.B \-f +Instead of failing, try hard to just run a shell without recording. +.TP .B \-u With this option, .B ttyrec @@ -54,8 +57,9 @@ on it for the file you want to transfer. Invoke .I command when ttyrec starts. - - +.TP +.BI \-l " limit" +Only log the first limit bytes of each second. .SH ENVIRONMENT .TP .I SHELL diff --git a/ttyrec.c b/ttyrec.c @@ -39,6 +39,10 @@ * - modify `script' to create `ttyrec'. */ +/* 2012-10-03 Antoine Amarilli <a3nm@a3nm.net> + * - add -f and -l + */ + /* * script */ @@ -85,6 +89,7 @@ #endif /* SVR4 && ! CDEL */ void done(void); +void dofail(void); void fail(void); void fixtty(void); void getmaster(void); @@ -112,6 +117,9 @@ char line[] = "/dev/ptyXX"; #endif /* !SVR4 */ int aflg; int uflg; +int force; +int limit; +char *command = NULL; static void resize(int dummy) { @@ -130,7 +138,6 @@ main(argc, argv) int ch; void finish(); char *getenv(); - char *command = NULL; while ((ch = getopt(argc, argv, "aue:h?")) != EOF) switch((char)ch) { @@ -143,10 +150,16 @@ main(argc, argv) case 'e': command = strdup(optarg); break; + case 'l': + limit = atoi(optarg); + break; + case 'f': + force = 1; + break; case 'h': case '?': default: - fprintf(stderr, _("usage: ttyrec [-u] [-e command] [-a] [file]\n")); + fprintf(stderr, _("usage: ttyrec [-u] [-e command] [-a] [-f] [-l limit] [file]\n")); exit(1); } argc -= optind; @@ -157,7 +170,7 @@ main(argc, argv) else fname = "ttyrecord"; if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) { - perror(fname); + if (!force) perror(fname); fail(); } setbuf(fscript, NULL); @@ -175,13 +188,13 @@ main(argc, argv) sigaction(SIGCHLD, &sa, NULL); child = fork(); if (child < 0) { - perror("fork"); + if (!force) perror("fork"); fail(); } if (child == 0) { subchild = child = fork(); if (child < 0) { - perror("fork"); + if (!force) perror("fork"); fail(); } if (child) { @@ -310,6 +323,8 @@ dooutput() { int cc; char obuf[BUFSIZ]; + time_t lastsec; + int readsec; setbuf(stdout, NULL); (void) close(0); @@ -326,6 +341,19 @@ dooutput() uu_check_output(obuf, cc); h.len = cc; gettimeofday(&h.tv, NULL); + if (limit) { + if (h.tv.tv_sec == lastsec) { + if (readsec >= limit) + continue; + readsec += cc; + if (readsec > limit) { + cc -= readsec - limit; + } + } else { + lastsec = h.tv.tv_sec; + readsec = cc; + } + } (void) write(1, obuf, cc); if ((cc = check_output(obuf, cc))) { (void) write_header(fscript, &h); @@ -361,7 +389,7 @@ doshell(const char* command) execl(shell, strrchr(shell, '/') + 1, "-c", command, NULL); } perror(shell); - fail(); + dofail(); } void @@ -391,14 +419,20 @@ fixtty() } void -fail() +dofail() { - (void) kill(0, SIGTERM); done(); } void +fail() +{ + if (force) doshell(command); + dofail(); +} + +void done() { if (subchild) {