zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: zpty non-functional?
Date: Sun, 25 Aug 2013 19:59:46 +0100	[thread overview]
Message-ID: <20130825195946.2f9799c6@pws-pc.ntlworld.com> (raw)
In-Reply-To: <130824170157.ZM15713@torch.brasslantern.com>

On Sat, 24 Aug 2013 17:01:57 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> I'm a bit
> surprised that calling attachtty() works, because it relies on SHTTY
> having been set to the right thing, and I don't see that anything in
> zpty.c is making sure that slave and SHTTY refer to the same fd; but
> perhaps it always is for some indirect reason ...
> 
> Is it safe/reasonable to add
> 
> 	SHTTY = slave;
> 
> right before the attachtty() call in your patch?

That seems to work, anyway.

I added a test, but if instead of using the pipe I add a string as
arguments to zpty -w it usually fails:  I get some of the string
followed by the whole of the string in the output.  This suggests the
write is doing something weird.

I added the trick to make it use _exit() (as we haven't forked) at the
end of the slave code, but that didn't help --- which it probably
shouldn't anyway for various reasons, but I left it in since it looked
logically correct anyway.

So there's something else to investigate.

diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 25ec7df..3821194 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -344,6 +344,8 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
 
 	if (get_pty(0, &slave))
 	    exit(1);
+	SHTTY = slave;
+	attachtty(mypid);
 #ifdef TIOCGWINSZ
 	/* Set the window size before associating with the terminal *
 	 * so that we don't get hit with a SIGWINCH.  I'm paranoid. */
@@ -398,6 +400,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
 	opts[INTERACTIVE] = 0;
 	execode(prog, 1, 0, "zpty");
 	stopmsg = 2;
+	mypid = 0; /* trick to ensure we _exit() */
 	zexit(lastval, 0);
     }
     master = movefd(master);
diff --git a/Test/.distfiles b/Test/.distfiles
index 689b695..ab92153 100644
--- a/Test/.distfiles
+++ b/Test/.distfiles
@@ -40,6 +40,7 @@ V04features.ztst
 V05styles.ztst
 V06parameter.ztst
 V07pcre.ztst
+V08zpty.ztst
 Y01completion.ztst
 Y02compmatch.ztst
 Y03arguments.ztst
diff --git a/Test/V08zpty.ztst b/Test/V08zpty.ztst
new file mode 100644
index 0000000..d9d24c5
--- /dev/null
+++ b/Test/V08zpty.ztst
@@ -0,0 +1,20 @@
+# zpty is required by tests of interactive modes of the shell itself.
+# This tests some extra things.
+
+%prep
+
+  if ! zmodload zsh/zpty 2>/dev/null
+  then
+    ZTST_unimplemented="the zsh/zpty module is not available"
+    return 0
+  fi
+
+%test
+
+  zpty cat cat
+  print a line of text | zpty -w cat
+  var=
+  zpty -r cat var && print -r -- ${var%%$'\r\n'}
+  zpty -d cat
+0:zpty with a process that does not set up the terminal
+>a line of text

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2013-08-25 19:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-24 12:44 Valodim Skywalker
2013-08-24 20:10 ` Bart Schaefer
2013-08-24 21:48   ` Peter Stephenson
2013-08-25  0:01     ` Bart Schaefer
2013-08-25 18:59       ` Peter Stephenson [this message]
2013-08-25 22:01         ` Bart Schaefer
2013-08-26 19:33           ` Peter Stephenson
2013-08-27  0:54             ` Bart Schaefer
2013-08-27 12:01               ` Peter Stephenson
2013-08-27 14:31                 ` Bart Schaefer

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=20130825195946.2f9799c6@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.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).