]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/mountd/svc_run.c
5ba5af6ddc7eb10915b3695f623e4ba6e47ceeca
[nfs-utils.git] / utils / mountd / svc_run.c
1 /*
2  * Copyright (C) 1984 Sun Microsystems, Inc.
3  * Based on svc_run.c from statd which claimed:
4  * Modified by Jeffrey A. Uphoff, 1995, 1997-1999.
5  * Modified by Olaf Kirch, 1996.
6  *
7  */
8
9 /* 
10  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
11  * unrestricted use provided that this legend is included on all tape
12  * media and as a part of the software program in whole or part.  Users
13  * may copy or modify Sun RPC without charge, but are not authorized
14  * to license or distribute it to anyone else except as part of a product or
15  * program developed by the user.
16  * 
17  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
18  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
20  * 
21  * Sun RPC is provided with no support and without any obligation on the
22  * part of Sun Microsystems, Inc. to assist in its use, correction,
23  * modification or enhancement.
24  * 
25  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
26  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
27  * OR ANY PART THEREOF.
28  * 
29  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
30  * or profits or other special, indirect and consequential damages, even if
31  * Sun has been advised of the possibility of such damages.
32  * 
33  * Sun Microsystems, Inc.
34  * 2550 Garcia Avenue
35  * Mountain View, California  94043
36  */
37
38 /* 
39  * Allow svc_run to listen to other file descriptors as well
40  */
41
42 /* 
43  * This is the RPC server side idle loop.
44  * Wait for input, call server program.
45  */
46
47 #ifdef HAVE_CONFIG_H
48 #include <config.h>
49 #endif
50
51 #include <sys/types.h>
52 #include <rpc/rpc.h>
53 #include "xlog.h"
54 #include <errno.h>
55 #include <time.h>
56
57 #ifdef HAVE_LIBTIRPC
58 #include <rpc/rpc_com.h>
59 #endif
60
61 void cache_set_fds(fd_set *fdset);
62 int cache_process_req(fd_set *readfds);
63
64 #if LONG_MAX != INT_MAX 
65 /* bug in glibc 2.3.6 and earlier, we need
66  * our own svc_getreqset
67  */
68 static void
69 my_svc_getreqset (fd_set *readfds)
70 {
71         fd_mask mask;
72         fd_mask *maskp;
73         int setsize;
74         int sock;
75         int bit;
76
77         setsize = _rpc_dtablesize ();
78         if (setsize > FD_SETSIZE)
79                 setsize = FD_SETSIZE;
80         maskp = readfds->fds_bits;
81         for (sock = 0; sock < setsize; sock += NFDBITS)
82                 for (mask = *maskp++;
83                      (bit = ffsl (mask));
84                      mask ^= (1L << (bit - 1)))
85                         svc_getreq_common (sock + bit - 1);
86 }
87 #define svc_getreqset my_svc_getreqset
88
89 #endif
90
91 /*
92  * The heart of the server.  A crib from libc for the most part...
93  */
94 void
95 my_svc_run(void)
96 {
97         fd_set  readfds;
98         int     selret;
99
100         for (;;) {
101
102                 readfds = svc_fdset;
103                 cache_set_fds(&readfds);
104
105                 selret = select(FD_SETSIZE, &readfds,
106                                 (void *) 0, (void *) 0, (struct timeval *) 0);
107
108
109                 switch (selret) {
110                 case -1:
111                         if (errno == EINTR || errno == ECONNREFUSED
112                          || errno == ENETUNREACH || errno == EHOSTUNREACH)
113                                 continue;
114                         xlog(L_ERROR, "my_svc_run() - select: %m");
115                         return;
116
117                 default:
118                         selret -= cache_process_req(&readfds);
119                         if (selret)
120                                 svc_getreqset(&readfds);
121                 }
122         }
123 }