xref: /csrg-svn/sbin/nfsiod/nfsiod.c (revision 61527)
138870Smckusick /*
2*61527Sbostic  * Copyright (c) 1989, 1993
3*61527Sbostic  *	The Regents of the University of California.  All rights reserved.
438870Smckusick  *
538870Smckusick  * This code is derived from software contributed to Berkeley by
638870Smckusick  * Rick Macklem at The University of Guelph.
738870Smckusick  *
842705Sbostic  * %sccs.include.redist.c%
938870Smckusick  */
1038870Smckusick 
1138870Smckusick #ifndef lint
12*61527Sbostic static char copyright[] =
13*61527Sbostic "@(#) Copyright (c) 1989, 1993\n\
14*61527Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1538870Smckusick #endif not lint
1638870Smckusick 
1738870Smckusick #ifndef lint
18*61527Sbostic static char sccsid[] = "@(#)nfsiod.c	8.1 (Berkeley) 06/05/93";
1938870Smckusick #endif not lint
2038870Smckusick 
2138870Smckusick #include <stdio.h>
2238870Smckusick #include <signal.h>
2338870Smckusick #include <fcntl.h>
2452511Smckusick #include <sys/syslog.h>
2552511Smckusick #include <sys/param.h>
2638870Smckusick #include <sys/ioctl.h>
2752511Smckusick #include <sys/wait.h>
2852511Smckusick #include <sys/ucred.h>
2952511Smckusick #include <nfs/nfsv2.h>
3052511Smckusick #include <nfs/nfs.h>
3138870Smckusick 
3238870Smckusick /* Global defs */
3338870Smckusick #ifdef DEBUG
3438870Smckusick int debug = 1;
3538870Smckusick #else
3638870Smckusick int debug = 0;
3738870Smckusick #endif
3852511Smckusick extern int errno;
3952511Smckusick void reapchild();
4038870Smckusick 
4138870Smckusick /*
4239865Smckusick  * Nfsiod does asynchronous buffered I/O on behalf of the NFS client.
4339865Smckusick  * It does not have to be running for correct operation, but will improve
4439865Smckusick  * throughput. The one optional argument is the number of children to fork.
4538870Smckusick  */
4638870Smckusick main(argc, argv)
4738870Smckusick 	int argc;
4838870Smckusick 	char *argv[];
4938870Smckusick {
5038870Smckusick 	register int i;
5138870Smckusick 	int cnt;
5238870Smckusick 
5352511Smckusick 	if (argc != 2 || (cnt = atoi(argv[1])) <= 0 || cnt > 20)
5452511Smckusick 		cnt = 1;
5538870Smckusick 	if (debug == 0) {
5644694Skarels 		daemon(0, 0);
5738870Smckusick 		signal(SIGINT, SIG_IGN);
5838870Smckusick 		signal(SIGQUIT, SIG_IGN);
5938870Smckusick 		signal(SIGHUP, SIG_IGN);
6038870Smckusick 	}
6152511Smckusick 	signal(SIGCHLD, reapchild);
6252511Smckusick 	openlog("nfsiod:", LOG_PID, LOG_DAEMON);
6338870Smckusick 	for (i = 1; i < cnt; i++)
6438870Smckusick 		if (fork() == 0)
6538870Smckusick 			break;
6652511Smckusick 	if (nfssvc(NFSSVC_BIOD, (char *)0) < 0)
6752511Smckusick 		syslog(LOG_ERR, "nfssvc failed %m");
6838870Smckusick }
6952511Smckusick 
7052511Smckusick void
7152511Smckusick reapchild()
7252511Smckusick {
7352511Smckusick 
7452511Smckusick 	while (wait3((int *) NULL, WNOHANG, (struct rusage *) NULL))
7552511Smckusick 		;
7652511Smckusick }
77