Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zpty non-functional?
On Sat, 24 Aug 2013 17:01:57 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author