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.4 (Berkeley) 05/03/95"; 19 #endif not lint 20 21 #include <sys/param.h> 22 #include <sys/ioctl.h> 23 #include <sys/syslog.h> 24 #include <sys/ucred.h> 25 #include <sys/wait.h> 26 27 #include <sys/mount.h> 28 #include <sys/time.h> 29 #include <nfs/rpcv2.h> 30 #include <nfs/nfsproto.h> 31 #include <nfs/nfs.h> 32 33 #include <err.h> 34 #include <errno.h> 35 #include <fcntl.h> 36 #include <signal.h> 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <unistd.h> 40 41 /* Global defs */ 42 #ifdef DEBUG 43 int debug = 1; 44 #else 45 int debug = 0; 46 #endif 47 48 void nonfs __P((int)); 49 void reapchild __P((int)); 50 void usage __P((void)); 51 52 /* 53 * Nfsiod does asynchronous buffered I/O on behalf of the NFS client. 54 * It does not have to be running for correct operation, but will 55 * improve throughput. 56 */ 57 int 58 main(argc, argv) 59 int argc; 60 char *argv[]; 61 { 62 int ch, num_servers; 63 64 #define MAXNFSDCNT 20 65 #define DEFNFSDCNT 1 66 num_servers = DEFNFSDCNT; 67 while ((ch = getopt(argc, argv, "n:")) != EOF) 68 switch (ch) { 69 case 'n': 70 num_servers = atoi(optarg); 71 if (num_servers < 1 || num_servers > MAXNFSDCNT) { 72 warnx("nfsiod count %d; reset to %d", 73 DEFNFSDCNT); 74 num_servers = DEFNFSDCNT; 75 } 76 break; 77 case '?': 78 default: 79 usage(); 80 } 81 argc -= optind; 82 argv += optind; 83 84 /* 85 * XXX 86 * Backward compatibility, trailing number is the count of daemons. 87 */ 88 if (argc > 1) 89 usage(); 90 if (argc == 1) { 91 num_servers = atoi(argv[0]); 92 if (num_servers < 1 || num_servers > MAXNFSDCNT) { 93 warnx("nfsiod count %d; reset to %d", DEFNFSDCNT); 94 num_servers = DEFNFSDCNT; 95 } 96 } 97 98 if (debug == 0) { 99 daemon(0, 0); 100 (void)signal(SIGHUP, SIG_IGN); 101 (void)signal(SIGINT, SIG_IGN); 102 (void)signal(SIGQUIT, SIG_IGN); 103 (void)signal(SIGSYS, nonfs); 104 } 105 (void)signal(SIGCHLD, reapchild); 106 107 openlog("nfsiod:", LOG_PID, LOG_DAEMON); 108 109 while (num_servers--) 110 switch (fork()) { 111 case -1: 112 syslog(LOG_ERR, "fork: %m"); 113 exit (1); 114 case 0: 115 if (nfssvc(NFSSVC_BIOD, NULL) < 0) { 116 syslog(LOG_ERR, "nfssvc: %m"); 117 exit (1); 118 } 119 exit(0); 120 } 121 exit (0); 122 } 123 124 void 125 nonfs(signo) 126 int signo; 127 { 128 syslog(LOG_ERR, "missing system call: NFS not available."); 129 } 130 131 void 132 reapchild(signo) 133 int signo; 134 { 135 136 while (wait3(NULL, WNOHANG, NULL)); 137 } 138 139 void 140 usage() 141 { 142 (void)fprintf(stderr, "usage: nfsiod [-n num_servers]\n"); 143 exit(1); 144 } 145