check for errors and recover instead of core-dumping.
This commit is contained in:
parent
670a38d899
commit
f0421a30ec
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: svc.c,v 1.35 2015/11/06 19:34:13 christos Exp $ */
|
||||
/* $NetBSD: svc.c,v 1.36 2015/11/07 17:34:33 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle America, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
static char *sccsid = "@(#)svc.c 1.44 88/02/08 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)svc.c 2.4 88/08/11 4.0 RPCSRC";
|
||||
#else
|
||||
__RCSID("$NetBSD: svc.c,v 1.35 2015/11/06 19:34:13 christos Exp $");
|
||||
__RCSID("$NetBSD: svc.c,v 1.36 2015/11/07 17:34:33 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -179,7 +179,8 @@ xprt_register(SVCXPRT *xprt)
|
|||
|
||||
__svc_xports[sock] = xprt;
|
||||
if (sock != -1) {
|
||||
svc_fdset_set(sock);
|
||||
if (svc_fdset_set(sock) == -1)
|
||||
return FALSE;
|
||||
}
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
return (TRUE);
|
||||
|
@ -222,7 +223,7 @@ __xprt_do_unregister(SVCXPRT *xprt, bool_t dolock)
|
|||
if (sock == -1)
|
||||
goto out;
|
||||
fdmax = svc_fdset_getmax();
|
||||
if (sock < *fdmax)
|
||||
if (fdmax == NULL || sock < *fdmax)
|
||||
goto clr;
|
||||
|
||||
for ((*fdmax)--; *fdmax >= 0; (*fdmax)--)
|
||||
|
@ -634,6 +635,8 @@ void
|
|||
svc_getreq(int rdfds)
|
||||
{
|
||||
fd_set *readfds = svc_fdset_copy(NULL);
|
||||
if (readfds == NULL)
|
||||
return;
|
||||
|
||||
readfds->fds_bits[0] = (unsigned int)rdfds;
|
||||
svc_getreqset(readfds);
|
||||
|
@ -771,7 +774,7 @@ svc_getreq_poll(struct pollfd *pfdp, int pollretval)
|
|||
* via someone select()ing from svc_fdset or
|
||||
* pollts()ing from svc_pollset[]. Thus it's safe
|
||||
* to handle the POLLNVAL event by simply turning
|
||||
* the corresponding bit off in svc_fdset. The
|
||||
* the corresponding bit off in the fdset. The
|
||||
* svc_pollset[] array is derived from svc_fdset
|
||||
* and so will also be updated eventually.
|
||||
*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: svc_run.c,v 1.23 2015/11/06 19:34:13 christos Exp $ */
|
||||
/* $NetBSD: svc_run.c,v 1.24 2015/11/07 17:34:33 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle America, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
static char *sccsid = "@(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC";
|
||||
#else
|
||||
__RCSID("$NetBSD: svc_run.c,v 1.23 2015/11/06 19:34:13 christos Exp $");
|
||||
__RCSID("$NetBSD: svc_run.c,v 1.24 2015/11/07 17:34:33 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -69,7 +69,7 @@ svc_run(void)
|
|||
{
|
||||
fd_set *readfds, *cleanfds;
|
||||
struct timeval timeout;
|
||||
int maxfd, fdsize;
|
||||
int *maxfd, fdsize;
|
||||
#ifndef RUMP_RPC
|
||||
int probs = 0;
|
||||
#endif
|
||||
|
@ -92,9 +92,13 @@ svc_run(void)
|
|||
free(cleanfds);
|
||||
cleanfds = svc_fdset_copy(svc_fdset_get());
|
||||
}
|
||||
maxfd = *svc_fdset_getmax();
|
||||
maxfd = svc_fdset_getmax();
|
||||
if (maxfd == NULL) {
|
||||
warn("can't get maxfd");
|
||||
continue;
|
||||
}
|
||||
rwlock_unlock(&svc_fd_lock);
|
||||
switch (select(maxfd + 1, readfds, NULL, NULL, &timeout)) {
|
||||
switch (select(*maxfd + 1, readfds, NULL, NULL, &timeout)) {
|
||||
case -1:
|
||||
#ifndef RUMP_RPC
|
||||
if ((errno == EINTR || errno == EBADF) && probs < 100) {
|
||||
|
@ -108,10 +112,12 @@ svc_run(void)
|
|||
warn("%s: select failed", __func__);
|
||||
goto out;
|
||||
case 0:
|
||||
__svc_clean_idle(cleanfds, 30, FALSE);
|
||||
if (cleanfds)
|
||||
__svc_clean_idle(cleanfds, 30, FALSE);
|
||||
continue;
|
||||
default:
|
||||
svc_getreqset2(readfds, fdsize);
|
||||
if (readfds)
|
||||
svc_getreqset2(readfds, fdsize);
|
||||
#ifndef RUMP_RPC
|
||||
probs = 0;
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: svc_vc.c,v 1.31 2015/11/06 19:34:13 christos Exp $ */
|
||||
/* $NetBSD: svc_vc.c,v 1.32 2015/11/07 17:34:33 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle America, Inc.
|
||||
|
@ -37,7 +37,7 @@
|
|||
static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
|
||||
static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC";
|
||||
#else
|
||||
__RCSID("$NetBSD: svc_vc.c,v 1.31 2015/11/06 19:34:13 christos Exp $");
|
||||
__RCSID("$NetBSD: svc_vc.c,v 1.32 2015/11/07 17:34:33 christos Exp $");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -329,7 +329,9 @@ again:
|
|||
*/
|
||||
if (errno == EMFILE || errno == ENFILE) {
|
||||
fd_set *cleanfds = svc_fdset_copy(svc_fdset_get());
|
||||
int rv = __svc_clean_idle(cleanfds, 0, FALSE);
|
||||
int rv = 0;
|
||||
if (cleanfds)
|
||||
rv = __svc_clean_idle(cleanfds, 0, FALSE);
|
||||
free(cleanfds);
|
||||
if (rv)
|
||||
goto again;
|
||||
|
@ -761,7 +763,7 @@ svc_vc_rendezvous_ops(SVCXPRT *xprt)
|
|||
bool_t
|
||||
__svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock)
|
||||
{
|
||||
int i, ncleaned, fdmax;
|
||||
int i, ncleaned, *fdmax;
|
||||
SVCXPRT *xprt, *least_active;
|
||||
struct timeval tv, tdiff, tmax;
|
||||
struct cf_conn *cd;
|
||||
|
@ -770,10 +772,17 @@ __svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock)
|
|||
tmax.tv_sec = tmax.tv_usec = 0;
|
||||
least_active = NULL;
|
||||
rwlock_wrlock(&svc_fd_lock);
|
||||
fdmax = *svc_fdset_getmax();
|
||||
for (i = ncleaned = 0; i <= fdmax; i++) {
|
||||
if (!svc_fdset_isset(i))
|
||||
fdmax = svc_fdset_getmax();
|
||||
if (fdmax == NULL)
|
||||
return FALSE;
|
||||
for (i = ncleaned = 0; i <= *fdmax; i++) {
|
||||
switch (svc_fdset_isset(i)) {
|
||||
case 0:
|
||||
case -1:
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
xprt = __svc_xports[i];
|
||||
if (xprt == NULL || xprt->xp_ops == NULL ||
|
||||
|
|
Loading…
Reference in New Issue