/*
 * 5799-WZQ (C) COPYRIGHT = NONE
 * LICENSED MATERIALS - PROPERTY OF IBM
 */
/* $Header:biod.c 12.0$ */
/* $ACIS:biod.c 12.0$ */
/* $Source: /ibm/acis/usr/src/nfs/etc/RCS/biod.c,v $ */

#ifndef lint
static char *rcsid = "$Header:biod.c 12.0$";
#endif

#include <sys/nfs_defines.h>

/* @(#)boid.c	1.1 87/09/21 3.2/4.3NFSSRC */
#ifndef lint
static	char sccsid[] = "@(#)boid.c 1.1 86/09/24 Copyr 1983 Sun Mircro";
/* static  char sccsid[] = "@(#)biod.c 1.1 85/05/30 Copyr 1983 Sun Micro"; */
#endif

#include <stdio.h>
#include <sys/file.h>
#include <sys/ioctl.h>

/*
 * This is the NFS asynchronous block I/O daemon
 */

main(argc, argv)
	int argc;
	char *argv[];
{
	extern int errno;
	int pid;
	int count;

	if (argc > 2) {
		usage(argv[0]);
	}

	if (argc == 2) {
		count = atoi(argv[1]);
		if (count < 0) {
			usage(argv[0]);
		}
	} else {
		count = 1;
	}

	{ int tt = open("/dev/tty", O_RDWR);
		if (tt > 0) {
			ioctl(tt, TIOCNOTTY, 0);
			close(tt);
		}
	}
	while (count--) {
		pid = fork();
		if (pid == 0) {
			async_daemon();		/* Should never return */
			fprintf(stderr, "%s: async_daemon ", argv[0]);
			perror("");
			exit(1);
		}
		if (pid < 0) {
			fprintf(stderr, "%s: cannot fork", argv[0]);
			perror("");
			exit(1);
		}
	}
}

usage(name)
	char	*name;
{

	fprintf(stderr, "usage: %s [<count>]\n", name);
	exit(1);
}
