zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: accessing zpty after child has finished (Mac OS X)
Date: Mon, 16 Dec 2013 10:15:27 -0800	[thread overview]
Message-ID: <131216101527.ZM13903@torch.brasslantern.com> (raw)
In-Reply-To: <C87F9A07-1C5B-46BA-B2F7-DB07880651A7@kba.biglobe.ne.jp>

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


      reply	other threads:[~2013-12-16 18:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-16 16:33 Jun T.
2013-12-16 18:15 ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=131216101527.ZM13903@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).