From 650cf81e7180920483621f98383d7e5878ae3171 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Mon, 27 Sep 2010 16:42:03 +0200 Subject: [PATCH] ready --- c.rb | 16 ++++++---------- r.pl | 18 +++--------------- s.pl | 12 +++--------- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/c.rb b/c.rb index 6fe17c9..2e6b90c 100755 --- a/c.rb +++ b/c.rb @@ -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 diff --git a/r.pl b/r.pl index 2682f12..1530fb5 100755 --- a/r.pl +++ b/r.pl @@ -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 { diff --git a/s.pl b/s.pl index 0bd678b..7b8e895 100755 --- a/s.pl +++ b/s.pl @@ -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;