3 # This example needs some work before it can support threads.
5 use Net::SSH 'sshopen2';
10 my ($host, $dir, $mount) = @ARGV;
11 if(!defined($mount)) {
13 if($host =~ /^(.*):(.*)$/) {
14 ($host,$dir) = ($1,$2);
16 die "usage: $0 user\@host remotedir mountpoint\n".
17 "or : $0 user\@host:remotedir mountpoint\n";
21 `umount $mount` unless -d $mount;
22 die "mountpoint $mount isn't a directory!\n" unless -d $mount;
24 my (%args) = (mountpoint => $mount);
26 map { my ($str) = $_; $args{$str} = sub { netlink($str,@_) } }
27 qw(getattr getdir open read write readlink unlink rmdir
28 symlink rename link chown chmod truncate utime mkdir
32 sshopen2($host, *READER, *WRITER, "./rmount_remote.pl $dir")
40 use POSIX ":sys_wait_h";
43 $kid = waitpid(-1,WNOHANG);
50 my ($str) = Dumper(\@_)."\n";
51 $str = sprintf("%08i\n%s",length($str),$str);
52 while(1) { # retry as necessary
56 local $SIG{ALRM} = sub { die "timeout\n" };
61 if(sysread(READER,$len,9) == 9) {
62 sysread(READER,$data,$len-length($data),length($data))
63 while(length($data) < $len);
69 return wantarray ? @{$VAR1} : $$VAR1[0];
71 print STDERR "failed to send command; reconnecting ssh\n";