diff options
author | Mark Glines <mark@glines.org> | 2002-06-26 05:32:13 +0000 |
---|---|---|
committer | Mark Glines <mark@glines.org> | 2002-06-26 05:32:13 +0000 |
commit | 34f1a73ae024aba08f1222ffaa4a4dd30b505c20 (patch) | |
tree | 3dd7c95ec9c14900259e0ae97fe84572b151ee81 /perl/examples/rmount.pl | |
parent | a6e354a6145bf958701204cf3cf99c8f2ef1c0b2 (diff) | |
download | libfuse-34f1a73ae024aba08f1222ffaa4a4dd30b505c20.tar.gz |
moved examples into a subdirectory
updated the README
Diffstat (limited to 'perl/examples/rmount.pl')
-rwxr-xr-x | perl/examples/rmount.pl | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/perl/examples/rmount.pl b/perl/examples/rmount.pl new file mode 100755 index 0000000..eef8ed8 --- /dev/null +++ b/perl/examples/rmount.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +use strict; +use Net::SSH 'sshopen2'; +use IPC::Open2; +use Fuse; +use Data::Dumper; + +my ($host, $dir, $mount) = @ARGV; +if(!defined($mount)) { + $mount = $dir; + if($host =~ /^(.*):(.*)$/) { + ($host,$dir) = ($1,$2); + } else { + die "usage: $0 user\@host remotedir mountpoint\n". + "or : $0 user\@host:remotedir mountpoint\n"; + } +} + +`umount $mount` unless -d $mount; +die "mountpoint $mount isn't a directory!\n" unless -d $mount; + +my (%args) = (mountpoint => $mount); + +map { my ($str) = $_; $args{$str} = sub { netlink($str,@_) } } + qw(getattr getdir open read write readlink unlink rmdir + symlink rename link chown chmod truncate utime mkdir + rmdir mknod statfs); + +sub connect_remote { + sshopen2($host, *READER, *WRITER, "./rmount_remote.pl $dir") + or die "ssh: $!\n"; +# open2(*READER,*WRITER,"./rmount_remote.pl $dir"); + select WRITER; + $| = 1; + select STDOUT; +} + +$SIG{CHLD} = sub { + use POSIX ":sys_wait_h"; + my $kid; + do { + $kid = waitpid(-1,WNOHANG); + } until $kid < 1; +}; + +connect_remote; + +sub netlink { + my ($str) = join("\n",map {" $_"} (split("\n",Dumper(\@_))))."\n"; + $str = sprintf("%08i\n%s",length($str),$str); + while(1) { # retry as necessary + my ($sig) = $SIG{ALRM}; + my ($VAR1); + $VAR1 = undef; + eval { + $SIG{ALRM} = sub { die "timeout\n" }; + alarm 10; + print WRITER $str; + my ($len, $data); + if(read(READER,$len,9) == 9) { + read(READER,$data,$len-length($data),length($data)) + while(length($data) < $len); + eval $data; + } + }; + alarm 0; + $SIG{ALRM} = $sig; + if(defined $VAR1) { + return wantarray ? @{$VAR1} : $$VAR1[0]; + } + print STDERR "failed to send command; reconnecting ssh\n"; + close(READER); + close(WRITER); + connect_remote(); + } +} + +Fuse::main(%args); + +netlink("bye"); +close(READER); +close(WRITER); |