Menu

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

obsolete: 8.4.12
closed-invalid
2
2006-03-31
2000-10-26
Anonymous
No

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

Discussion

  • Don Porter

    Don Porter - 2001-04-05
    • labels: 104241 --> 27. Channel Types
     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2001-10-16
    • assigned_to: nobody --> andreas_kupries
     
  • Don Porter

    Don Porter - 2006-03-10

    Logged In: YES
    user_id=80530

    status?

     
  • Andreas Kupries

    Andreas Kupries - 2006-03-15
    • milestone: 102432 --> obsolete: 8.4.12
     
  • Andreas Kupries

    Andreas Kupries - 2006-03-15

    Logged In: YES
    user_id=75003

    The behaviour is unchanged for HEAD and 8.4 branch head.

     
  • Andreas Kupries

    Andreas Kupries - 2006-03-16
    • priority: 5 --> 2
    • status: open --> open-invalid
     
  • Andreas Kupries

    Andreas Kupries - 2006-03-16

    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

    Andreas Kupries - 2006-03-16
    • status: open-invalid --> pending-invalid
     
  • SourceForge Robot

    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).

     
  • SourceForge Robot

    • status: pending-invalid --> closed-invalid