Summary
pty egg: example doesn't work
Metadata
- Id: bdb686572534e7755c1887bc93c05c03578b2c5e
- Trac id: 885
- Type: defect
- Reporter: megane
- Owner: ashinn
- Cc:
- Status: closed
- Component: extensions
- Estimated difficulty:
- Resolution: fixed
- Priority: minor
- Milestone:
- Version: 4.7.x
- Changetime: 2012-07-18 19:05:56 UTC
- Created: 2012-07-10 21:37:38 UTC
- Keywords: pty
Description
The example from the egg wiki doesn't work.
$ csi -v && cat ptytest.scm && csi -nbq ptytest.scm
CHICKEN
(c)2008-2011 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.7.5 (rev 0e44970)
linux-unix-gnu-x86 [ manyargs dload ptables ]
compiled 2012-07-10 on shiro (Linux)
(use pty)
(call-with-pty-process-io "ssh myfirewall"
(lambda (in out pid)
(peek-char in)
(display (gui-get-password) out)
(newline out)
(read-line in)
(display "dhclient 2>/dev/null && echo OK || echo FAIL\n" out)
(unless (equal? "OK" (read-line in))
(error "couldn't launch dhclient"))))
Error: can't read from FD - Resource temporarily unavailable: 4
Call history:
<eval> (call-with-pty-process-io "ssh myfirewall" (lambda (in out pid) (peek-char in) (display (gui-get-pas......
##sys#substring-index
pty.scm:196: string-split
pty.scm:202: process-fork
pty.scm:231: open-file-io/non-blocking
##sys#make-string
pty.scm:90: make-input-port
pty.scm:134: make-output-port
pty.scm:236: proc
<eval> (peek-char in)
pty.scm:94: file-read/maybe
pty.scm:111: g68
pty.scm:76: ##sys#update-errno
##sys#peek-c-string
pty.scm:77: ##sys#string-append
pty.scm:77: ##sys#signal-hook <--
Changes and comments
[2012-07-11 21:44:56 UTC] sjamaan changed status from new to assigned
[2012-07-11 21:44:56 UTC] sjamaan set owner to ashinn
[2012-07-11 21:44:56 UTC] sjamaan removed milestone 4.8.0
[2012-07-11 21:44:56 UTC] sjamaan wrote:
There seem to be several problems with this egg and the example.
One is that errno seems to be bound to a procedure (the "errno" procedure from the library unit) rather than the foreign value (this could be a bug in the module system?? possibly fixed already??) so it will never be eq? to _ewouldblock. Also, while EWOULDBLOCK is identical to EAGAIN on my system, I'm not sure it's everywhere; might want to add that to the check.
You could re-use errno/wouldblock and errno/again from the POSIX unit, by the way.
Furthermore, the library doesn't compile on (Net)BSD because there it needs to include util.h (and also link to libutil, which for some odd reason OS X doesn't require?).
The example, if used literally, will call ssh with a nonexistant hostname, so it probably won't really work and it uses some undefined (gui-get-password) procedure. For now I just added a comment saying that it's not defined and the user needs to define it. Not sure if this is something you meant to take out or something?
If I insert a (sleep 10) as first call in the lambda before the peek-char call, I get an error about this gui procedure, so I guess somehow the child process hasn't started yet or the PTY hasn't been fully set up at the time of the peek-char call. That error message is actually the string that belongs to EAGAIN/EWOULDBLOCK, so I don't quite see why the loop isn't working.
I'll remove the milestone, since this has nothing to do with the Chicken release itself.
[2012-07-18 15:06:34 UTC] ashinn wrote:
Your complaint about the example confused me. Obviously it's a hypothetical example for connecting to some ssh host with your own get-password procedure.
The BSD issue and errno issues are real and have been tentatively fixed, waiting for someone to test them on BSD.
[2012-07-18 17:56:47 UTC] sjamaan changed status from assigned to closed
[2012-07-18 17:56:47 UTC] sjamaan set resolution to fixed
[2012-07-18 17:56:47 UTC] sjamaan wrote:
Works fine. Closing the ticket
[2012-07-18 19:05:56 UTC] megane wrote:
Sorry, I should have been more specific. I actually got the `Error: can't read from FD - Resource temporarily unavailable: 4' error with everything I tried. For example with this:
(use pty)
(call-with-pty-process-io "date"
(lambda (in out pid)
(peek-char in)
(print (read-line in))))
But now it seems to be fixed, thanks!