From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28648 invoked by alias); 16 Dec 2013 18:16:05 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32131 Received: (qmail 19321 invoked from network); 16 Dec 2013 18:15:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <131216101527.ZM13903@torch.brasslantern.com> Date: Mon, 16 Dec 2013 10:15:27 -0800 In-reply-to: Comments: In reply to "Jun T." "accessing zpty after child has finished (Mac OS X)" (Dec 17, 1:33am) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: accessing zpty after child has finished (Mac OS X) MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Dec 17, 1:33am, Jun T. wrote: } } - if ((r = read(cmd->fd, &c, 1)) < 0) { } + if ((r = read(cmd->fd, &c, 1)) <= 0) { I don't see any significant ill effect from this other than some extra kill(pid, 0) calls which should be low overhead. There is a chance that it will leave some child output un-consumed on platforms where the PTY does maintain the buffer until both ends are closed. There's no generalized way around this except for using the same kind of special sync write/read that's exchanged when the PTY is being set up, but that would have to be done out of band, whereas the startup sync is in-band (uses the PTY itself). However, Jun's change makes a subsequent test unnecessary. I propose this instead: diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index fca0cc1..d119658 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -510,14 +510,14 @@ checkptycmd(Ptycmd cmd) if (cmd->read != -1 || cmd->fin) return; - if ((r = read(cmd->fd, &c, 1)) < 0) { + if ((r = read(cmd->fd, &c, 1)) <= 0) { if (kill(cmd->pid, 0) < 0) { cmd->fin = 1; zclose(cmd->fd); } return; } - if (r) cmd->read = (int) c; + cmd->read = (int) c; } static int