#!/usr/local/bin/perl -Tw
# lockerd - distributed lock handler for perl IPC::Locker

# RCS Status      : $Id: lockerd,v 1.7 1999/11/16 16:13:12 wsnyder Exp $
# Author          : Wilson Snyder <wsnyder@world.std.com>

################ Introduction ################
#
# This program is Copyright 2000 by Wilson Snyder.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of either the GNU General Public License or the
# Perl Artistic License, with the exception that it cannot be placed
# on a CD-ROM or similar media for commercial distribution without the
# prior approval of the author.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# If you do not have a copy of the GNU General Public License write to
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
# MA 02139, USA.
######################################################################

require 5.004;
use lib './blib/lib';	# testing
use English;
use Getopt::Long;
use Pod::Text;
use IPC::Locker::Server;

BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }	# Secure path

######################################################################
# configuration

######################################################################
# globals

######################################################################
# main

my $Debug = 0;
my %server_params = ();

$result = &GetOptions (
		       "help"		=> \&usage,
		       "debug"		=> \&debug,
		       "version"	=> \&version,
		       "port=i"		=> sub {$server_params{port} = shift;}
		       );

if (!$result) { &usage(); }

# Loop in case something kills us
while (1) {
    print "Starting server\n" if $Debug;
    unless ($pid = fork) {
        IPC::Locker::Server->start_server (%server_params);
	exit(0);
    }
    waitpid($pid,0);
    warn "%Warning: Server aborted\n" if $Debug;
    sleep(1);
    kill 9, $pid;
    sleep(1);
}

exit (0);

######################################################################

sub usage {
    print '$Id: lockerd,v 1.7 1999/11/16 16:13:12 wsnyder Exp $ ', "\n";
    $SIG{__WARN__} = sub{};	#pod2text isn't clean.
    pod2text($0);
    exit(1);
}

sub version {
    print 'Version: $Id: lockerd,v 1.7 1999/11/16 16:13:12 wsnyder Exp $ ';
    print "\n";
    exit (1);
}

sub debug {
    $Debug = 1;
    $IPC::Locker::Server::Debug = 1;
}

######################################################################
__END__

=pod

=head1 NAME

lockerd - Distributed lock handler for perl IPC::Locker

=head1 SYNOPSIS

B<lockerd>
[ B<--help> ]
[ B<--port=>I<port> ]
[ B<--version> ]

=head1 DESCRIPTION

Lockerd will start a deamon to watch for and service connects by the perl
IPC::Locker package.

=head1 ARGUMENTS

=over 4

=item --help
Displays this message and program version and exits.

=item --port
Specifies the port number to be used.

=item --version
Displays program version and exits.

=back

=head1 AUTHORS

Wilson Snyder <wsnyder@world.std.com>

=cut
######################################################################
