From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3911 invoked from network); 15 May 2008 13:27:43 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 May 2008 13:27:43 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 39661 invoked from network); 15 May 2008 13:27:40 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 May 2008 13:27:40 -0000 Received: (qmail 18628 invoked by alias); 15 May 2008 13:27:37 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25037 Received: (qmail 18612 invoked from network); 15 May 2008 13:27:36 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 15 May 2008 13:27:36 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [85.115.41.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 5B4F580589A4 for ; Thu, 15 May 2008 15:27:26 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly20g.srv.mailcontrol.com (MailControl) with ESMTP id m4FDQf6q020261 for ; Thu, 15 May 2008 14:27:19 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Thu, 15 May 2008 14:18:57 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.14.2/8.13.4) with ESMTP id m4FDIwia015247 for ; Thu, 15 May 2008 14:18:58 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.14.2/8.14.2/Submit) with ESMTP id m4FDIvKS015244 for ; Thu, 15 May 2008 14:18:58 +0100 Message-Id: <200805151318.m4FDIvKS015244@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk Subject: Re: zpty woes In-reply-to: <34AE8142-F5DA-44FD-96BA-61BDE12BC74E@mac.com> References: <34AE8142-F5DA-44FD-96BA-61BDE12BC74E@mac.com> Comments: In-reply-to Jaime Vargas message dated "Thu, 15 May 2008 08:02:04 -0400." Date: Thu, 15 May 2008 14:18:57 +0100 From: Peter Stephenson X-OriginalArrivalTime: 15 May 2008 13:18:57.0936 (UTC) FILETIME=[3B778900:01C8B68E] X-Scanned-By: MailControl A-08-50-03 (www.mailcontrol.com) on 10.71.0.130 X-Virus-Scanned: ClamAV 0.91.2/7128/Thu May 15 12:45:41 2008 on bifrost X-Virus-Status: Clean 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.) Anyway, it now seems to work for me (though if there were an occasional race I might have missed it). -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070