Add "-f" to also output filemon(4) information.
This commit is contained in:
parent
f3ec0567c4
commit
5f08f2efa8
@ -28,7 +28,7 @@
|
|||||||
.\" @(#)script.1 8.1 (Berkeley) 6/6/93
|
.\" @(#)script.1 8.1 (Berkeley) 6/6/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd July 30, 2012
|
.Dd Oct 27, 2012
|
||||||
.Dt SCRIPT 1
|
.Dt SCRIPT 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -36,7 +36,7 @@
|
|||||||
.Nd make typescript of terminal session
|
.Nd make typescript of terminal session
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl adkpqr
|
.Op Fl adfkpqr
|
||||||
.Op Fl t Ar time
|
.Op Fl t Ar time
|
||||||
.Op Ar file Op Ar command ...
|
.Op Ar file Op Ar command ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
@ -76,6 +76,13 @@ retaining the prior contents.
|
|||||||
When playing back a session with the
|
When playing back a session with the
|
||||||
.Fl p
|
.Fl p
|
||||||
flag, do not sleep between records when playing back a timestamped session.
|
flag, do not sleep between records when playing back a timestamped session.
|
||||||
|
.It Fl f
|
||||||
|
Create
|
||||||
|
.Ar file.filemon
|
||||||
|
or
|
||||||
|
.Pa typescript.filemon
|
||||||
|
using
|
||||||
|
.Xr filemon 4 .
|
||||||
.It Fl k
|
.It Fl k
|
||||||
Log keys sent to the program as well as output.
|
Log keys sent to the program as well as output.
|
||||||
.It Fl p
|
.It Fl p
|
||||||
@ -151,6 +158,7 @@ is assumed.
|
|||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr csh 1
|
.Xr csh 1
|
||||||
|
.Xr filemon 4
|
||||||
.Po
|
.Po
|
||||||
for the
|
for the
|
||||||
.Em history
|
.Em history
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2010, 2012 David E. O'Brien
|
||||||
* Copyright (c) 1980, 1992, 1993
|
* Copyright (c) 1980, 1992, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -44,6 +45,7 @@ static const char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93";
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <sys/endian.h>
|
#include <sys/endian.h>
|
||||||
|
#include <dev/filemon/filemon.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -70,7 +72,8 @@ static FILE *fscript;
|
|||||||
static int master, slave;
|
static int master, slave;
|
||||||
static int child;
|
static int child;
|
||||||
static const char *fname;
|
static const char *fname;
|
||||||
static int qflg, ttyflg;
|
static char *fmfname;
|
||||||
|
static int fflg, qflg, ttyflg;
|
||||||
static int usesleep, rawout;
|
static int usesleep, rawout;
|
||||||
|
|
||||||
static struct termios tt;
|
static struct termios tt;
|
||||||
@ -90,21 +93,23 @@ main(int argc, char *argv[])
|
|||||||
int cc;
|
int cc;
|
||||||
struct termios rtt, stt;
|
struct termios rtt, stt;
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
int aflg, kflg, pflg, ch, n;
|
|
||||||
struct timeval tv, *tvp;
|
struct timeval tv, *tvp;
|
||||||
time_t tvec, start;
|
time_t tvec, start;
|
||||||
char obuf[BUFSIZ];
|
char obuf[BUFSIZ];
|
||||||
char ibuf[BUFSIZ];
|
char ibuf[BUFSIZ];
|
||||||
fd_set rfd;
|
fd_set rfd;
|
||||||
int flushtime = 30;
|
int aflg, kflg, pflg, ch, k, n;
|
||||||
int readstdin;
|
int flushtime, readstdin;
|
||||||
int k;
|
int fm_fd, fm_log;
|
||||||
|
|
||||||
aflg = kflg = pflg = 0;
|
aflg = kflg = pflg = 0;
|
||||||
usesleep = 1;
|
usesleep = 1;
|
||||||
rawout = 0;
|
rawout = 0;
|
||||||
|
flushtime = 30;
|
||||||
|
fm_fd = -1; /* Shut up stupid "may be used uninitialized" GCC
|
||||||
|
warning. (not needed w/clang) */
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "adkpqrt:")) != -1)
|
while ((ch = getopt(argc, argv, "adfkpqrt:")) != -1)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
aflg = 1;
|
aflg = 1;
|
||||||
@ -112,6 +117,9 @@ main(int argc, char *argv[])
|
|||||||
case 'd':
|
case 'd':
|
||||||
usesleep = 0;
|
usesleep = 0;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
fflg = 1;
|
||||||
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
kflg = 1;
|
kflg = 1;
|
||||||
break;
|
break;
|
||||||
@ -146,6 +154,23 @@ main(int argc, char *argv[])
|
|||||||
if ((fscript = fopen(fname, pflg ? "r" : aflg ? "a" : "w")) == NULL)
|
if ((fscript = fopen(fname, pflg ? "r" : aflg ? "a" : "w")) == NULL)
|
||||||
err(1, "%s", fname);
|
err(1, "%s", fname);
|
||||||
|
|
||||||
|
if (fflg) {
|
||||||
|
asprintf(&fmfname, "%s.filemon", fname);
|
||||||
|
if (!fmfname)
|
||||||
|
err(1, "%s.filemon", fname);
|
||||||
|
if ((fm_fd = open("/dev/filemon", O_RDWR)) == -1)
|
||||||
|
err(1, "open(\"/dev/filemon\", O_RDWR)");
|
||||||
|
if ((fm_log = open(fmfname, O_WRONLY | O_CREAT | O_TRUNC,
|
||||||
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
|
||||||
|
err(1, "open(%s)", fmfname);
|
||||||
|
if (ioctl(fm_fd, FILEMON_SET_FD, &fm_log) < 0)
|
||||||
|
err(1, "Cannot set filemon log file descriptor");
|
||||||
|
|
||||||
|
/* Set up these two fd's to close on exec. */
|
||||||
|
(void)fcntl(fm_fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
(void)fcntl(fm_log, F_SETFD, FD_CLOEXEC);
|
||||||
|
}
|
||||||
|
|
||||||
if (pflg)
|
if (pflg)
|
||||||
playback(fscript);
|
playback(fscript);
|
||||||
|
|
||||||
@ -169,7 +194,7 @@ main(int argc, char *argv[])
|
|||||||
(void)printf("Script started, output file is %s\n", fname);
|
(void)printf("Script started, output file is %s\n", fname);
|
||||||
if (!rawout) {
|
if (!rawout) {
|
||||||
(void)fprintf(fscript, "Script started on %s",
|
(void)fprintf(fscript, "Script started on %s",
|
||||||
ctime(&tvec));
|
ctime(&tvec));
|
||||||
if (argv[0]) {
|
if (argv[0]) {
|
||||||
fprintf(fscript, "command: ");
|
fprintf(fscript, "command: ");
|
||||||
for (k = 0 ; argv[k] ; ++k)
|
for (k = 0 ; argv[k] ; ++k)
|
||||||
@ -179,6 +204,10 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fflush(fscript);
|
fflush(fscript);
|
||||||
|
if (fflg) {
|
||||||
|
(void)printf("Filemon started, output file is %s\n",
|
||||||
|
fmfname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ttyflg) {
|
if (ttyflg) {
|
||||||
rtt = tt;
|
rtt = tt;
|
||||||
@ -196,6 +225,9 @@ main(int argc, char *argv[])
|
|||||||
doshell(argv);
|
doshell(argv);
|
||||||
close(slave);
|
close(slave);
|
||||||
|
|
||||||
|
if (fflg && ioctl(fm_fd, FILEMON_SET_PID, &child) < 0)
|
||||||
|
err(1, "Cannot set filemon PID");
|
||||||
|
|
||||||
start = tvec = time(0);
|
start = tvec = time(0);
|
||||||
readstdin = 1;
|
readstdin = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -260,7 +292,7 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage: script [-adkpqr] [-t time] [file [command ...]]\n");
|
"usage: script [-adfkpqr] [-t time] [file [command ...]]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +323,7 @@ doshell(char **av)
|
|||||||
|
|
||||||
(void)close(master);
|
(void)close(master);
|
||||||
(void)fclose(fscript);
|
(void)fclose(fscript);
|
||||||
|
free(fmfname);
|
||||||
login_tty(slave);
|
login_tty(slave);
|
||||||
setenv("SCRIPT", fname, 1);
|
setenv("SCRIPT", fname, 1);
|
||||||
if (av[0]) {
|
if (av[0]) {
|
||||||
@ -323,8 +356,12 @@ done(int eno)
|
|||||||
if (!qflg) {
|
if (!qflg) {
|
||||||
if (!rawout)
|
if (!rawout)
|
||||||
(void)fprintf(fscript,"\nScript done on %s",
|
(void)fprintf(fscript,"\nScript done on %s",
|
||||||
ctime(&tvec));
|
ctime(&tvec));
|
||||||
(void)printf("\nScript done, output file is %s\n", fname);
|
(void)printf("\nScript done, output file is %s\n", fname);
|
||||||
|
if (fflg) {
|
||||||
|
(void)printf("Filemon done, output file is %s\n",
|
||||||
|
fmfname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(void)fclose(fscript);
|
(void)fclose(fscript);
|
||||||
(void)close(master);
|
(void)close(master);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user