xref: /csrg-svn/sbin/nfsiod/nfsiod.c (revision 38870)
1*38870Smckusick /*
2*38870Smckusick  * Copyright (c) 1989 The Regents of the University of California.
3*38870Smckusick  * All rights reserved.
4*38870Smckusick  *
5*38870Smckusick  * This code is derived from software contributed to Berkeley by
6*38870Smckusick  * Rick Macklem at The University of Guelph.
7*38870Smckusick  *
8*38870Smckusick  * Redistribution and use in source and binary forms are permitted
9*38870Smckusick  * provided that the above copyright notice and this paragraph are
10*38870Smckusick  * duplicated in all such forms and that any documentation,
11*38870Smckusick  * advertising materials, and other materials related to such
12*38870Smckusick  * distribution and use acknowledge that the software was developed
13*38870Smckusick  * by the University of California, Berkeley.  The name of the
14*38870Smckusick  * University may not be used to endorse or promote products derived
15*38870Smckusick  * from this software without specific prior written permission.
16*38870Smckusick  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17*38870Smckusick  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18*38870Smckusick  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19*38870Smckusick  */
20*38870Smckusick 
21*38870Smckusick #ifndef lint
22*38870Smckusick char copyright[] =
23*38870Smckusick "@(#) Copyright (c) 1989 Regents of the University of California.\n\
24*38870Smckusick  All rights reserved.\n";
25*38870Smckusick #endif not lint
26*38870Smckusick 
27*38870Smckusick #ifndef lint
28*38870Smckusick static char sccsid[] = "@(#)nfsiod.c	5.1 (Berkeley) 08/30/89";
29*38870Smckusick #endif not lint
30*38870Smckusick 
31*38870Smckusick #include <stdio.h>
32*38870Smckusick #include <syslog.h>
33*38870Smckusick #include <signal.h>
34*38870Smckusick #include <fcntl.h>
35*38870Smckusick #include <sys/types.h>
36*38870Smckusick #include <sys/ioctl.h>
37*38870Smckusick 
38*38870Smckusick /* Global defs */
39*38870Smckusick #ifdef DEBUG
40*38870Smckusick #define	syslog(e, s)	fprintf(stderr,(s))
41*38870Smckusick int debug = 1;
42*38870Smckusick #else
43*38870Smckusick int debug = 0;
44*38870Smckusick #endif
45*38870Smckusick 
46*38870Smckusick /*
47*38870Smckusick  * Nfs asynchronous i/o daemon. Just helps out client i/o with read aheads
48*38870Smckusick  */
49*38870Smckusick main(argc, argv)
50*38870Smckusick 	int argc;
51*38870Smckusick 	char *argv[];
52*38870Smckusick {
53*38870Smckusick 	register int i;
54*38870Smckusick 	int cnt;
55*38870Smckusick 
56*38870Smckusick 	if (debug == 0) {
57*38870Smckusick 		if (fork())
58*38870Smckusick 			exit(0);
59*38870Smckusick 		{ int s;
60*38870Smckusick 		for (s = 0; s < 10; s++)
61*38870Smckusick 			(void) close(s);
62*38870Smckusick 		}
63*38870Smckusick 		(void) open("/", O_RDONLY);
64*38870Smckusick 		(void) dup2(0, 1);
65*38870Smckusick 		(void) dup2(0, 2);
66*38870Smckusick 		{ int tt = open("/dev/tty", O_RDWR);
67*38870Smckusick 		  if (tt > 0) {
68*38870Smckusick 			ioctl(tt, TIOCNOTTY, (char *)0);
69*38870Smckusick 			close(tt);
70*38870Smckusick 		  }
71*38870Smckusick 		}
72*38870Smckusick 		(void) setpgrp(0, 0);
73*38870Smckusick 		signal(SIGTSTP, SIG_IGN);
74*38870Smckusick 		signal(SIGTTIN, SIG_IGN);
75*38870Smckusick 		signal(SIGTTOU, SIG_IGN);
76*38870Smckusick 		signal(SIGINT, SIG_IGN);
77*38870Smckusick 		signal(SIGQUIT, SIG_IGN);
78*38870Smckusick 		signal(SIGTERM, SIG_IGN);
79*38870Smckusick 		signal(SIGHUP, SIG_IGN);
80*38870Smckusick 	}
81*38870Smckusick 	openlog("nfsiod:", LOG_PID, LOG_DAEMON);
82*38870Smckusick 	if (argc != 2 || (cnt = atoi(argv[1])) <= 0 || cnt > 20)
83*38870Smckusick 		cnt = 1;
84*38870Smckusick 	for (i = 1; i < cnt; i++)
85*38870Smckusick 		if (fork() == 0)
86*38870Smckusick 			break;
87*38870Smckusick 	if (async_daemon() < 0)		/* Only returns on error */
88*38870Smckusick 		syslog(LOG_ERR, "nfsiod() failed %m");
89*38870Smckusick 	exit();
90*38870Smckusick }
91