Reto Schuettel
3/23/2006 6:30:00 PM
Hi Jonathan
On Thu, Mar 23, 2006 at 12:34:31PM +0000, Jonathan Paisley wrote:
> I implemented a quick hack to do this. Hopefully the code below will help.
> It's a bit of a mess, but allows you to use a DRb scheme like
> 'drbfd://0,1' which means uses file descriptors 0 and 1 (stdin/stdout) for
> communication.
>
> module DRb
That's great! exactly what I needed.
For the record: My statement in the first mail wasn't completely
correct, the pipe I used in my example is only a 'one-way' thing. But
ssh actually transports three streams/pipes: stdin, stdout and stderr, so this
isn't really a problem.
There's one small problem with your fdsocket, it seems like the drb
server/thread doesn't always terminate itself when the streams get
closed. But I will try to investigate this by myself tomorrow :).
I've appended an example which uses your library. It creates two pipes,
forks, connects the pipes to the stdin/stdout of the child and then execs
the ssh client. The same technique could also be used to communicate
with a child (instead of a unix/tcp socket or a simple plain pipe). IMHO
that's really nice, great work Jonathan!
require 'drb'
require 'fdsocket'
ctprd, ctpwr = IO.pipe
ptcrd, ptcwr = IO.pipe
pid = fork
unless pid
# child
ctprd.close
ptcwr.close
$stdin.reopen( ptcrd )
$stdout.reopen( ctpwr )
exec("ssh", "hostname", "./agent.rb")
exit # child shounld't reach this point
end
# parent
ctpwr.close
ptcrd.close
fd_read = ctprd.fileno
fd_write = ptcwr.fileno
# The URI to connect to
SERVER_URI="drbfd://#{fd_read},#{fd_write}"
DRb.start_service
obj = DRbObject.new_with_uri(SERVER_URI)
[...]
Regards,
Reto Schuettel