History log of /freebsd-current/usr.bin/script/script.c
Revision Date Author Comments
# 8ceac8e1 26-Apr-2024 Kyle Evans <kevans@FreeBSD.org>

script: handle terminal resize on SIGWINCH

Add a -w flag to forward terminal resize events on to the child, which
can be useful in some circumstances to avoid terminal corruption.

Reviewed by: des
Co-authored-by: Xavier Beaudouin <xavier.beaudouin@klarasystems.com>
Sponsored by: Modirum MDPay
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D44167


# 4459abe3 26-Apr-2024 Xavier Beaudouin <xavier.beaudouin@klarasystems.com>

script: minor style improvements

Fix some nits pointed out by checkstyle9.pl in advance of functional
changes to script(1).

Reviewed by: des
Sponsored by: Modirum MDPay
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D44167


# 0b8224d1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

Remove copyright strings ifdef'd out

We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by: Netflix


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# cccdaf50 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# 473e9fca 27-Oct-2022 Dag-Erling Smørgrav <des@FreeBSD.org>

script: Handle a missing 's' stamp gracefully.

Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37182


# 6ac087cf 27-Oct-2022 Dag-Erling Smørgrav <des@FreeBSD.org>

script: Further usage string nits.

Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37177


# 3276866f 27-Oct-2022 Dag-Erling Smørgrav <des@FreeBSD.org>

script: Use size_t / ssize_t where needed.

Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37177


# e7c13cf4 26-Oct-2022 Dag-Erling Smørgrav <des@FreeBSD.org>

script: Add usage string for playback mode.

Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D37138


# 8e096e24 26-Oct-2022 Dag-Erling Smørgrav <des@FreeBSD.org>

script: Correct -F in man page and usage string.

Sponsored by: Klara, Inc.
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D37138


# 31fde973 10-Mar-2022 Simon J. Gerraty <sjg@FreeBSD.org>

script: use %n at the end of default tstamp_fmt

Since we are only outputting time-stamps when they differ
ending it with a newline, interferes with the output less.


# 7b45ad3f 09-Mar-2022 Simon J. Gerraty <sjg@FreeBSD.org>

script -T skip timstamps for same second

The result is much more readable if we only output the time-stamp
when it is at least 1s since last one.


# 6c4afed5 09-Mar-2022 Simon J. Gerraty <sjg@FreeBSD.org>

script add -T fmt to print time-stamps

script -r is useful for recording time-stamps of when output
happened. With -T, rather than playback the script in real-time
we simply print the time-stamps to show when the output happened.

This is very useful for example, for analyzing boot time activity.

If the fmt provided contains no % characters the default
%n@ %s [%Y-%m-%d %T]
is used, which lends itself to analysis by tools as well as humans.

Sponsored by: Juniper Networks, Inc.

Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D34511


# c0ba4c2e 08-Jan-2022 Konstantin Belousov <kib@FreeBSD.org>

script(1): work around slow reading child

If child is slow reading from its input, or even completely stops doing
the read, script(1) hangs in write(2) to the pts master waiting until
there is a space in the terminal discipline buffer. This also stops
handling any outer io, as well as child output.

Work around the problem by making pts master fd non-blocking, and be
prepared for short writes to it. The data to be written to master is
buffered in the tailq which is processed when select(2) detects that
master is ready for write.

PR: 260938
Reported by: наб <nabijaczleweli@nabijaczleweli.xyz>
See also: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1003095
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D33789


# 84961358 04-Sep-2020 Warner Losh <imp@FreeBSD.org>

Fix typo in comment.

Noticed by: bapt@


# f9177b6c 01-Sep-2020 Warner Losh <imp@FreeBSD.org>

Have script accept and ignore -e for Linux compat

In the util-linux version of script, it will always exit with succes.
Except when run with -e, in which case it will have the exit value of
the child. BSD Script already uses the child's exit value for its exit
value. Some config and other helper scripts depend on being able to
specify -e. Accept it for compatibility since we'll already to the
right thing, but otherwise we ignore it.


# 8bc30d2a 11-Aug-2020 Mark Johnston <markj@FreeBSD.org>

script: Minor cleanups.

- Instead of using isatty() to decide whether to call tcgetattr(), just
call tcgetattr() directly, since that's all that isatty() does anyway.
- Simplify error handling in termset(). Check for errno != ENOTTY from
tcgetattr() to handle errors that may be raised while running
script(1) under a debugger.

PR: 248377
Submitted by: Soumendra Ganguly <soumendraganguly@gmail.com>
MFC after: 1 week


# 69bc4fa9 07-Aug-2020 Mark Johnston <markj@FreeBSD.org>

script: Put the terminal in raw mode when playing back a session.

Otherwise recorded sessions of some interactive programs do not play
back properly.

PR: 248377
Submitted by: Soumendra Ganguly <0.gangzta@gmail.com>
MFC after: 1 week


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 26e736b2 15-Apr-2016 Baptiste Daroussin <bapt@FreeBSD.org>

Directly set the O_CLOEXEC flags via the open(2) attributes

MFC after: 1 week


# 66d93438 08-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Record command exit status in the typescript file when running simple commands.

Also capitalize 'command:'.

Relnotes: yes
MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division


# 95d13d1b 08-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Just exit in the child if execve(2) fails.

No functional change.

This is mostly addressing a false-positive from the clang static
analyzer due to it thinking that done() was being called with freed
memory, however the kill(0, SIGTERM) made the done() never reached.
It doesn't make sense to the show the footer from the child anyhow, nor
does it make sense to kill the process group here since the execve(2)
failed in the child. This code was leftover from many years of refactoring.

MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division


# 7b245cb8 08-Mar-2016 Bryan Drewery <bdrewery@FreeBSD.org>

Filemon: Attach from the child to avoid racing with the parent attach.

This is the same as how the bmake filemon usage works.

This also fixes failed attach not properly flushing the TTY.

MFC after: 1 week
Relnotes: yes
Sponsored by: EMC / Isilon Storage Division


# 29f4384a 17-Jan-2014 Mikolaj Golub <trociny@FreeBSD.org>

Bring back r226403, the fix for bin/161526, which was (accidentally?)
reverted in r238896.

PR: bin/161526
Reported by: Karli.Sjoberg slu.se
MFC after: 3 days


# 8d105abc 04-Dec-2013 Tom Rhodes <trhodes@FreeBSD.org>

Add -F to flush output after each write. With this, I can
set up a pipe and allow a jr user to watch what I'm doing
by running 'script -F pipefile' on it.

While here, spell out the month in the .Dd tag like other
manual pages.


# 6cff4e07 26-Oct-2012 David E. O'Brien <obrien@FreeBSD.org>

Add "-f" to also output filemon(4) information.


# 13f02f28 23-Oct-2012 David E. O'Brien <obrien@FreeBSD.org>

Don't include both <sys/param.h> & <sys/types.h>.


# df53360c 30-Jul-2012 Brian Somers <brian@FreeBSD.org>

Add d, p and r switches for recording script sessions with timing data
and playing sessions back with or without time delays.

PR: 114465
Submitted by: ighighi at gmail dot com
MFC after: 3 weeks


# 8d105928 15-Oct-2011 Mikolaj Golub <trociny@FreeBSD.org>

In r225809 the intention was to send VEOF only once if STDIN was not a
terminal. Unfortunately the fix was incorrect and for flushtime > 0 it
keept sending VEOF.

Sent VEOF generates ^D\b\b echoed by the terminal, which was reported
in bin/161526. Note, we still send VEOF at least once. Otherwise
commands like below would hang forever:

echo 1 |script /tmp/script.out cat

PR: bin/161526
Reported by: Adrian Wontroba <aw1@stade.co.uk>, Stefan Bethke <stb@lassitu.de>
Tested by: Stefan Bethke <stb@lassitu.de>
MFC after: 3 days


# 29da7547 27-Sep-2011 Mikolaj Golub <trociny@FreeBSD.org>

When script(1) reads EOF from input it starts spinning on zero-byte
reads eating 100% CPU. Fix this by skipping select on STDIN after
reading EOF -- permanently if STDIN is not terminal and for one second
if it is.

Also after reading EOF from STDIN we have to pass it to the program
being scripted. The previous approach was to write zero bytes into the
pseudo-terminal. This does not work because zero-byte write does not
have any effect on read. Fix this by sending VEOF instead.

Submitted by: Ronald Klop <ronald-freebsd8@klop.yi.org>
Discussed with: kib, Chris Torek <chris.torek@gmail.com>
Approved by: kib
MFC after: 1 week


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 9b91846c 16-Sep-2010 David E. O'Brien <obrien@FreeBSD.org>

+ Add the SCRIPT environmental variable to the sub-shell. Its value is
the name of the typescript file.
+ Add the 'command' argument (if supplied on the command line) to the
typescript file. This creates a more complete typescript when invoked
this way - more equal to invoking script without supplying the 'command'
argument.


# e8efeec6 15-Aug-2010 Ed Schouten <ed@FreeBSD.org>

Mark functions and variables as static.

All these functions and variables are local to this compilation unit, so
there is no reason why we shouldn't mark them static. This slightly
reduces the binary size.


# 8f6794dd 13-May-2010 Ed Schouten <ed@FreeBSD.org>

MFC r207453:

Remove WNOHANG flag from wait3().

Because script(1) now reliably terminates when the TTY is closed, it may
be the case that the call to wait3() occurs just before the child
process exits. This causes error codes to be ignored.

Just change script(1) to use waitpid() instead of wait3(). This makes it
more portable and prevents the need for a loop, since waitpid() only
returns a specified process.

PR: bin/146189
Tested by: amdmi3@, older version


# e1e9ba33 30-Apr-2010 Ed Schouten <ed@FreeBSD.org>

Remove WNOHANG flag from wait3().

Because script(1) now reliably terminates when the TTY is closed, it may
be the case that the call to wait3() occurs just before the child
process exits. This causes error codes to be ignored.

Just change script(1) to use waitpid() instead of wait3(). This makes it
more portable and prevents the need for a loop, since waitpid() only
returns a specified process.

PR: bin/146189
Tested by: amdmi3@, older version
MFC after: 2 weeks


# 4ae65fe9 25-Mar-2010 Ed Schouten <ed@FreeBSD.org>

MFC r205008 and 205009:

Make script(1) a little less broken.

Close the file descriptor to the TTY. There is no reason why the parent
process should keep track of the descriptor. This ensures that the
application inside properly drains the TTY during exit(2).

Reported by: alfred


# e8b9127d 11-Mar-2010 Ed Schouten <ed@FreeBSD.org>

Improve the change made in the previous commit.

doshell() never returns, so there is no need to see whether we are the
parent process.


# 8d5e4a14 11-Mar-2010 Ed Schouten <ed@FreeBSD.org>

Make script(1) a little less broken.

Close the file descriptor to the TTY. There is no reason why the parent
process should keep track of the descriptor. This ensures that the
application inside properly drains the TTY during exit(2).

Reported by: alfred
MFC after: 2 weeks


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d93708c3 02-Jan-2010 Ed Schouten <ed@FreeBSD.org>

Remove a warning by adding extra parentheses.

GCC generates warnings when using "if (foo = bar)". In this case its use
is valid.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# d6a68195 15-Feb-2004 Colin Percival <cperciva@FreeBSD.org>

Attempt #2 to fix script(1) if the standard input is closed: If we
read EOF from STDIN_FILENO, write zero bytes into the pseudo-terminal;
this is interpreted as an EOF by the program being scripted.

I've tested this with two non-interactive scripts:
# echo 5 | script foo sh -c 'read x; sleep $x; echo bar'
# echo bar | xargs script foo echo
and one interactive program:
# script foo more /etc/passwd
and everything seems to work properly...

PR: bin/56166, bin/57414, ports/57415, ports/60534
Approved by: rwatson (mentor)
MFC after: 2 weeks


# 0a43b788 27-Jan-2004 Colin Percival <cperciva@FreeBSD.org>

Back out part of 1.21, since it breaks `script interactive-program`. This
re-breaks non-interactive portupgrade (or at least old versions of
portupgrade); I'll see if I can put together a solution which avoids
breaking anything later.

Approved by: rwatson (mentor)
Noticed by: Stefan Farfeleder, Joshua Goodall


# 4294ff16 22-Jan-2004 Sheldon Hearn <sheldonh@FreeBSD.org>

Fix SYNOPSIS of manual page, clustering no-arg options correctly.

Sync usage with manpage.


# e292a0e3 22-Jan-2004 Colin Percival <cperciva@FreeBSD.org>

Two fixes for script(1):
1. Don't do tty stuff to stdin if stdin isn't a tty.
2. When running in non-interactive mode, don't select(2)
on the standard input.

This un-breaks non-interactive portupgrade.

PR: bin/59036 [1]
PR: bin/56166, bin/57414, ports/57415, ports/60534 [2]
MFC after: 7 days
Approved by: rwatson (mentor)


# f4ac32de 04-Sep-2002 David Malone <dwmalone@FreeBSD.org>

ANSIify function definitions.
Add some constness to avoid some warnings.
Remove use register keyword.
Deal with missing/unneeded extern/prototypes.
Some minor type changes/casts to avoid warnings.

Reviewed by: md5


# cb263c35 03-Jun-2002 Mike Barcroft <mike@FreeBSD.org>

Use POSIX macros for wait(2)-style status information instead of the
deprecated 4.2/4.3BSD wait union. Fix some nearby pid_t/int
confusion.


# 3f330d7d 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# d20f95e1 12-Dec-2001 Mark Murray <markm@FreeBSD.org>

Minor style stuff, use __FBSDID(), remove to-be-default WARNS=2.


# b139689c 03-Dec-2001 David Malone <dwmalone@FreeBSD.org>

Warns cleanups. Add FreeBSD ID.


# e1b4d8d0 26-Jul-2001 Sheldon Hearn <sheldonh@FreeBSD.org>

Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. The
definitions are more readable, and it's possible that they're
more portable to pathalogical platforms.

Submitted by: David Hill <david@phobia.ms>


# 7bc6d015 09-Jul-2001 Brian Somers <brian@FreeBSD.org>

Fix the type of the NULL arg to execl()

Idea from: Theo de Raadt <deraadt@openbsd.org>


# 7309915e 24-Jun-2001 Dima Dorfman <dd@FreeBSD.org>

Nuke unused variables.


# b7ffba17 10-Jul-2000 Kris Kennaway <kris@FreeBSD.org>

Don't call warn() with no format string.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 5cba8cca 11-Aug-1999 Sheldon Hearn <sheldonh@FreeBSD.org>

Pass as argv[0] the name of the shell executed instead of "sh".

PR: 2851
Reported by: era@iki.fi
Obtained from: NetBSD


# b1c66970 19-Sep-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Fix the following bugs:

- if a command was specified and script(1) failed to execute it,
it would print the name of your shell in the error message
instead of that of the command that failed.

- since finish() was installed as a SIGCHLD handler, it would
often run before the main loop had had time to process the
last few bytes of output. This resulted in very strange
truncated error messages.

- script(1) would almost always return with an exit status of 0,
even if the command returned a non-zero exit status. This broke
my 'build world, install it and rebuild the kernel' scripts
because 'make installworld' would run even if 'make buildworld'
had failed.


# e8eb82a8 08-Mar-1998 Peter Wemm <peter@FreeBSD.org>

Rewrite script as a select loop rather than as a twin reader/write process.
This allows simple logging of keys sent to a session (turned on with -k).
Also allow specifying the script file flush interval.


# 0e604e98 29-Dec-1997 Peter Wemm <peter@FreeBSD.org>

Fix typo while copying patch from the 2.2 system that it came from
Use execvp rather than execv so that full paths are not needed.


# 51afb8df 29-Dec-1997 Peter Wemm <peter@FreeBSD.org>

script(1) has annoyed me with it's inflexable command argument parsing
since I first saw it. I finally needed to pass arguments through to
the spawned command badly enough (and urgently) that I threw this together.


# 236d2f55 07-Aug-1997 Philippe Charnier <charnier@FreeBSD.org>

Add usage(). Use err(3) instead of local redefinition.


# 1c8af878 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# eaa86f9d 13-Sep-1996 Bruce Evans <bde@FreeBSD.org>

Don't use __dead or __pure in user code. They were obfuscations
for gcc >= 2.5 and no-ops for gcc >= 2.6. Converted to use __dead2
or __pure2 where it wasn't already done, except in math.h where use
of __pure was mostly wrong.


# 656dcd43 07-Aug-1995 Garrett Wollman <wollman@FreeBSD.org>

Delete bogus referneces to timezone code internal header file `tzfile.h',
which is no longer bogusly installed in /usr/include.


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources