/*======================================================================
                    I N E T R A Y . P I N G . C 
                    doc: Thu Mar  5 12:55:31 1992
                    dlm: Thu Jul 22 15:30:41 1993
                    (c) 1992 ant@julia
                    uE-Info: 57 50 T 0 0 72 2 2 8 ofnI
======================================================================*/

#include	<stdio.h>
#include	<signal.h>
#include	<ctype.h>
#include	<sys/param.h>
#include	<rpc/rpc.h>
#include	"inetray.h"
#include	"config.h"
#include	"common.h"
#include	"comm.h"
#include	"version.h"
#include	"patchlevel.h"

int 	key = 0;			/* dummy key */

static void cleanUp()			/* clean up self */
{
	int 	i;

	for (i=SIGHUP; i<=SIGQUIT; i++)
		signal(i,SIG_IGN);
	fprintf(stderr,"Exiting... [terminate"); 
	terminateAll();
	fprintf(stderr,", close");
	closeAll();
	fprintf(stderr,"]\n");
	exit(0);
}

main(ac,av)
int ac; char *av[];
{
	int 	i;
	char	hName[MAXHOSTNAMELEN],cwd[MAXPATHLEN];
	char	*getcwd();

	if (gethostname(hName,MAXHOSTNAMELEN) < 0) {
		perror("gethostname");
		exit(1);
	}
	
	for (i=SIGHUP; i<=SIGQUIT; i++)
		signal(i,cleanUp);
	fprintf(stderr,"%s [%s%d]\n",av[0],VERSION,PATCHLEVEL);

	if (ac == 1) readRc();
	else addUseList(ac,av);
		
        fprintf(stderr,"Pinging... ["); 
        registerSvc(hName,"",getcwd(cwd,MAXPATHLEN),FALSE);
        if (nRunning == 0) fprintf(stderr,"\n[Warning: ");
        else	           fprintf(stderr,"\n[");
	fprintf(stderr,"%d workers answered]\n",nRunning);
	cleanUp();
}
