Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/rpc check for errors and recover instead of core-du...



details:   https://anonhg.NetBSD.org/src/rev/effe83f81e6d
branches:  trunk
changeset: 811609:effe83f81e6d
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 07 17:34:33 2015 +0000

description:
check for errors and recover instead of core-dumping.

diffstat:

 lib/libc/rpc/svc.c     |  13 ++++++++-----
 lib/libc/rpc/svc_run.c |  20 +++++++++++++-------
 lib/libc/rpc/svc_vc.c  |  23 ++++++++++++++++-------
 3 files changed, 37 insertions(+), 19 deletions(-)

diffs (172 lines):

diff -r d2673bab2080 -r effe83f81e6d lib/libc/rpc/svc.c
--- a/lib/libc/rpc/svc.c        Sat Nov 07 16:58:24 2015 +0000
+++ b/lib/libc/rpc/svc.c        Sat Nov 07 17:34:33 2015 +0000
@@ -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 @@
 
        __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 @@
        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 @@
 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 @@
                         *      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.
                         *
diff -r d2673bab2080 -r effe83f81e6d lib/libc/rpc/svc_run.c
--- a/lib/libc/rpc/svc_run.c    Sat Nov 07 16:58:24 2015 +0000
+++ b/lib/libc/rpc/svc_run.c    Sat Nov 07 17:34:33 2015 +0000
@@ -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 @@
 {
        fd_set *readfds, *cleanfds;
        struct timeval timeout;
-       int maxfd, fdsize;
+       int *maxfd, fdsize;
 #ifndef RUMP_RPC               
        int probs = 0;
 #endif
@@ -92,9 +92,13 @@
                        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 @@
                        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
diff -r d2673bab2080 -r effe83f81e6d lib/libc/rpc/svc_vc.c
--- a/lib/libc/rpc/svc_vc.c     Sat Nov 07 16:58:24 2015 +0000
+++ b/lib/libc/rpc/svc_vc.c     Sat Nov 07 17:34:33 2015 +0000
@@ -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 @@
                 */
                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 @@
 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 @@
        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 ||



Home | Main Index | Thread Index | Old Index