Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#885 closed defect (fixed)

pty egg: example doesn't work

Reported by: megane Owned by: Alex Shinn
Priority: minor Milestone:
Component: extensions Version: 4.7.x
Keywords: pty Cc:
Estimated difficulty:

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	  	<--

Change History (4)

comment:1 Changed 12 years ago by sjamaan

Milestone: 4.8.0
Owner: set to Alex Shinn
Status: newassigned

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.

comment:2 Changed 12 years ago by Alex Shinn

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.

comment:3 Changed 12 years ago by sjamaan

Resolution: fixed
Status: assignedclosed

Works fine. Closing the ticket

comment:4 Changed 12 years ago by megane

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!

Note: See TracTickets for help on using tickets.