Skip to content
Tcl Source Code View Ticket
Login

View Ticket

close $pipe doesn't return non-zero exit status

Closed / Invalid219327ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 21 years ago
Descriptionplain2000-10-26 05:10:48
OriginalBugID: 4044 Bug
Version: 8.2.3
SubmitDate: '2000-01-19'
LastModified: '2000-02-05'
Severity: SER
Status: UnAssn
Submitter: techsupp
ChangedBy: hobbs
OS: Solaris
OSVersion: SunOS 5.5.1
Machine: Sun Ultra 5
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
Mikhail Terekhov

Comments:
Both tcl8.2.3 and tcl8.3b2 have the same bug.

ReproducibleScript:
Save the following script as ~/test.tcl

proc Pipe_Reader1 {  fd  } {

    if [ eof $fd ] {
if [ catch { close $fd } message ] {
    puts "ERROR detected inside fileevent: $message"
} else {
    puts "OK inside fileevent"
}
global wt
set wt 1
    } else {
puts [ read $fd ]\n
    }
}

proc Pipe_Reader2 {  fd  } {

    if [ eof $fd ] {
global wt
set wt 1
    } else {
puts [ read $fd ]\n
    }
}

#======================================================================

global wt

set cmd "| cat /xyz"

set rc [ catch { open $cmd r  } fd ]
fconfigure $fd -blocking 0 -buffering line
fileevent $fd readable [ list Pipe_Reader1 $fd ]
vwait wt

set rc [ catch { open $cmd r  } fd ]
fconfigure $fd -blocking 0 -buffering line
fileevent $fd readable [ list Pipe_Reader2 $fd ]
vwait wt

if [ catch { close $fd } message ] {
    puts "ERROR detected outside fileevent: $message"
} else {
    puts "OK inside fileevent"
}

ObservedBehavior:
home:> /usr/Local/tcltk.8.3b2/bin/tclsh8.3 ~/test.tcl


OK inside fileevent


OK inside fileevent

home:> /usr/Local/tcltk.8.2.3/bin/tclsh8.2 ~/test.tcl


OK inside fileevent


OK inside fileevent

DesiredBehavior:
The same script produces valid results when tcl8.2.1 is used:

home:> /usr/Local/tcltk.8.2.1/bin/tclsh8.2  ~/syren/test1.tcl


ERROR detected inside fileevent: cat: cannot open /xyz


ERROR detected outside fileevent: cat: cannot open /xyz
dgp Ticket [219327ffff]: 1 change [History diff]2001-04-05 08:20:11
hobbs Ticket [219327ffff]: 1 change [History diff]2001-10-17 05:43:37
dgpplain2006-03-10 23:32:04
Logged In: YES 
user_id=80530

status?
andreas_kupriesplain2006-03-16 01:10:26
Logged In: YES 
user_id=75003

The behaviour is unchanged for HEAD and 8.4 branch head.
andreas_kupriesplain2006-03-17 03:18:01
Logged In: YES 
user_id=75003

I believe that the are actually seeing a bug in Tcl 8.2.1.
In Nov 29, 1999 Jeff Hobbs fixed a problem in tclUnixPipe,
apparently the blocking mode of the channel was not properly
set before.

So, a channel with -blocking 0 does not report errors. See
tclUnixPipe.c, PipeCloseProc. This code is present in Tcl
8.2.1 as well, in unchanged form. 8.2.1 reported the error
despite this because of the bad information it had about the
blocking mode of the pipe.

To get the error from the pipe run
    fconfigure -blocking 1 $fd
    close $fd
instead of just a 'close $fd'.

I have to admit that the manpage of close is written poorly
when it comes to explaining the handling of -blocking. The
behaviour is descried in the the manpage of open, in the
section about command pipelines.

I recommend to try and fix the documentation. The core is
ok, and the example script simply falls into a trap for the
unwary.

I will not mind if this bug is simply closed. As described
by the submitter it is 'Invalid'.
andreas_kupries Pending ticket [219327ffff]. [History diff]2006-03-17 03:28:56
sf-robotplain2006-03-31 10:20:55
Logged In: YES 
user_id=1312539

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
Log in (anonymous is fine) to add a comment.