2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static const char copyright[] =
39 "@(#) Copyright (c) 1989, 1993, 1994\n\
40 The Regents of the University of California. All rights reserved.\n";
45 static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95";
47 static const char rcsid[] =
51 #include <sys/param.h>
52 #include <sys/syslog.h>
54 #include <sys/mount.h>
55 #include <sys/linker.h>
56 #include <sys/module.h>
59 #include <rpc/pmap_clnt.h>
62 #include <arpa/inet.h>
63 #include <nfs/rpcv2.h>
64 #include <nfs/nfsproto.h>
65 #include <nfsserver/nfs.h>
78 #define syslog(e, s...) fprintf(stderr,s)
86 pid_t children[MAXNFSDCNT]; /* PIDs of children */
87 int nfsdcnt; /* number of children */
90 void child_cleanup(int);
91 void killchildren(void);
95 int setbindhost(struct addrinfo **ia, const char *bindhost,
96 struct addrinfo hints);
97 void start_server(int);
98 void unregistration(void);
102 * Nfs server daemon mostly just a user context for nfssvc()
104 * 1 - do file descriptor and signal cleanup
105 * 2 - fork the nfsd(s)
106 * 3 - create server socket(s)
107 * 4 - register socket with rpcbind
109 * For connectionless protocols, just pass the socket into the kernel via.
111 * For connection based sockets, loop doing accepts. When you get a new
112 * socket from accept, pass the msgsock into the kernel via. nfssvc().
114 * -r - reregister with rpcbind
115 * -d - unregister with rpcbind
116 * -t - support tcp nfs clients
117 * -u - support udp nfs clients
118 * followed by "n" which is the number of nfsds' to fork off
121 main(argc, argv, envp)
123 char *argv[], *envp[];
125 struct nfsd_args nfsdargs;
126 struct addrinfo *ai_udp, *ai_tcp, *ai_udp6, *ai_tcp6, hints;
127 struct netconfig *nconf_udp, *nconf_tcp, *nconf_udp6, *nconf_tcp6;
128 struct netbuf nb_udp, nb_tcp, nb_udp6, nb_tcp6;
129 struct sockaddr_in inetpeer;
130 struct sockaddr_in6 inet6peer;
131 fd_set ready, sockbits;
132 fd_set v4bits, v6bits;
133 int ch, connect_type_cnt, i, len, maxsock, msgsock;
134 int on = 1, unregister, reregister, sock;
135 int tcp6sock, ip6flag, tcpflag, tcpsock;
136 int udpflag, ecode, s, srvcnt;
137 int bindhostc, bindanyflag, rpcbreg, rpcbregcnt;
138 char **bindhost = NULL;
141 if (modfind("nfsserver") < 0) {
142 /* Not present in kernel, try loading it */
143 if (kldload("nfsserver") < 0 || modfind("nfsserver") < 0)
144 errx(1, "NFS server is not available");
147 nfsdcnt = DEFNFSDCNT;
148 unregister = reregister = tcpflag = maxsock = 0;
149 bindanyflag = udpflag = connect_type_cnt = bindhostc = 0;
150 #define GETOPT "ah:n:rdtu"
151 #define USAGE "[-ardtu] [-n num_servers] [-h bindip]"
152 while ((ch = getopt(argc, argv, GETOPT)) != -1)
158 nfsdcnt = atoi(optarg);
159 if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
160 warnx("nfsd count %d; reset to %d", nfsdcnt,
162 nfsdcnt = DEFNFSDCNT;
167 bindhost = realloc(bindhost,sizeof(char *)*bindhostc);
168 if (bindhost == NULL)
169 errx(1, "Out of memory");
170 bindhost[bindhostc-1] = strdup(optarg);
171 if (bindhost[bindhostc-1] == NULL)
172 errx(1, "Out of memory");
190 if (!tcpflag && !udpflag)
197 * Backward compatibility, trailing number is the count of daemons.
202 nfsdcnt = atoi(argv[0]);
203 if (nfsdcnt < 1 || nfsdcnt > MAXNFSDCNT) {
204 warnx("nfsd count %d; reset to %d", nfsdcnt,
206 nfsdcnt = DEFNFSDCNT;
211 s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
213 if (errno != EPROTONOSUPPORT)
216 } else if (getnetconfigent("udp6") == NULL ||
217 getnetconfigent("tcp6") == NULL) {
223 if (bindhostc == 0 || bindanyflag) {
225 bindhost = realloc(bindhost,sizeof(char *)*bindhostc);
226 if (bindhost == NULL)
227 errx(1, "Out of memory");
228 bindhost[bindhostc-1] = strdup("*");
229 if (bindhost[bindhostc-1] == NULL)
230 errx(1, "Out of memory");
239 memset(&hints, 0, sizeof hints);
240 hints.ai_flags = AI_PASSIVE;
241 hints.ai_family = AF_INET;
242 hints.ai_socktype = SOCK_DGRAM;
243 hints.ai_protocol = IPPROTO_UDP;
244 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp);
246 err(1, "getaddrinfo udp: %s", gai_strerror(ecode));
247 nconf_udp = getnetconfigent("udp");
248 if (nconf_udp == NULL)
249 err(1, "getnetconfigent udp failed");
250 nb_udp.buf = ai_udp->ai_addr;
251 nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
252 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp)) ||
253 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp, &nb_udp)))
254 err(1, "rpcb_set udp failed");
255 freeaddrinfo(ai_udp);
257 if (udpflag && ip6flag) {
258 memset(&hints, 0, sizeof hints);
259 hints.ai_flags = AI_PASSIVE;
260 hints.ai_family = AF_INET6;
261 hints.ai_socktype = SOCK_DGRAM;
262 hints.ai_protocol = IPPROTO_UDP;
263 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp6);
265 err(1, "getaddrinfo udp6: %s", gai_strerror(ecode));
266 nconf_udp6 = getnetconfigent("udp6");
267 if (nconf_udp6 == NULL)
268 err(1, "getnetconfigent udp6 failed");
269 nb_udp6.buf = ai_udp6->ai_addr;
270 nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
271 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6)) ||
272 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp6, &nb_udp6)))
273 err(1, "rpcb_set udp6 failed");
274 freeaddrinfo(ai_udp6);
277 memset(&hints, 0, sizeof hints);
278 hints.ai_flags = AI_PASSIVE;
279 hints.ai_family = AF_INET;
280 hints.ai_socktype = SOCK_STREAM;
281 hints.ai_protocol = IPPROTO_TCP;
282 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp);
284 err(1, "getaddrinfo tcp: %s", gai_strerror(ecode));
285 nconf_tcp = getnetconfigent("tcp");
286 if (nconf_tcp == NULL)
287 err(1, "getnetconfigent tcp failed");
288 nb_tcp.buf = ai_tcp->ai_addr;
289 nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
290 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp, &nb_tcp)) ||
291 (!rpcb_set(RPCPROG_NFS, 3, nconf_tcp, &nb_tcp)))
292 err(1, "rpcb_set tcp failed");
293 freeaddrinfo(ai_tcp);
295 if (tcpflag && ip6flag) {
296 memset(&hints, 0, sizeof hints);
297 hints.ai_flags = AI_PASSIVE;
298 hints.ai_family = AF_INET6;
299 hints.ai_socktype = SOCK_STREAM;
300 hints.ai_protocol = IPPROTO_TCP;
301 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp6);
303 err(1, "getaddrinfo tcp6: %s", gai_strerror(ecode));
304 nconf_tcp6 = getnetconfigent("tcp6");
305 if (nconf_tcp6 == NULL)
306 err(1, "getnetconfigent tcp6 failed");
307 nb_tcp6.buf = ai_tcp6->ai_addr;
308 nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
309 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6)) ||
310 (!rpcb_set(RPCPROG_NFS, 3, nconf_tcp6, &nb_tcp6)))
311 err(1, "rpcb_set tcp6 failed");
312 freeaddrinfo(ai_tcp6);
318 (void)signal(SIGHUP, SIG_IGN);
319 (void)signal(SIGINT, SIG_IGN);
321 * nfsd sits in the kernel most of the time. It needs
322 * to ignore SIGTERM/SIGQUIT in order to stay alive as long
323 * as possible during a shutdown, otherwise loopback
324 * mounts will not be able to unmount.
326 (void)signal(SIGTERM, SIG_IGN);
327 (void)signal(SIGQUIT, SIG_IGN);
329 (void)signal(SIGSYS, nonfs);
330 (void)signal(SIGCHLD, reapchild);
332 openlog("nfsd", LOG_PID, LOG_DAEMON);
334 /* If we use UDP only, we start the last server below. */
335 srvcnt = tcpflag ? nfsdcnt : nfsdcnt - 1;
336 for (i = 0; i < srvcnt; i++) {
337 switch ((pid = fork())) {
339 syslog(LOG_ERR, "fork: %m");
347 (void)signal(SIGUSR1, child_cleanup);
348 setproctitle("server");
353 (void)signal(SIGUSR1, cleanup);
359 /* Set up the socket for udp and rpcb register it. */
362 for (i = 0; i < bindhostc; i++) {
363 memset(&hints, 0, sizeof hints);
364 hints.ai_flags = AI_PASSIVE;
365 hints.ai_family = AF_INET;
366 hints.ai_socktype = SOCK_DGRAM;
367 hints.ai_protocol = IPPROTO_UDP;
368 if (setbindhost(&ai_udp, bindhost[i], hints) == 0) {
371 if ((sock = socket(ai_udp->ai_family,
373 ai_udp->ai_protocol)) < 0) {
375 "can't create udp socket");
378 if (bind(sock, ai_udp->ai_addr,
379 ai_udp->ai_addrlen) < 0) {
381 "can't bind udp addr %s: %m",
385 freeaddrinfo(ai_udp);
386 nfsdargs.sock = sock;
387 nfsdargs.name = NULL;
388 nfsdargs.namelen = 0;
389 if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
390 syslog(LOG_ERR, "can't Add UDP socket");
397 memset(&hints, 0, sizeof hints);
398 hints.ai_flags = AI_PASSIVE;
399 hints.ai_family = AF_INET;
400 hints.ai_socktype = SOCK_DGRAM;
401 hints.ai_protocol = IPPROTO_UDP;
402 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp);
404 syslog(LOG_ERR, "getaddrinfo udp: %s",
405 gai_strerror(ecode));
408 nconf_udp = getnetconfigent("udp");
409 if (nconf_udp == NULL)
410 err(1, "getnetconfigent udp failed");
411 nb_udp.buf = ai_udp->ai_addr;
412 nb_udp.len = nb_udp.maxlen = ai_udp->ai_addrlen;
413 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp, &nb_udp)) ||
414 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp, &nb_udp)))
415 err(1, "rpcb_set udp failed");
416 freeaddrinfo(ai_udp);
420 /* Set up the socket for udp6 and rpcb register it. */
421 if (udpflag && ip6flag) {
423 for (i = 0; i < bindhostc; i++) {
424 memset(&hints, 0, sizeof hints);
425 hints.ai_flags = AI_PASSIVE;
426 hints.ai_family = AF_INET6;
427 hints.ai_socktype = SOCK_DGRAM;
428 hints.ai_protocol = IPPROTO_UDP;
429 if (setbindhost(&ai_udp6, bindhost[i], hints) == 0) {
432 if ((sock = socket(ai_udp6->ai_family,
433 ai_udp6->ai_socktype,
434 ai_udp6->ai_protocol)) < 0) {
436 "can't create udp6 socket");
439 if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
440 &on, sizeof on) < 0) {
442 "can't set v6-only binding for "
446 if (bind(sock, ai_udp6->ai_addr,
447 ai_udp6->ai_addrlen) < 0) {
449 "can't bind udp6 addr %s: %m",
453 freeaddrinfo(ai_udp6);
454 nfsdargs.sock = sock;
455 nfsdargs.name = NULL;
456 nfsdargs.namelen = 0;
457 if (nfssvc(NFSSVC_ADDSOCK, &nfsdargs) < 0) {
459 "can't add UDP6 socket");
466 memset(&hints, 0, sizeof hints);
467 hints.ai_flags = AI_PASSIVE;
468 hints.ai_family = AF_INET6;
469 hints.ai_socktype = SOCK_DGRAM;
470 hints.ai_protocol = IPPROTO_UDP;
471 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_udp6);
473 syslog(LOG_ERR, "getaddrinfo udp6: %s",
474 gai_strerror(ecode));
477 nconf_udp6 = getnetconfigent("udp6");
478 if (nconf_udp6 == NULL)
479 err(1, "getnetconfigent udp6 failed");
480 nb_udp6.buf = ai_udp6->ai_addr;
481 nb_udp6.len = nb_udp6.maxlen = ai_udp6->ai_addrlen;
482 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_udp6, &nb_udp6)) ||
483 (!rpcb_set(RPCPROG_NFS, 3, nconf_udp6, &nb_udp6)))
484 err(1, "rpcb_set udp6 failed");
485 freeaddrinfo(ai_udp6);
489 /* Set up the socket for tcp and rpcb register it. */
492 for (i = 0; i < bindhostc; i++) {
493 memset(&hints, 0, sizeof hints);
494 hints.ai_flags = AI_PASSIVE;
495 hints.ai_family = AF_INET;
496 hints.ai_socktype = SOCK_STREAM;
497 hints.ai_protocol = IPPROTO_TCP;
498 if (setbindhost(&ai_tcp, bindhost[i], hints) == 0) {
501 if ((tcpsock = socket(AF_INET, SOCK_STREAM,
504 "can't create tpc socket");
507 if (setsockopt(tcpsock, SOL_SOCKET,
509 (char *)&on, sizeof(on)) < 0)
511 "setsockopt SO_REUSEADDR: %m");
512 if (bind(tcpsock, ai_tcp->ai_addr,
513 ai_tcp->ai_addrlen) < 0) {
515 "can't bind tcp addr %s: %m",
519 if (listen(tcpsock, 5) < 0) {
520 syslog(LOG_ERR, "listen failed");
523 freeaddrinfo(ai_tcp);
524 FD_SET(tcpsock, &sockbits);
525 FD_SET(tcpsock, &v4bits);
531 memset(&hints, 0, sizeof hints);
532 hints.ai_flags = AI_PASSIVE;
533 hints.ai_family = AF_INET;
534 hints.ai_socktype = SOCK_STREAM;
535 hints.ai_protocol = IPPROTO_TCP;
536 ecode = getaddrinfo(NULL, "nfs", &hints,
539 syslog(LOG_ERR, "getaddrinfo tcp: %s",
540 gai_strerror(ecode));
543 nconf_tcp = getnetconfigent("tcp");
544 if (nconf_tcp == NULL)
545 err(1, "getnetconfigent tcp failed");
546 nb_tcp.buf = ai_tcp->ai_addr;
547 nb_tcp.len = nb_tcp.maxlen = ai_tcp->ai_addrlen;
548 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp,
549 &nb_tcp)) || (!rpcb_set(RPCPROG_NFS, 3,
550 nconf_tcp, &nb_tcp)))
551 err(1, "rpcb_set tcp failed");
552 freeaddrinfo(ai_tcp);
556 /* Set up the socket for tcp6 and rpcb register it. */
557 if (tcpflag && ip6flag) {
559 for (i = 0; i < bindhostc; i++) {
560 memset(&hints, 0, sizeof hints);
561 hints.ai_flags = AI_PASSIVE;
562 hints.ai_family = AF_INET6;
563 hints.ai_socktype = SOCK_STREAM;
564 hints.ai_protocol = IPPROTO_TCP;
565 if (setbindhost(&ai_tcp6, bindhost[i], hints) == 0) {
568 if ((tcp6sock = socket(ai_tcp6->ai_family,
569 ai_tcp6->ai_socktype,
570 ai_tcp6->ai_protocol)) < 0) {
572 "can't create tcp6 socket");
575 if (setsockopt(tcp6sock, SOL_SOCKET,
577 (char *)&on, sizeof(on)) < 0)
579 "setsockopt SO_REUSEADDR: %m");
580 if (setsockopt(tcp6sock, IPPROTO_IPV6,
581 IPV6_V6ONLY, &on, sizeof on) < 0) {
583 "can't set v6-only binding for tcp6 "
587 if (bind(tcp6sock, ai_tcp6->ai_addr,
588 ai_tcp6->ai_addrlen) < 0) {
590 "can't bind tcp6 addr %s: %m",
594 if (listen(tcp6sock, 5) < 0) {
595 syslog(LOG_ERR, "listen failed");
598 freeaddrinfo(ai_tcp6);
599 FD_SET(tcp6sock, &sockbits);
600 FD_SET(tcp6sock, &v6bits);
601 if (maxsock < tcp6sock)
607 memset(&hints, 0, sizeof hints);
608 hints.ai_flags = AI_PASSIVE;
609 hints.ai_family = AF_INET6;
610 hints.ai_socktype = SOCK_STREAM;
611 hints.ai_protocol = IPPROTO_TCP;
612 ecode = getaddrinfo(NULL, "nfs", &hints, &ai_tcp6);
614 syslog(LOG_ERR, "getaddrinfo tcp6: %s",
615 gai_strerror(ecode));
618 nconf_tcp6 = getnetconfigent("tcp6");
619 if (nconf_tcp6 == NULL)
620 err(1, "getnetconfigent tcp6 failed");
621 nb_tcp6.buf = ai_tcp6->ai_addr;
622 nb_tcp6.len = nb_tcp6.maxlen = ai_tcp6->ai_addrlen;
623 if ((!rpcb_set(RPCPROG_NFS, 2, nconf_tcp6, &nb_tcp6)) ||
624 (!rpcb_set(RPCPROG_NFS, 3, nconf_tcp6, &nb_tcp6)))
625 err(1, "rpcb_set tcp6 failed");
626 freeaddrinfo(ai_tcp6);
630 if (rpcbregcnt == 0) {
631 syslog(LOG_ERR, "rpcb_set() failed, nothing to do: %m");
635 if (tcpflag && connect_type_cnt == 0) {
636 syslog(LOG_ERR, "tcp connects == 0, nothing to do: %m");
640 setproctitle("master");
642 * We always want a master to have a clean way to to shut nfsd down
643 * (with unregistration): if the master is killed, it unregisters and
644 * kills all children. If we run for UDP only (and so do not have to
645 * loop waiting waiting for accept), we instead make the parent
646 * a "server" too. start_server will not return.
652 * Loop forever accepting connections and passing the sockets
653 * into the kernel for the mounts.
657 if (connect_type_cnt > 1) {
658 if (select(maxsock + 1,
659 &ready, NULL, NULL, NULL) < 1) {
660 syslog(LOG_ERR, "select failed: %m");
666 for (tcpsock = 0; tcpsock <= maxsock; tcpsock++) {
667 if (FD_ISSET(tcpsock, &ready)) {
668 if (FD_ISSET(tcpsock, &v4bits)) {
669 len = sizeof(inetpeer);
670 if ((msgsock = accept(tcpsock,
671 (struct sockaddr *)&inetpeer, &len)) < 0) {
672 syslog(LOG_ERR, "accept failed: %m");
673 if (errno == ECONNABORTED ||
678 memset(inetpeer.sin_zero, 0,
679 sizeof(inetpeer.sin_zero));
680 if (setsockopt(msgsock, SOL_SOCKET,
681 SO_KEEPALIVE, (char *)&on, sizeof(on)) < 0)
683 "setsockopt SO_KEEPALIVE: %m");
684 nfsdargs.sock = msgsock;
685 nfsdargs.name = (caddr_t)&inetpeer;
686 nfsdargs.namelen = len;
687 nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
688 (void)close(msgsock);
689 } else if (FD_ISSET(tcpsock, &v6bits)) {
690 len = sizeof(inet6peer);
691 if ((msgsock = accept(tcpsock,
692 (struct sockaddr *)&inet6peer,
695 "accept failed: %m");
696 if (errno == ECONNABORTED ||
701 if (setsockopt(msgsock, SOL_SOCKET,
702 SO_KEEPALIVE, (char *)&on,
704 syslog(LOG_ERR, "setsockopt "
706 nfsdargs.sock = msgsock;
707 nfsdargs.name = (caddr_t)&inet6peer;
708 nfsdargs.namelen = len;
709 nfssvc(NFSSVC_ADDSOCK, &nfsdargs);
710 (void)close(msgsock);
718 setbindhost(struct addrinfo **ai, const char *bindhost, struct addrinfo hints)
721 u_int32_t host_addr[4]; /* IPv4 or IPv6 */
724 if (bindhost == NULL || strcmp("*", bindhost) == 0)
729 if (hostptr != NULL) {
730 switch (hints.ai_family) {
732 if (inet_pton(AF_INET, hostptr, host_addr) == 1) {
733 hints.ai_flags = AI_NUMERICHOST;
735 if (inet_pton(AF_INET6, hostptr,
741 if (inet_pton(AF_INET6, hostptr, host_addr) == 1) {
742 hints.ai_flags = AI_NUMERICHOST;
744 if (inet_pton(AF_INET, hostptr,
754 ecode = getaddrinfo(hostptr, "nfs", &hints, ai);
756 syslog(LOG_ERR, "getaddrinfo %s: %s", bindhost,
757 gai_strerror(ecode));
766 (void)fprintf(stderr, "usage: nfsd %s\n", USAGE);
774 syslog(LOG_ERR, "missing system call: NFS not available");
784 while ((pid = wait3(NULL, WNOHANG, NULL)) > 0) {
785 for (i = 0; i < nfsdcnt; i++)
786 if (pid == children[i])
794 if ((!rpcb_unset(RPCPROG_NFS, 2, NULL)) ||
795 (!rpcb_unset(RPCPROG_NFS, 3, NULL)))
796 syslog(LOG_ERR, "rpcb_unset failed");
804 for (i = 0; i < nfsdcnt; i++) {
806 kill(children[i], SIGKILL);
811 * Cleanup master after SIGUSR1.
820 * Cleanup child after SIGUSR1.
829 nfsd_exit(int status)
837 start_server(int master)
842 if (nfssvc(NFSSVC_NFSD, NULL) < 0) {
843 syslog(LOG_ERR, "nfssvc: %m");