예제 #1
0
static int realmode(unsigned nthreads)
{
int	listensock;
struct	cthreadinfo *threads;
struct	dupinfo di;

	listensock=lf_init("filters/dupfilter-mode",
		ALLFILTERSOCKETDIR "/dupfilter",
		ALLFILTERSOCKETDIR "/.dupfilter",
		FILTERSOCKETDIR "/dupfilter",
		FILTERSOCKETDIR "/.dupfilter");

	if (listensock < 0)
		return (1);

	threads=cthread_init(nthreads, sizeof(struct dupinfo),
		(void (*)(void *))&hashclient_wrapper,
		(void (*)(void *))&checkclient);
	if (!threads)
	{
		perror("cthread_init");
		return (1);
	}

	lf_init_completed(listensock);

	for (;;)
	{
		if ((di.fd=lf_accept(listensock)) < 0)	break;

		di.cancelfunc= &realcancel;

		if ( cthread_go(threads,
			(void (*)(void *, void *))&initdupinfo, &di))
		{
			perror("cthread_go");
			break;
		}
	}
	cthread_wait(threads);
	return (0);
}
예제 #2
0
int main(int argc, char **argv, char **env)
{
char	*fn, *f;
int	rc;
char	buffer[1];
int	waitstat;
struct	stat	stat_buf;

	fn=config_localfilename("filters/perlfilter-numprocs");
	if ( (f=config_read1l(fn)) != 0)
	{
		sscanf(f, "%u", &nchildren);
		free(f);
	}
	free(fn);
	if (nchildren <= 0)	nchildren=1;

	fn=config_localfilename("filters/perlfilter");
	if ( (f=config_read1l(fn)) == 0)
	{
		fprintf(stderr, "filters/perlfilter: not defined.\n");
		exit(1);
	}

	filter=f;

	if (stat(filter, &stat_buf))
	{
		perror(filter);
		exit(1);
	}

	listen_sock=lf_init("filters/perlfilter-mode",
		ALLFILTERSOCKETDIR "/perlfilter",
		ALLFILTERSOCKETDIR "/.perlfilter",
		FILTERSOCKETDIR "/perlfilter",
		FILTERSOCKETDIR "/.perlfilter");

	if (listen_sock < 0)
	{
		perror("socket");
		exit(1);
	}

	rc=wait_startchildren(nchildren, &children);

	if (rc < 0)
	{
		perror("fork");
		exit(1);
	}

	if (rc > 0)
	{
		lf_init_completed(listen_sock);
		perlfilter();
	}

	signal(SIGCHLD, reap_children);
	lf_init_completed(listen_sock);

	while (read(0, &buffer, 1) != 0)
	{
		;
	}
	wait_restore();

	/* Wait for all child processes to terminate */

	while (wait(&waitstat) > 0)
		;
	exit(0);
	return (0);
}