diff --git a/c.rb b/c.rb index 2e6b90c..c7e3f05 100755 --- a/c.rb +++ b/c.rb @@ -43,5 +43,5 @@ else $stdout.reopen tor.last tor.first.close $stderr.puts( {proc: 'c', exec: 'reciever', destination: ARGV[2]}.to_json) - exec 'perl', 'r.pl', ARGV[2].shdump + exec 'perl', 'r.pl', ARGV[2] end diff --git a/r.pl b/r.pl index 1530fb5..fe91195 100755 --- a/r.pl +++ b/r.pl @@ -6,8 +6,8 @@ $|++; $SIG{CLD} = sub { wait; - printf STDERR "{proc: \"r\", action: \"exit\", code: 1, error: \"child_died\"}\n"; - exit 1; + printf STDERR "{proc: \"r\", action: \"exit\", code: $?, error: \"child_died\"}\n"; + exit $?; }; sub readcmd { @@ -18,16 +18,15 @@ sub readcmd { $data; } +chdir $ARGV[0] or die( "{proc: \"r\", error: \"cannot_chdir\", exception: \"$!\"}\n"); while( my$data = readcmd) { (my$cmd, my$length) = unpack( 'nN', $data); print STDERR "{cmd: $cmd, length: $length}\n"; read STDIN, $data, $length; if( 1 == $cmd) { - 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 pack( 'N', $size); + open( F, '>>', $data) or die( "{proc: \"r\", error: \"unable_to_open_file\", message: \"Can't open file <$data>.\"}\n"); + my@stat = stat F; + print pack( 'N', $stat[7]); } elsif( 2 == $cmd) { print F $data;