]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/svc.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sunrpc / svc.c
CommitLineData
28f540f4
RM
1/*
2 * svc.c, Server-side remote procedure call interface.
3 *
4 * There are two sets of procedures here. The xprt routines are
5 * for handling transport handles. The svc routines handle the
6 * list of service routines.
6d7e8eda 7 * Copyright (C) 2002-2023 Free Software Foundation, Inc.
14bc93a9 8 * This file is part of the GNU C Library.
14bc93a9
JL
9 *
10 * The GNU C Library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * The GNU C Library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with the GNU C Library; if not, see
5a82c748 22 * <https://www.gnu.org/licenses/>.
28f540f4 23 *
a7ab6ec8
UD
24 * Copyright (c) 2010, Oracle America, Inc.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions are
28 * met:
29 *
30 * * Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * * Redistributions in binary form must reproduce the above
33 * copyright notice, this list of conditions and the following
34 * disclaimer in the documentation and/or other materials
35 * provided with the distribution.
36 * * Neither the name of the "Oracle America, Inc." nor the names of its
37 * contributors may be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
43 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
44 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
45 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
47 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
49 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
50 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28f540f4
RM
52 */
53
e7fd8a39 54#include <errno.h>
bdb04ee8 55#include <unistd.h>
28f540f4 56#include <rpc/rpc.h>
e7fd8a39 57#include <rpc/svc.h>
28f540f4 58#include <rpc/pmap_clnt.h>
bdb04ee8 59#include <sys/poll.h>
14bc93a9 60#include <time.h>
82f43dd2 61#include <shlib-compat.h>
28f540f4 62
1bc1a2b9 63#define xports RPC_THREAD_VARIABLE(svc_xports_s)
28f540f4
RM
64
65#define NULL_SVC ((struct svc_callout *)0)
e7fd8a39 66#define RQCRED_SIZE 400 /* this size is excessive */
28f540f4 67
bdb04ee8
UD
68/* The services list
69 Each entry represents a set of procedures (an rpc program).
70 The dispatch routine takes request structs and runs the
71 appropriate procedure. */
f1e4a4a4 72struct svc_callout {
bdb04ee8
UD
73 struct svc_callout *sc_next;
74 rpcprog_t sc_prog;
75 rpcvers_t sc_vers;
76 void (*sc_dispatch) (struct svc_req *, SVCXPRT *);
71894681 77 bool_t sc_mapped;
f1e4a4a4 78};
1bc1a2b9 79#define svc_head RPC_THREAD_VARIABLE(svc_head_s)
28f540f4
RM
80
81/* *************** SVCXPRT related stuff **************** */
82
bdb04ee8 83/* Activate a transport handle. */
28f540f4 84void
e7fd8a39 85xprt_register (SVCXPRT *xprt)
28f540f4 86{
e7fd8a39 87 register int sock = xprt->xp_sock;
bdb04ee8 88 register int i;
28f540f4 89
e7fd8a39
UD
90 if (xports == NULL)
91 {
ed6b0fe7
BH
92 xports = (SVCXPRT **) calloc (_rpc_dtablesize (), sizeof (SVCXPRT *));
93 if (xports == NULL) /* Don't add handle */
bdb04ee8 94 return;
e7fd8a39 95 }
bdb04ee8 96
e7fd8a39
UD
97 if (sock < _rpc_dtablesize ())
98 {
d1dddedf
UD
99 struct pollfd *new_svc_pollfd;
100
e7fd8a39 101 xports[sock] = xprt;
bdb04ee8
UD
102 if (sock < FD_SETSIZE)
103 FD_SET (sock, &svc_fdset);
104
105 /* Check if we have an empty slot */
106 for (i = 0; i < svc_max_pollfd; ++i)
107 if (svc_pollfd[i].fd == -1)
108 {
109 svc_pollfd[i].fd = sock;
110 svc_pollfd[i].events = (POLLIN | POLLPRI |
111 POLLRDNORM | POLLRDBAND);
112 return;
113 }
114
d1dddedf
UD
115 new_svc_pollfd = (struct pollfd *) realloc (svc_pollfd,
116 sizeof (struct pollfd)
117 * (svc_max_pollfd + 1));
118 if (new_svc_pollfd == NULL) /* Out of memory */
bdb04ee8 119 return;
d1dddedf
UD
120 svc_pollfd = new_svc_pollfd;
121 ++svc_max_pollfd;
bdb04ee8
UD
122
123 svc_pollfd[svc_max_pollfd - 1].fd = sock;
124 svc_pollfd[svc_max_pollfd - 1].events = (POLLIN | POLLPRI |
125 POLLRDNORM | POLLRDBAND);
e7fd8a39 126 }
28f540f4 127}
021db4be 128libc_hidden_nolink_sunrpc (xprt_register, GLIBC_2_0)
28f540f4 129
bdb04ee8 130/* De-activate a transport handle. */
28f540f4 131void
bdb04ee8 132xprt_unregister (SVCXPRT *xprt)
c4029823 133{
e7fd8a39 134 register int sock = xprt->xp_sock;
bdb04ee8 135 register int i;
28f540f4 136
e7fd8a39
UD
137 if ((sock < _rpc_dtablesize ()) && (xports[sock] == xprt))
138 {
139 xports[sock] = (SVCXPRT *) 0;
bdb04ee8
UD
140
141 if (sock < FD_SETSIZE)
142 FD_CLR (sock, &svc_fdset);
143
144 for (i = 0; i < svc_max_pollfd; ++i)
145 if (svc_pollfd[i].fd == sock)
146 svc_pollfd[i].fd = -1;
e7fd8a39 147 }
28f540f4 148}
7b57bfe5 149#ifdef EXPORT_RPC_SYMBOLS
cd4c174b 150libc_hidden_def (xprt_unregister)
7b57bfe5 151#else
021db4be 152libc_hidden_nolink_sunrpc (xprt_unregister, GLIBC_2_0)
7b57bfe5 153#endif
28f540f4
RM
154
155
156/* ********************** CALLOUT list related stuff ************* */
157
bdb04ee8
UD
158/* Search the callout list for a program number, return the callout
159 struct. */
160static struct svc_callout *
161svc_find (rpcprog_t prog, rpcvers_t vers, struct svc_callout **prev)
162{
163 register struct svc_callout *s, *p;
164
165 p = NULL_SVC;
166 for (s = svc_head; s != NULL_SVC; s = s->sc_next)
167 {
168 if ((s->sc_prog == prog) && (s->sc_vers == vers))
169 goto done;
170 p = s;
171 }
172done:
173 *prev = p;
174 return s;
175}
176
177/* Add a service program to the callout list.
178 The dispatch routine will be called when a rpc request for this
179 program number comes in. */
28f540f4 180bool_t
bdb04ee8
UD
181svc_register (SVCXPRT * xprt, rpcprog_t prog, rpcvers_t vers,
182 void (*dispatch) (struct svc_req *, SVCXPRT *),
183 rpcproc_t protocol)
28f540f4 184{
e7fd8a39
UD
185 struct svc_callout *prev;
186 register struct svc_callout *s;
187
188 if ((s = svc_find (prog, vers, &prev)) != NULL_SVC)
189 {
190 if (s->sc_dispatch == dispatch)
191 goto pmap_it; /* he is registering another xptr */
192 return FALSE;
193 }
194 s = (struct svc_callout *) mem_alloc (sizeof (struct svc_callout));
195 if (s == (struct svc_callout *) 0)
bdb04ee8
UD
196 return FALSE;
197
e7fd8a39
UD
198 s->sc_prog = prog;
199 s->sc_vers = vers;
200 s->sc_dispatch = dispatch;
201 s->sc_next = svc_head;
71894681 202 s->sc_mapped = FALSE;
e7fd8a39 203 svc_head = s;
bdb04ee8 204
28f540f4 205pmap_it:
e7fd8a39
UD
206 /* now register the information with the local binder service */
207 if (protocol)
71894681
UD
208 {
209 if (! pmap_set (prog, vers, protocol, xprt->xp_port))
210 return FALSE;
211
212 s->sc_mapped = TRUE;
213 }
bdb04ee8 214
e7fd8a39 215 return TRUE;
28f540f4 216}
7b57bfe5 217#ifdef EXPORT_RPC_SYMBOLS
e2ec9b4d 218libc_hidden_def (svc_register)
7b57bfe5 219#else
021db4be 220libc_hidden_nolink_sunrpc (svc_register, GLIBC_2_0)
7b57bfe5 221#endif
28f540f4 222
bdb04ee8 223/* Remove a service program from the callout list. */
28f540f4 224void
bdb04ee8 225svc_unregister (rpcprog_t prog, rpcvers_t vers)
28f540f4 226{
e7fd8a39
UD
227 struct svc_callout *prev;
228 register struct svc_callout *s;
229
230 if ((s = svc_find (prog, vers, &prev)) == NULL_SVC)
231 return;
37fb019c 232 bool is_mapped = s->sc_mapped;
bdb04ee8 233
e7fd8a39 234 if (prev == NULL_SVC)
bdb04ee8 235 svc_head = s->sc_next;
e7fd8a39 236 else
bdb04ee8
UD
237 prev->sc_next = s->sc_next;
238
e7fd8a39
UD
239 s->sc_next = NULL_SVC;
240 mem_free ((char *) s, (u_int) sizeof (struct svc_callout));
241 /* now unregister the information with the local binder service */
37fb019c 242 if (is_mapped)
71894681 243 pmap_unset (prog, vers);
28f540f4 244}
021db4be 245libc_hidden_nolink_sunrpc (svc_unregister, GLIBC_2_0)
28f540f4
RM
246
247/* ******************* REPLY GENERATION ROUTINES ************ */
248
bdb04ee8 249/* Send a reply to an rpc request */
28f540f4 250bool_t
bdb04ee8
UD
251svc_sendreply (register SVCXPRT *xprt, xdrproc_t xdr_results,
252 caddr_t xdr_location)
28f540f4 253{
e7fd8a39
UD
254 struct rpc_msg rply;
255
256 rply.rm_direction = REPLY;
257 rply.rm_reply.rp_stat = MSG_ACCEPTED;
258 rply.acpted_rply.ar_verf = xprt->xp_verf;
259 rply.acpted_rply.ar_stat = SUCCESS;
260 rply.acpted_rply.ar_results.where = xdr_location;
261 rply.acpted_rply.ar_results.proc = xdr_results;
262 return SVC_REPLY (xprt, &rply);
28f540f4 263}
7b57bfe5
UD
264#ifdef EXPORT_RPC_SYMBOLS
265libc_hidden_def (svc_sendreply)
266#else
021db4be 267libc_hidden_nolink_sunrpc (svc_sendreply, GLIBC_2_0)
7b57bfe5 268#endif
28f540f4 269
bdb04ee8 270/* No procedure error reply */
28f540f4 271void
bdb04ee8 272svcerr_noproc (register SVCXPRT *xprt)
28f540f4 273{
e7fd8a39 274 struct rpc_msg rply;
28f540f4 275
e7fd8a39
UD
276 rply.rm_direction = REPLY;
277 rply.rm_reply.rp_stat = MSG_ACCEPTED;
278 rply.acpted_rply.ar_verf = xprt->xp_verf;
279 rply.acpted_rply.ar_stat = PROC_UNAVAIL;
280 SVC_REPLY (xprt, &rply);
28f540f4 281}
7b57bfe5
UD
282#ifdef EXPORT_RPC_SYMBOLS
283libc_hidden_def (svcerr_noproc)
284#else
021db4be 285libc_hidden_nolink_sunrpc (svcerr_noproc, GLIBC_2_0)
7b57bfe5 286#endif
28f540f4 287
bdb04ee8 288/* Can't decode args error reply */
28f540f4 289void
bdb04ee8 290svcerr_decode (register SVCXPRT *xprt)
28f540f4 291{
e7fd8a39 292 struct rpc_msg rply;
28f540f4 293
e7fd8a39
UD
294 rply.rm_direction = REPLY;
295 rply.rm_reply.rp_stat = MSG_ACCEPTED;
296 rply.acpted_rply.ar_verf = xprt->xp_verf;
297 rply.acpted_rply.ar_stat = GARBAGE_ARGS;
298 SVC_REPLY (xprt, &rply);
28f540f4 299}
7b57bfe5
UD
300#ifdef EXPORT_RPC_SYMBOLS
301libc_hidden_def (svcerr_decode)
302#else
021db4be 303libc_hidden_nolink_sunrpc (svcerr_decode, GLIBC_2_0)
7b57bfe5 304#endif
28f540f4 305
bdb04ee8 306/* Some system error */
28f540f4 307void
bdb04ee8 308svcerr_systemerr (register SVCXPRT *xprt)
28f540f4 309{
e7fd8a39 310 struct rpc_msg rply;
28f540f4 311
e7fd8a39
UD
312 rply.rm_direction = REPLY;
313 rply.rm_reply.rp_stat = MSG_ACCEPTED;
314 rply.acpted_rply.ar_verf = xprt->xp_verf;
315 rply.acpted_rply.ar_stat = SYSTEM_ERR;
316 SVC_REPLY (xprt, &rply);
28f540f4 317}
7b57bfe5
UD
318#ifdef EXPORT_RPC_SYMBOLS
319libc_hidden_def (svcerr_systemerr)
320#else
021db4be 321libc_hidden_nolink_sunrpc (svcerr_systemerr, GLIBC_2_0)
7b57bfe5 322#endif
28f540f4 323
bdb04ee8 324/* Authentication error reply */
28f540f4 325void
bdb04ee8 326svcerr_auth (SVCXPRT *xprt, enum auth_stat why)
28f540f4 327{
e7fd8a39 328 struct rpc_msg rply;
28f540f4 329
e7fd8a39
UD
330 rply.rm_direction = REPLY;
331 rply.rm_reply.rp_stat = MSG_DENIED;
332 rply.rjcted_rply.rj_stat = AUTH_ERROR;
333 rply.rjcted_rply.rj_why = why;
334 SVC_REPLY (xprt, &rply);
28f540f4 335}
021db4be 336libc_hidden_nolink_sunrpc (svcerr_auth, GLIBC_2_0)
28f540f4 337
bdb04ee8 338/* Auth too weak error reply */
28f540f4 339void
bdb04ee8 340svcerr_weakauth (SVCXPRT *xprt)
28f540f4 341{
e7fd8a39 342 svcerr_auth (xprt, AUTH_TOOWEAK);
28f540f4 343}
021db4be 344libc_hidden_nolink_sunrpc (svcerr_weakauth, GLIBC_2_0)
28f540f4 345
bdb04ee8 346/* Program unavailable error reply */
c4029823 347void
bdb04ee8 348svcerr_noprog (register SVCXPRT *xprt)
28f540f4 349{
e7fd8a39 350 struct rpc_msg rply;
28f540f4 351
e7fd8a39
UD
352 rply.rm_direction = REPLY;
353 rply.rm_reply.rp_stat = MSG_ACCEPTED;
354 rply.acpted_rply.ar_verf = xprt->xp_verf;
355 rply.acpted_rply.ar_stat = PROG_UNAVAIL;
356 SVC_REPLY (xprt, &rply);
28f540f4 357}
021db4be 358libc_hidden_nolink_sunrpc (svcerr_noprog, GLIBC_2_0)
28f540f4 359
bdb04ee8 360/* Program version mismatch error reply */
c4029823 361void
bdb04ee8
UD
362svcerr_progvers (register SVCXPRT *xprt, rpcvers_t low_vers,
363 rpcvers_t high_vers)
28f540f4 364{
e7fd8a39
UD
365 struct rpc_msg rply;
366
367 rply.rm_direction = REPLY;
368 rply.rm_reply.rp_stat = MSG_ACCEPTED;
369 rply.acpted_rply.ar_verf = xprt->xp_verf;
370 rply.acpted_rply.ar_stat = PROG_MISMATCH;
371 rply.acpted_rply.ar_vers.low = low_vers;
372 rply.acpted_rply.ar_vers.high = high_vers;
373 SVC_REPLY (xprt, &rply);
28f540f4 374}
021db4be 375libc_hidden_nolink_sunrpc (svcerr_progvers, GLIBC_2_0)
28f540f4
RM
376
377/* ******************* SERVER INPUT STUFF ******************* */
378
379/*
380 * Get server side input from some transport.
381 *
382 * Statement of authentication parameters management:
383 * This function owns and manages all authentication parameters, specifically
384 * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
385 * the "cooked" credentials (rqst->rq_clntcred).
386 * However, this function does not know the structure of the cooked
c4029823 387 * credentials, so it make the following assumptions:
28f540f4 388 * a) the structure is contiguous (no pointers), and
c4029823 389 * b) the cred structure size does not exceed RQCRED_SIZE bytes.
28f540f4
RM
390 * In all events, all three parameters are freed upon exit from this routine.
391 * The storage is trivially management on the call stack in user land, but
392 * is mallocated in kernel land.
393 */
394
395void
91eee4dd 396svc_getreq (int rdfds)
28f540f4 397{
e7fd8a39 398 fd_set readfds;
28f540f4 399
e7fd8a39
UD
400 FD_ZERO (&readfds);
401 readfds.fds_bits[0] = rdfds;
7b57bfe5 402 svc_getreqset (&readfds);
bdb04ee8 403}
021db4be 404libc_hidden_nolink_sunrpc (svc_getreq, GLIBC_2_0)
28f540f4 405
bdb04ee8
UD
406void
407svc_getreqset (fd_set *readfds)
408{
0994e2b8
UD
409 register fd_mask mask;
410 register fd_mask *maskp;
bdb04ee8
UD
411 register int setsize;
412 register int sock;
413 register int bit;
414
415 setsize = _rpc_dtablesize ();
0994e2b8
UD
416 if (setsize > FD_SETSIZE)
417 setsize = FD_SETSIZE;
418 maskp = readfds->fds_bits;
419 for (sock = 0; sock < setsize; sock += NFDBITS)
77c4d115 420 for (mask = *maskp++; (bit = ffsl (mask)); mask ^= (1L << (bit - 1)))
7b57bfe5 421 svc_getreq_common (sock + bit - 1);
28f540f4 422}
021db4be 423libc_hidden_nolink_sunrpc (svc_getreqset, GLIBC_2_0)
28f540f4
RM
424
425void
bdb04ee8 426svc_getreq_poll (struct pollfd *pfdp, int pollretval)
28f540f4 427{
30199a66
UD
428 if (pollretval == 0)
429 return;
a334319f 430
30199a66
UD
431 register int fds_found;
432 for (int i = fds_found = 0; i < svc_max_pollfd; ++i)
bdb04ee8
UD
433 {
434 register struct pollfd *p = &pfdp[i];
435
436 if (p->fd != -1 && p->revents)
437 {
438 /* fd has input waiting */
bdb04ee8 439 if (p->revents & POLLNVAL)
e79137b2 440 xprt_unregister (xports[p->fd]);
bdb04ee8 441 else
7b57bfe5 442 svc_getreq_common (p->fd);
30199a66
UD
443
444 if (++fds_found >= pollretval)
445 break;
bdb04ee8
UD
446 }
447 }
448}
7b57bfe5
UD
449#ifdef EXPORT_RPC_SYMBOLS
450libc_hidden_def (svc_getreq_poll)
451#else
021db4be 452libc_hidden_nolink_sunrpc (svc_getreq_poll, GLIBC_2_2)
7b57bfe5 453#endif
bdb04ee8
UD
454
455
456void
457svc_getreq_common (const int fd)
28f540f4 458{
e7fd8a39
UD
459 enum xprt_stat stat;
460 struct rpc_msg msg;
e7fd8a39 461 register SVCXPRT *xprt;
e7fd8a39
UD
462 char cred_area[2 * MAX_AUTH_BYTES + RQCRED_SIZE];
463 msg.rm_call.cb_cred.oa_base = cred_area;
464 msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
28f540f4 465
bdb04ee8
UD
466 xprt = xports[fd];
467 /* Do we control fd? */
468 if (xprt == NULL)
469 return;
28f540f4 470
bdb04ee8
UD
471 /* now receive msgs from xprtprt (support batch calls) */
472 do
e7fd8a39 473 {
bdb04ee8 474 if (SVC_RECV (xprt, &msg))
e7fd8a39 475 {
bdb04ee8
UD
476 /* now find the exported program and call it */
477 struct svc_callout *s;
478 struct svc_req r;
479 enum auth_stat why;
480 rpcvers_t low_vers;
481 rpcvers_t high_vers;
482 int prog_found;
483
484 r.rq_clntcred = &(cred_area[2 * MAX_AUTH_BYTES]);
485 r.rq_xprt = xprt;
486 r.rq_prog = msg.rm_call.cb_prog;
487 r.rq_vers = msg.rm_call.cb_vers;
488 r.rq_proc = msg.rm_call.cb_proc;
489 r.rq_cred = msg.rm_call.cb_cred;
490
491 /* first authenticate the message */
492 /* Check for null flavor and bypass these calls if possible */
493
494 if (msg.rm_call.cb_cred.oa_flavor == AUTH_NULL)
e7fd8a39 495 {
bdb04ee8
UD
496 r.rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
497 r.rq_xprt->xp_verf.oa_length = 0;
498 }
7b57bfe5 499 else if ((why = _authenticate (&r, &msg)) != AUTH_OK)
bdb04ee8
UD
500 {
501 svcerr_auth (xprt, why);
502 goto call_done;
503 }
504
505 /* now match message with a registered service */
506 prog_found = FALSE;
507 low_vers = 0 - 1;
508 high_vers = 0;
e7fd8a39 509
bdb04ee8
UD
510 for (s = svc_head; s != NULL_SVC; s = s->sc_next)
511 {
512 if (s->sc_prog == r.rq_prog)
513 {
514 if (s->sc_vers == r.rq_vers)
e7fd8a39 515 {
bdb04ee8 516 (*s->sc_dispatch) (&r, xprt);
e7fd8a39
UD
517 goto call_done;
518 }
bdb04ee8
UD
519 /* found correct version */
520 prog_found = TRUE;
521 if (s->sc_vers < low_vers)
522 low_vers = s->sc_vers;
523 if (s->sc_vers > high_vers)
524 high_vers = s->sc_vers;
e7fd8a39 525 }
bdb04ee8 526 /* found correct program */
28f540f4 527 }
bdb04ee8
UD
528 /* if we got here, the program or version
529 is not served ... */
530 if (prog_found)
531 svcerr_progvers (xprt, low_vers, high_vers);
532 else
533 svcerr_noprog (xprt);
534 /* Fall through to ... */
535 }
536 call_done:
537 if ((stat = SVC_STAT (xprt)) == XPRT_DIED)
538 {
539 SVC_DESTROY (xprt);
540 break;
28f540f4 541 }
e7fd8a39 542 }
bdb04ee8 543 while (stat == XPRT_MOREREQS);
28f540f4 544}
021db4be 545libc_hidden_nolink_sunrpc (svc_getreq_common, GLIBC_2_2)
f1e4a4a4 546
4b2e40a9
SL
547void
548__svc_wait_on_error (void)
549{
550 struct timespec ts = { .tv_sec = 0, .tv_nsec = 50000000 };
551 __nanosleep (&ts, NULL);
552}
553
14bc93a9
JL
554/* If there are no file descriptors available, then accept will fail.
555 We want to delay here so the connection request can be dequeued;
556 otherwise we can bounce between polling and accepting, never giving the
557 request a chance to dequeue and eating an enormous amount of cpu time
558 in svc_run if we're polling on many file descriptors. */
559void
560__svc_accept_failed (void)
561{
562 if (errno == EMFILE)
563 {
4b2e40a9 564 __svc_wait_on_error ();
14bc93a9
JL
565 }
566}
567
f1e4a4a4
UD
568
569void
570__rpc_thread_svc_cleanup (void)
571{
572 struct svc_callout *svcp;
573
574 while ((svcp = svc_head) != NULL)
575 svc_unregister (svcp->sc_prog, svcp->sc_vers);
576}