Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zpty non-functional?

On Sat, 24 Aug 2013 13:10:41 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> A quick check with "ps"/"strace" indicates that "cat" is being stopped with
> a TTIN signal.  That's kind of odd, it means that in spite of being on a
> new pty it is not being "attached" to that tty as group leader.  I would say
> this is in fact a bug in zpty.

Hmm... this is well outside my comfort zone.  I thought the following
existing code:

	ioctl(slave, TIOCSCTTY, 0);

should have that effect (man tty_ioctl, all the following on Linux, actually Fedora 15):

       TIOCSCTTY int arg
              Make  the given terminal the controlling terminal of the calling

But it apparently doesn't, and sure enough with the patch below...

% zpty x cat
% zpty -w x this is some text
% zpty -r x var
% print $var
this is some text

(I think you need that "var" there, otherwise zpty waits for the process
to exit, which isn't what you want.  This is not the only place the
syntax is a bit wayward...)

The following is after the setsid() (or setpgrp() if that fails or
doesn't exist).  Maybe it should be conditional on one of those
succeeding (and do we *really* want to do setpgrp() if setsid() fails,
even with a warning)?  Or maybe I'm missing the point entirely and just
got lucky?

diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 25ec7df..f31e0ba 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -344,6 +344,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
 	if (get_pty(0, &slave))
+	attachtty(mypid);
 	/* Set the window size before associating with the terminal *
 	 * so that we don't get hit with a SIGWINCH.  I'm paranoid. */

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