Bug 57414

Summary: /usr/bin/script fails silently if stdin is not a terminal
Product: Base System Reporter: Jonathan Lennox <lennox>
Component: binAssignee: Colin Percival <cperciva>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.1-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Jonathan Lennox 2003-09-30 19:20:17 UTC
The /usr/bin/script utility fails silently if its standard input is not a
terminal.  It does nothing, and does not execute its argument, but exits
with a successful output status.

This is not such a big deal if the user is using 'script' directly -- it's
pretty easy to figure out what happened.  However, this can be *extremely*
surprising -- and dangerous -- if 'script' is called by some other program
which doesn't document this limitation.

In particular, the 'portupgrade' utility wraps its calls to 'make' and 'make
install' of upgraded ports in 'script'.  As a result, if portupgrade is run
with its standard input redirected, out-of-date ports will be deleted and
then not reinstalled, with no warning or indication of any problem.

Fix: The following patch causes /usr/bin/script to error quickly with a non-zero
exit status if tcgetattr or ioctl fail, as they will if stdin is not a tty.
How-To-Repeat: $ script /var/tmp/foo cat /etc/passwd < /dev/null
outputs only
Script started, output file is /var/tmp/foo

Script done, output file is /var/tmp/foo
and /var/tmp/foo is empty.

# BATCH=yes portupgrade -arRv < /dev/null > /var/tmp/portupgrade.log 2>&1 &
(which seems like a perfectly reasonable way of upgrading all one's ports,
without having to stay logged in to watch it happen)
deletes all out-of-date ports from your system, without replacing them with
up-to-date versions.
Comment 1 colin.percival 2003-10-10 20:09:49 UTC
   This is the same bug as PR bin/56166 -- the issue is not one of whether 
stdin is a terminal, but rather relates to the behaviour of select(2) -- 
/usr/bin/script exits if stdin is closed even if it is operating in 
execute-a-script mode instead of log-this-shell mode.

Colin Percival
Comment 2 Colin Percival freebsd_committer freebsd_triage 2004-01-22 21:08:22 UTC
State Changed
From-To: open->patched

Fixed in -current, will MFC in 7 days. 
Claim ownership to remind myself to close this later. 



Comment 3 Colin Percival freebsd_committer freebsd_triage 2004-01-22 21:08:22 UTC
Responsible Changed
From-To: freebsd-bugs->cperciva

Fixed in -current, will MFC in 7 days. 
Claim ownership to remind myself to close this later.
Comment 4 Colin Percival freebsd_committer freebsd_triage 2004-03-13 09:25:05 UTC
State Changed
From-To: patched->closed

MFC to RELENG_4 is done.