Skip to content
Tcl Source Code History Of Ticket 2647951
Login

History Of Ticket 2647951

Artifacts Associated With Ticket 2647951

  1. Ticket change [e54f23497f] (rid 88106) by eugene_cdn on 2009-02-28 06:56:26:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Tcl version: 8.4+
      OS: Linux Red Hat 4, 5
      Maybe, it is a Linux bug, but it appeared in Tcl's stdin handling. I got the problem in C, but I created a Tcl script that fails the same way.
      If you execute a certain command though system()/exec which fails, stdin stream does not provide any more input except already buffered in C code. My Tcl script is more that 8K long because I initially got the problem on the very next byte after 8K, but attached test fails a bit earlier.
      Important: file must be redirected to stdin:
      > tclsh <xxx.tcl
      Read(0) just returns 0 as if it is the end of pipe/socket. If you specify file name as an argument, the script works.
      I cannot classify the problem. Just weird. Stdin stays open, /proc/pid/fd shows it, but 0 handle is damaged. Fork/clone is doing something bad to to the parent's stdin.
      Any help is appreciated. I cannot depend on any developer who can call system() and break stdin. Yes, I know that such redirection seem to make no sense, but it does; it is just a simplified version.
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "eugene_cdn"
    10. subsystem initialized to: "None"
    11. title initialized to: "Error in exec ends stdin"
    12. type initialized to: "Bug"
  2. Ticket change [73b29260f4] (rid 105082) by eugene_cdn on 2009-02-28 13:56:26:

    1. icomment:
      
      
      File Added - 315531: xxx.tcl
      
      
      
    2. login: "eugene_cdn"
    3. mimetype: "text/plain"
    4. username: "eugene_cdn"
  3. Add attachment "xxx.tcl" [52fedf3ed7] (rid 126408) by eugene_cdn on 2009-02-28 13:56:26.

  4. Ticket change [1c70aeac15] (rid 90606) by ferrieux on 2009-02-28 19:23:27:

    1. icomment:
      Please attach an strace:
      
           strace -f -tt -o tra tclsh < xxx.tcl
      
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  5. Ticket change [98be1d2066] (rid 110661) by dkf on 2009-02-28 19:46:48:

    1. subsystem changed to: "50. Embedding Support"
  6. Ticket change [c0e937199e] (rid 102499) by dkf on 2009-02-28 19:46:49:

    1. assignee changed to: "ferrieux"
    2. foundin changed to: "obsolete: 8.4.19"
  7. Add attachment "tra" [1e62a39a58] (rid 90962) by eugene_cdn on 2009-03-01 00:33:32.

  8. Ticket change [e94488ce1e] (rid 104794) by eugene_cdn on 2009-03-01 00:33:33:

    1. icomment:
      
      
      File Added - 315586: tra
      
      File Added: tra
      
      
    2. login: "eugene_cdn"
    3. mimetype: "text/plain"
    4. username: "eugene_cdn"
  9. Ticket change [b3731159a2] (rid 124863) by eugene_cdn on 2009-03-01 01:53:08:

    1. icomment:
      
      
      File Added - 315599: tra
      
      File Added: tra
      
      
    2. login: "eugene_cdn"
    3. mimetype: "text/plain"
    4. username: "eugene_cdn"
  10. Ticket change [f7e2c7d2e2] (rid 91448) by eugene_cdn on 2009-03-01 01:55:18:

    1. icomment:
      
      
      File Deleted - 315599: 
      
      
      
    2. login: "eugene_cdn"
    3. mimetype: "text/plain"
    4. username: "eugene_cdn"
  11. Ticket change [c9d843e84d] (rid 122357) by ferrieux on 2009-03-01 17:57:43:

    1. closedate changed to: "2009-03-01T10:57:43"
    2. closer changed to: "ferrieux"
    3. icomment:
      
      
      allow_comments - 1
      
      OK got it. This is not a Tcl nor Linux problem, just one specific behavior of csh.
      Details from the strace:
      
      12200 09:32:12.664493 execve("/bin/csh", ["csh"..., "-fc"..., "echo hello >fff"...], [/* 69 vars */] <unfinished ...>
      12200 09:32:12.675081 dup2(0, 16)       = 16
      12200 09:32:12.747895 open("fff", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied)
      12200 09:32:12.748463 write(18, "fff: Permission denied.\n", 24) = 24
      12200 09:32:12.748541 lseek(16, 0, SEEK_END) = 8660
      
      Explanation:
      
      (1) The dup2 is part of the redirections for the "echo hello" command. It just inherits desc 0 because there is no redirection on stdin.
      (2) Csh tries to honour the > redirection, and gets an (expected) error. It barfs to stderr (which is okay).
      (3) *but* it also decides to skip ahead to the end of the local subcommand's stdin (lseek(16,...))
      (4) All this hooks back to Tcl's stdin since the [exec csh] has no stdin redirection either.
      (5) Hence on the next attempt to read, the Tcl IO subsystem gets an EOF. QED.
      
      I have no idea why Csh does (3). At the extreme it could vaguely make sense for an interactive Csh to do that on a terminal, so that it skips to new typed command when an error has occurred in a buffered block of commands... But here the Csh is not interactive. From my seat it is a fully qualified Bug.
      
      A simple workaround is to [exec csh ... < /dev/null].
      
      I'll thus close this artifact as Invalid, since Tcl cannot be held responsible for Csh's misbehavior.
      My personal take on Csh is: only use it interactively if ever. That's not a programming language. That's an engineer's nightmare.
      *Always* use /bin/sh when you need to resort to an OS shell.
      
      
      
      
    4. login: "ferrieux"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
    8. username: "ferrieux"
  12. Ticket change [5753bbaabe] (rid 94471) by eugene_cdn on 2009-03-02 03:43:49:

    1. icomment:
      Thanks!!!
      
      
    2. login: "eugene_cdn"
    3. mimetype: "text/plain"
    4. username: "eugene_cdn"