Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 7cd1c0ebe7deb11191e1143043cfa5cef8f86bbe
Ticket: 419685ffffffffffffffffffffffffffffffffff
Problem with [file channels] if std channels not available
User & Date: mmg_kraus on 2001-04-28 02:12:28
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    This occurs whenever Tcl could not initialize the 
    standard channels (e.g. when it's running as a Windows 
    NT service). Without any other open channels, [file 
    channels] returns an empty list, which is correct. As 
    soon as the first channel (e.g. a socket) is opened, 
    it is registered as stdin, the next one as stdout, the 
    third one as stderr. [file channels] returns {stdin 
    stdout stderr}. Any additional open channel is 
    returned with its Tcl name, e.g. sock123.
    
    The problem is that I don't know how to prevent the 
    first three sockets to be registered as the standard 
    channels, and that [file channels sock*] does not 
    return the list of all open sockets. (As a workaround, 
    I create three dummy channels that do nothing.)
    
    The man page for TclGetStdChannel sort of talks about 
    that behavior, but only if "one of the standard 
    channels is set to NULL, either by calling 
    Tcl_SetStdChannel with a null channel argument, or by 
    calling Tcl_Close on the channel". Since I'm doing 
    pure Tcl here, it's hard to figure out what happens 
    internally. Is this really the desired behavior of Tcl?
    
    Looking at tclIO.c, I find that in Tcl_GetStdChannel() 
    the statement "tsdPtr->stdinInitialized = 1" is done 
    unconditionally, even when the preceeding "tsdPtr-
    >stdinChannel = TclpGetDefaultStdChannel(TCL_STDIN)" 
    returns NULL. This is the reason why, at the end of 
    Tcl_CreateChannel(), the first programatically created 
    channel is automatically registered as stdin, the next 
    as stdout etc., even though these standard channels 
    weren't really initialized (because they couldn't be 
    obtained).
    
    This conflicts with the documentation, since neither 
    Tcl_SetStdChannel() was called with NULL, nor was 
    Tcl_Close() called.
    
    Proposed fix: In TclGetStdChannel(), do the "tsdPtr-
    >stdinInitialized = 1" only when 
    TclpGetDefaultStdChannel(TCL_STDIN) returned != NULL 
    (and similar for stdout and stderr). That is, move 
    those lines down a bit into the already existing if() 
    statements. Is this the right solution (or is there 
    not even a problem ;-)?
    
    Diff for tclIO.c:
    
    332d331
    < tsdPtr->stdinInitialized = 1;
    343a343
    >             tsdPtr->stdinInitialized = 1;
    353d352
    < tsdPtr->stdoutInitialized = 1;
    354a354
    >             tsdPtr->stdoutInitialized = 1;
    364d363
    < tsdPtr->stderrInitialized = 1;
    365a365
    >             tsdPtr->stderrInitialized = 1;
    
    
  4. foundin changed to: "obsolete: 8.3.3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "mmg_kraus"
  9. subsystem changed to: "27. Channel Types"
  10. title changed to: "How standard channels are set"
  11. type changed to: "Bug"