#!/usr/bin/env perl
# Serve a tcpmux client the contents of a local file -- ksb
# call from tcpmux as:	/path/to/this argv0 [/path/to/file] [reply_header]
# By defalt we send mmsrc's auto.cf file, which is mostly useful.
# $Id: publish.pl,v 1.1 2011/12/22 16:03:44 ksb Exp $
use strict;
use Socket;
use IO::Handle;

my($progname) = $0 || 'publish';
my($list) = shift(@ARGV) || '/usr/local/lib/hxmd/auto.cf';
my($oo) = shift(@ARGV);

STDOUT->autoflush(1);

unless (open DATA, "<$list") {
	print STDOUT "-$list: $!\r\n";
	exit(0);
}

if (defined($oo)) {
	print STDOUT "+$oo\r\n";
} else {
	print STDOUT "+$list\r\n";
}
local $SIG{ALRM} = sub {
	exit 1;
};
shutdown(STDOUT, 0);
alarm(180);
my $data;
while ($data = <DATA>) {
	print STDOUT $data;
	alarm(60);
}
close(STDOUT);
exit 0;
