#!/afs/athena/contrib/perl/perl

require 'sys/socket.ph';
require 'sys/un.ph';

$socket_file = $ARGV[0];

$SIG{'INT'} = 'dokill';
sub dokill {
    kill 9,$child if $child;
}

$sockaddr_un = 's a100';

$this = pack ($sockaddr_un, &AF_UNIX, $socket_file);

# Make the socket filehandle.

if (socket(S, &AF_UNIX, &SOCK_STREAM, 0)) { 
    print "socket ok\n";
}
else {
    die $!;
}

connect (S, $this) || die "connect: $!";

# Avoid deadlock by forking.

select(S); $| = 1; select(STDOUT);

if($child = fork) {
    while (<STDIN>) {
	print S;
    }
    sleep 3;
    do dokill();
}
else {
    while(<S>) {
	print;
    }
}
