master
Denis Knauf 2010-09-27 16:42:03 +02:00
parent f4680dfd8d
commit 650cf81e71
3 changed files with 12 additions and 34 deletions

16
c.rb
View File

@ -15,18 +15,18 @@ class IO
end
end
class String
def shdump
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
end
end
class File
def self.readall file
open( file) {|f| f.readall }
end
end
class String
def shdump
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
end
end
$tor = tor = IO.pipe
$tos = tos = IO.pipe
@ -38,10 +38,6 @@ if Process.fork
$stderr.puts( {proc: 'c', connect: ARGV[0], args: ARGV[1]}.to_json)
exec 'ssh', ARGV[0], 'perl', '-e', File.readall( 's.pl').shdump, ARGV[1].shdump
else
#$stdout.puts 'test'
#$stderr.print '>> '
#$stdin.each_line {|l| p eval( l); print '>> ' }
$stdin.reopen tos.first
tos.last.close
$stdout.reopen tor.last

18
r.pl
View File

@ -5,19 +5,11 @@ use warnings;
$|++;
$SIG{CLD} = sub {
printf STDERR "{proc: \"r\", action: \"child_died\"}\n";
wait;
printf STDERR "{proc: \"r\", action: \"exit\", code: 0}\n";
exit 0;
printf STDERR "{proc: \"r\", action: \"exit\", code: 1, error: \"child_died\"}\n";
exit 1;
};
my @cmds = (
1 => 'file',
2 => 'content'
);
print STDERR "r << s";
sub readcmd {
my $data = '';
while( length( $data) < 6) {
@ -27,21 +19,17 @@ sub readcmd {
}
while( my$data = readcmd) {
printf STDERR "{proc: \"r\", read_length: %d}\n", length( $data);
(my$cmd, my$length) = unpack( 'nN', $data);
print STDERR "{cmd: $cmd, length: $length}\n";
print STDERR "r << s\n";
read STDIN, $data, $length;
if( 1 == $cmd) {
print STDERR "{proc: \"r\", action: \"open_file\", file: \"$data\"}\n";
print STDERR "{proc: \"r\", action: \"open\", file: \"$data\"}\n";
open( F, '>>', $data) or print STDERR ("{proc: \"r\", error: \"unable_to_open_file\", message: \"Can't open file <$data>.\"}\n");
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat F;
print STDERR "r >> s\n";
print pack( 'N', $size);
}
elsif( 2 == $cmd) {
print STDERR "r >> f\n";
print F $data;
}
else {

12
s.pl
View File

@ -4,8 +4,6 @@ use strict;
use warnings;
$|++;
my%cmds = (file => 1, content => 2);
my$dir = shift @ARGV;
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n");
($dir, my$fexpr) = ($1, $2);
@ -15,18 +13,14 @@ opendir( my$dh, '.') || die "{proc: \"s\", error: \"dir_not_found\", message: \"
while( my$filename = readdir( $dh)) {
$filename =~ /$fexpr/ or next;
-f $filename or next;
print STDERR "s >> r\n";
print pack( 'nN/A*', $cmds{file}, $filename);
print pack( 'nN/A*', 1, $filename);
print STDERR "{proc: \"s\", action: \"open\", file: \"$filename\"}\n";
open F, $filename;
print STDERR "s << r\n";
read STDIN, my$length, 4; # Was wenn < 4 ?
$length = unpack 'N', $length;
print STDERR "s: seek $length\n";
seek F, $length, 0;
print STDERR "s >>>> r\n";
while( read( F, my$r, 2048)) {
print pack( 'nN/(A*)', $cmds{content}, $r);
while( read( F, my$r, 2040)) {
print pack( 'nN/A*', 2, $r);
}
print STDERR "{proc: \"s\", action: \"close\", file: \"$filename\"}\n";
close F;