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

Re: zpty woes



On Thu, May 15, 2008 at 02:18:57PM +0100, Peter Stephenson wrote:
> Jaime Vargas wrote:
> > In the script attached, when trying to follwing line always fails.
> > 
> >      zpty -r scppty line "*:" || echo "no password asked" && exit
> > 
> > It appears that the "password" string from the ssh session is discarded
> > by the psuedo terminal.
> > 
> > Is there a way to fix this? or Am I missing something?
> 
> Yes and yes, but it's annoying and I spent a few minutes rediscovering
> the arcana.  zpty attempts to read in whole lines, while the password
> prompt isn't a whole line.  I came across this myself and looked at the
> code a while ago and it seemed unnecessarily obscure.  However, I worked
> around it and don't have time to make it work sensibly in all the
> possible cases, so I'm not touching it.  (If anyone's interested it's in
> ptyread() in Src/Modules/zpty.c and could definitely do with someone
> taking it over; it's pretty much self-contained.)
> 
> To work around this, you need to use non-blocking mode, i.e. start with
> "zpty -b scppty ...".  I think (although the code is obscure) that with
> your "*:" pattern this will work, i.e. although it doesn't block it will
> carry on reading until it gets the password input.  If not, you would
> need to delay (the zsh/zselect module allows you to do this in 100ths of
> a second) and retry.  (Waiting for a pattern with noblocking is
> effectively a busy wait so even this isn't ideal---you can add the -t
> option to the -r command line to test first, but then it *won't* wait
> if there's no input and you do have to delay in your script.)
[...]

It works for me without "-b", why would you say "-b" is
necessary?

The problem I've found is that zpty -r doesn't return when the
command in the pty has terminated. A strace -p shows:

read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
read(12, 0xb7ba04c8, 1)                 = -1 EIO (Input/output error)
[...]

And the other problem I mentionned in another email about the
PS4 output not being correct.

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author