Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c8899efe6d33f3b2635c529c30a6fa234eb436dfd574ca30c9a0b2b58ef79d98
Ticket: 8419c55e2cb159f977b76cadb3cebe0353389b22
Tclsh read loop does not handle EINTR
User & Date: anonymous on 2021-02-27 04:08:26
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    I'm building an extension to a large and rather opaque Linux package
    (About which I won't say more).  One of the things I knew from the
    documentation, but which I had not thought about is that the package
    uses timers and SIGALRM handling internally to do its house keeping
    and maintain its state.  I saw the warning to not use SIGALRM in
    any calling program, but since I wasn't doing that, and was pretty
    sure Tcl wasn't doing that, I wasn't worried.
    
    And in fact, things work pretty well as long as I am running my
    tests from scripts.  I noticed however, that if I had the package
    loaded in an interactive Tclsh so I could type things at it, Tclsh
    would often unexpectedly & silently exit. I finally figured out
    this must be whenever a SIGLARM fires and the package calls its
    handler function.
    
    Looking at the code in tclUnixChan.c where the Tclsh terminal read
    loop reads are done, I see that EINTR is not handled, even though
    it is handled for pipes and sockets elsewhere.
    
    If I make the following change, based on the code used for pipes
    and sockets,  and compile a new Tclsh, it works fine.  This seems
    like a bug to me -- is there some reason for not handling EINTR
    here?
    
    
    % diff -c tclUnixChan.c.bak tclUnixChan.c
    *** tclUnixChan.c.bak   Fri Feb 12 13:59:13 2021
    --- tclUnixChan.c       Fri Feb 12 13:59:13 2021
    ***************
    *** 253,259 ****
           * nonblocking, the read will never block.
           */
      
    !     bytesRead = read(fsPtr->fd, buf, (size_t) toRead);
          if (bytesRead > -1) {
            return bytesRead;
          }
    --- 253,262 ----
           * nonblocking, the read will never block.
           */
      
    !     do {
    !       bytesRead = read(fsPtr->fd, buf, (size_t) toRead);
    !     } while ((bytesRead < 0) && (errno == EINTR));
    ! 
          if (bytesRead > -1) {
            return bytesRead;
          }
    
  5. foundin changed to: "8.6.*"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "f453a2d8b2491bec888a11ddd709eccbaa04b032"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "55. Other Tools"
  15. title changed to: "Tclsh read loop does not handle EINTR"
  16. type changed to: "Bug"