xref: /original-bsd/sbin/nfsiod/nfsiod.c (revision 2cb1372a)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char copyright[] =
13 "@(#) Copyright (c) 1989, 1993\n\
14 	The Regents of the University of California.  All rights reserved.\n";
15 #endif not lint
16 
17 #ifndef lint
18 static char sccsid[] = "@(#)nfsiod.c	8.1 (Berkeley) 06/05/93";
19 #endif not lint
20 
21 #include <stdio.h>
22 #include <signal.h>
23 #include <fcntl.h>
24 #include <sys/syslog.h>
25 #include <sys/param.h>
26 #include <sys/ioctl.h>
27 #include <sys/wait.h>
28 #include <sys/ucred.h>
29 #include <nfs/nfsv2.h>
30 #include <nfs/nfs.h>
31 
32 /* Global defs */
33 #ifdef DEBUG
34 int debug = 1;
35 #else
36 int debug = 0;
37 #endif
38 extern int errno;
39 void reapchild();
40 
41 /*
42  * Nfsiod does asynchronous buffered I/O on behalf of the NFS client.
43  * It does not have to be running for correct operation, but will improve
44  * throughput. The one optional argument is the number of children to fork.
45  */
46 main(argc, argv)
47 	int argc;
48 	char *argv[];
49 {
50 	register int i;
51 	int cnt;
52 
53 	if (argc != 2 || (cnt = atoi(argv[1])) <= 0 || cnt > 20)
54 		cnt = 1;
55 	if (debug == 0) {
56 		daemon(0, 0);
57 		signal(SIGINT, SIG_IGN);
58 		signal(SIGQUIT, SIG_IGN);
59 		signal(SIGHUP, SIG_IGN);
60 	}
61 	signal(SIGCHLD, reapchild);
62 	openlog("nfsiod:", LOG_PID, LOG_DAEMON);
63 	for (i = 1; i < cnt; i++)
64 		if (fork() == 0)
65 			break;
66 	if (nfssvc(NFSSVC_BIOD, (char *)0) < 0)
67 		syslog(LOG_ERR, "nfssvc failed %m");
68 }
69 
70 void
71 reapchild()
72 {
73 
74 	while (wait3((int *) NULL, WNOHANG, (struct rusage *) NULL))
75 		;
76 }
77