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