This commit is contained in:
Denis Knauf 2010-09-27 16:56:02 +02:00
parent 650cf81e71
commit 8d242f6511
2 changed files with 7 additions and 8 deletions

2
c.rb
View file

@ -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

13
r.pl
View file

@ -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;