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