Skip to content
Tcl Source Code History Of Ticket 219252
Login

History Of Ticket 219252

Artifacts Associated With Ticket 219252

  1. Ticket change [85f815191b] (rid 131423) by nobody on 2000-10-26 05:04:11:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 5759 Bug
      Version: 8.4a1
      SubmitDate: '2000-05-31'
      LastModified: '2000-08-22'
      Severity: CRIT
      Status: Assigned
      Submitter: techsupp
      ChangedBy: hobbs
      RelatedBugIDs: 6148
      OS: Linux-Red Hat
      FixedDate: '2000-10-25'
      ClosedDate: '2000-10-25'
      
      
      Name:
      
      Mo
      
      
      CVS:
      
      Mon May 29
      
      
      Comments:
      
      I was not sure where to put a regression test for this problem. I
      
          thought
      
          about adding one to ioCmd.test but the test I created would only work on
      
          UNIX. I am open to suggestions on where and how to add a test for this
      
          feature.
      
      
          Another interesting question is should the blocking status of the pipe
      
          have anything to do with the choice between using WNOHANG or 0 as the
      
          argument to Tcl_WaitPid?
      
      
      ReproducibleScript:
      
      This problem can be demonstrated in a simple two line script
      
      that will hang Tcl.
      
      
      set pipe [open {|/bin/sh -c "sleep 60"} r]
      
      close $pipe
      
      
      ObservedBehavior:
      
      The above script will hang a Tcl/Tk process for 60 seconds.
      
      If the program being run in the pipe was stuck in a loop, Tcl
      
      would never return.
      
      
      DesiredBehavior:
      
      I would like Tcl to return an error in the case where a process
      
      in the pipeline would deadlock. The right thing to do would be
      
      to tell the user what happened and then reap the pid later.
      
      
      Here is the output after my patch has been applied.
      
      
      set pipe [open {|/bin/sh -c "sleep 60"} r]
      
      close $pipe
      
      child status not available: 12257
      
      
      For multiple commands in a pipeline, we get multiple errors.
      
      
      set pipe [open {|/bin/sh -c "sleep 60" | /bin/sh -c "sleep 60" | /bin/sh -c "exit -1"} r]
      
      close $pipe
      
      child status not available: 12258
      
      child status not available: 12259
      
      child process exited abnormally
      
      
      Patch:
      
      Index: doc/close.n
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/doc/close.n,v
      
      retrieving revision 1.2
      
      diff -u -r1.2 close.n
      
      --- close.n1998/09/14 18:39:511.2
      
      +++ close.n2000/05/29 11:05:32
      
      @@ -53,7 +53,9 @@
      
       .VE
      
       .PP
      
       The command returns an empty string, and may generate an error if
      
      -an error occurs while flushing output.
      
      +an error occurs while flushing output. The close command can also
      
      +generate an error if the child's status is not available because
      
      +the child has not yet terminated.
      
      
       .SH KEYWORDS
      
       blocking, channel, close, nonblocking
      
      Index: generic/tclPipe.c
      
      ===================================================================
      
      RCS file: /cvsroot/tcl/generic/tclPipe.c,v
      
      retrieving revision 1.3
      
      diff -u -r1.3 tclPipe.c
      
      --- tclPipe.c1999/04/16 00:46:511.3
      
      +++ tclPipe.c2000/05/29 11:05:36
      
      @@ -282,7 +282,7 @@
      
      
           abnormalExit = 0;
      
           for (i = 0; i < numPids; i++) {
      
      -        pid = Tcl_WaitPid(pidPtr[i], (int *) &waitStatus, 0);
      
      +        pid = Tcl_WaitPid(pidPtr[i], (int *) &waitStatus, WNOHANG);
      
       if (pid == (Tcl_Pid) -1) {
      
           result = TCL_ERROR;
      
                   if (interp != (Tcl_Interp *) NULL) {
      
      @@ -322,7 +322,31 @@
      
                                   (char *) NULL);
      
                       }
      
       abnormalExit = 1;
      
      -    } else if (WIFSIGNALED(waitStatus)) {
      
      +    } else if (pid == 0) {
      
      +                /*
      
      + * In this case, we tried to wait for a child
      
      +                 * that had not yet terminated. This is a special
      
      +                 * case, we need to put the child pid on our
      
      +                 * list of pids to be reaped later but we cant
      
      +                 * use the pid returned by Tcl_WaitPid as it is 0.
      
      +                 * Get the original child pid from pidPtr[i]
      
      +                 * and set a reasonable error code and message.
      
      +                 */
      
      +
      
      +                Tcl_DetachPids(1, &pidPtr[i]);
      
      +
      
      +                if (interp != (Tcl_Interp *) NULL) {
      
      +                    TclFormatInt(msg1, (long) pidPtr[i]);
      
      +
      
      +                    /* documentation for pclose uses ECHILD for this errno */
      
      +                    Tcl_SetErrorCode(interp, "ECHILD", msg1,
      
      +                            (char *) NULL);
      
      +                    
      
      +                    Tcl_AppendResult(interp, "child status not available: ", msg1, "\n",
      
      +                            (char *) NULL);
      
      +                }
      
      +
      
      +            } else if (WIFSIGNALED(waitStatus)) {
      
                       if (interp != (Tcl_Interp *) NULL) {
      
                           char *p;
      
      
      PatchFiles:
      
      doc/close.n
      
          generic/tclPipe.c
      
      
      
      
      Mo adds later:
      
      I later found that the change I suggested in 5759 caused
      some other problems with a normal exec, so it really should
      not be applied as is.
       
      -- 08/22/2000 hobbs
      
    4. foundin initialized to: "obsolete: 8.4a1"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "60. NRE and coroutines"
    10. title initialized to: "Tcl deadlocks when closing a piped command."
    11. type initialized to: "Bug"
  2. Ticket change [2c2b8e9e6f] (rid 118853) by dkf on 2001-01-09 22:19:12:

    1. icomment:
      It would be fair for the error to only be generated in the case where blocking is not permitted ([fconfigure $pipe -blocking 0]) as this would also allow a tackling of bug #119255 with the same stone.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  3. Ticket change [4ee0737fc3] (rid 125723) by dgp on 2001-04-05 08:20:12:

    1. subsystem changed to: "27. Channel Types"
  4. Ticket change [8b6452658c] (rid 127559) by andreas_kupries on 2001-09-08 06:38:38:

    1. assignee changed to: "andreas_kupries"
  5. Ticket change [f3a99042ea] (rid 129750) by andreas_kupries on 2001-09-12 03:03:47:

    1. icomment:
      Logged In: YES 
      user_id=75003
      
      Rather #219255 after SF renumbering tango.
      
      
    2. login: "andreas_kupries"
    3. mimetype: "text/plain"
    4. username: "andreas_kupries"
  6. Ticket change [c06182fdd1] (rid 102392) by hobbs on 2004-11-12 03:28:43:

    1. assignee changed to: "davygrvy"
    2. icomment:
      Logged In: YES 
      user_id=72656
      
      Passing to davygrvy - I think he addressed this.
      
      
    3. login: "hobbs"
    4. mimetype: "text/plain"
    5. username: "hobbs"
  7. Ticket change [1b8b6dd1ad] (rid 123171) by davygrvy on 2004-11-12 04:28:32:

    1. closedate changed to: "2004-11-11T21:28:32"
    2. closer changed to: "davygrvy"
    3. icomment:
      Logged In: YES 
      user_id=7549
      
      With '-blocking 0' the [close] will not block, nor return
      any exit status.  When that behavior came around in
      unix/tclUnixPipe.c, I don't know for sure.
      
      So currently (8.4 at least) there is a path for this.  Same
      on windows, too.
      
      
    4. login: "davygrvy"
    5. mimetype: "text/plain"
    6. resolution changed to: "Works For Me"
    7. status changed to: "Closed"
    8. username: "davygrvy"