Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/rpc * don't close the socket unless it was opened b...



details:   https://anonhg.NetBSD.org/src/rev/d9d2fd604bf0
branches:  trunk
changeset: 467452:d9d2fd604bf0
user:      lukem <lukem%NetBSD.org@localhost>
date:      Thu Mar 25 01:16:10 1999 +0000

description:
* don't close the socket unless it was opened by the function
* note (in the comments) that the client is responsible for closing
  the socket if they opened it, or they didn't use CLNT_DESTROY()

fixes a couple of unnecessary closing of already-closed sockets.
noted by: Matthias Drochner <M.Drochner%fz-juelich.de@localhost>

diffstat:

 lib/libc/rpc/clnt_simple.c  |  12 +++++++-----
 lib/libc/rpc/clnt_tcp.c     |  12 ++++++++----
 lib/libc/rpc/clnt_udp.c     |  14 ++++++++------
 lib/libc/rpc/pmap_clnt.c    |  12 +++---------
 lib/libc/rpc/pmap_getmaps.c |   6 ++----
 lib/libc/rpc/pmap_getport.c |   6 ++----
 lib/libc/rpc/pmap_rmt.c     |   6 ++----
 lib/libc/rpc/svc_tcp.c      |   7 ++++---
 lib/libc/rpc/svc_udp.c      |   7 ++++---
 lib/libc/rpc/xdr_stdio.c    |   6 +++---
 10 files changed, 43 insertions(+), 45 deletions(-)

diffs (truncated from 332 to 300 lines):

diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/clnt_simple.c
--- a/lib/libc/rpc/clnt_simple.c        Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/clnt_simple.c        Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clnt_simple.c,v 1.15 1999/01/20 11:37:35 lukem Exp $   */
+/*     $NetBSD: clnt_simple.c,v 1.16 1999/03/25 01:16:10 lukem Exp $   */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)clnt_simple.c       2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: clnt_simple.c,v 1.15 1999/01/20 11:37:35 lukem Exp $");
+__RCSID("$NetBSD: clnt_simple.c,v 1.16 1999/03/25 01:16:10 lukem Exp $");
 #endif
 #endif
 
@@ -99,13 +99,15 @@
                /* reuse old client */          
        } else {
                crp->valid = 0;
-               if (crp->socket != -1)
+               if (crp->socket != -1) {
                        (void)close(crp->socket);
-               crp->socket = RPC_ANYSOCK;
+                       crp->socket = -1;
+               }
                if (crp->client) {
-                       clnt_destroy(crp->client);
+                       CLNT_DESTROY(crp->client);
                        crp->client = NULL;
                }
+               crp->socket = RPC_ANYSOCK;
                if ((hp = gethostbyname(host)) == NULL)
                        return ((int) RPC_UNKNOWNHOST);
                timeout.tv_usec = 0;
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/clnt_tcp.c
--- a/lib/libc/rpc/clnt_tcp.c   Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/clnt_tcp.c   Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clnt_tcp.c,v 1.17 1999/01/31 20:45:31 christos Exp $   */
+/*     $NetBSD: clnt_tcp.c,v 1.18 1999/03/25 01:16:10 lukem Exp $      */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)clnt_tcp.c  2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: clnt_tcp.c,v 1.17 1999/01/31 20:45:31 christos Exp $");
+__RCSID("$NetBSD: clnt_tcp.c,v 1.18 1999/03/25 01:16:10 lukem Exp $");
 #endif
 #endif
  
@@ -126,7 +126,11 @@
  * If raddr->sin_port is 0, then a binder on the remote machine is
  * consulted for the right port number.
  * NB: *sockp is copied into a private area.
- * NB: It is the clients responsibility to close *sockp.
+ * NB: It is the client's responsibility to close *sockp, unless
+ *     CLNT_DESTROY() is used
+ * NB: It is the client's responsibility to close *sockp, unless
+ *     clnttcp_create() was called with *sockp = -1 (so it created
+ *     the socket), and CLNT_DESTROY() is used.
  * NB: The rpch->cl_auth is set null authentication.  Caller may wish to set
  * this something more useful.
  */
@@ -414,7 +418,7 @@
 {
        struct ct_data *ct = (struct ct_data *) h->cl_private;
 
-       if (ct->ct_closeit) {
+       if (ct->ct_closeit && ct->ct_sock != -1) {
                (void)close(ct->ct_sock);
        }
        XDR_DESTROY(&(ct->ct_xdrs));
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/clnt_udp.c
--- a/lib/libc/rpc/clnt_udp.c   Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/clnt_udp.c   Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clnt_udp.c,v 1.16 1999/01/20 11:37:36 lukem Exp $      */
+/*     $NetBSD: clnt_udp.c,v 1.17 1999/03/25 01:16:11 lukem Exp $      */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)clnt_udp.c  2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: clnt_udp.c,v 1.16 1999/01/20 11:37:36 lukem Exp $");
+__RCSID("$NetBSD: clnt_udp.c,v 1.17 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -112,7 +112,9 @@
  * If *sockp<0, *sockp is set to a newly created UPD socket.
  * If raddr->sin_port is 0 a binder on the remote machine
  * is consulted for the correct port number.
- * NB: It is the clients responsibility to close *sockp.
+ * NB: It is the client's responsibility to close *sockp, unless
+ *     clntudp_bufcreate() was called with *sockp = -1 (so it created
+ *     the socket), and CLNT_DESTROY() is used.
  * NB: The rpch->cl_auth is initialized to null authentication.
  *     Caller may wish to set this something more useful.
  *
@@ -200,9 +202,9 @@
                        rpc_createerr.cf_error.re_errno = errno;
                        goto fooy;
                }
-               /* attempt to bind to priv port */
+                       /* attempt to bind to priv port */
                (void)bindresvport(*sockp, (struct sockaddr_in *)0);
-               /* the sockets rpc controls are non-blocking */
+                       /* the sockets rpc controls are non-blocking */
                (void)ioctl(*sockp, FIONBIO, (char *)(void *)&dontblock);
                cu->cu_closeit = TRUE;
        } else {
@@ -467,7 +469,7 @@
 {
        struct cu_data *cu = (struct cu_data *)cl->cl_private;
 
-       if (cu->cu_closeit) {
+       if (cu->cu_closeit && cu->cu_sock != -1) {
                (void)close(cu->cu_sock);
        }
        XDR_DESTROY(&(cu->cu_outxdrs));
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/pmap_clnt.c
--- a/lib/libc/rpc/pmap_clnt.c  Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/pmap_clnt.c  Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_clnt.c,v 1.11 1999/01/31 20:45:31 christos Exp $  */
+/*     $NetBSD: pmap_clnt.c,v 1.12 1999/03/25 01:16:11 lukem Exp $     */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: pmap_clnt.c,v 1.11 1999/01/31 20:45:31 christos Exp $");
+__RCSID("$NetBSD: pmap_clnt.c,v 1.12 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -92,13 +92,9 @@
        if (CLNT_CALL(client, PMAPPROC_SET, (xdrproc_t)xdr_pmap, 
            &parms, (xdrproc_t)xdr_bool, &rslt, tottimeout) != RPC_SUCCESS) {
                clnt_perror(client, "Cannot register service");
-               if (socket != -1)
-                       (void)close(socket);
-               return (FALSE);
+               rslt = FALSE;
        }
        CLNT_DESTROY(client);
-       if (socket != -1)
-               (void)close(socket);
        return (rslt);
 }
 
@@ -129,7 +125,5 @@
        CLNT_CALL(client, PMAPPROC_UNSET, (xdrproc_t)xdr_pmap, &parms,
            (xdrproc_t)xdr_bool, &rslt, tottimeout);
        CLNT_DESTROY(client);
-       if (socket != -1)
-               (void)close(socket);
        return (rslt);
 }
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/pmap_getmaps.c
--- a/lib/libc/rpc/pmap_getmaps.c       Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/pmap_getmaps.c       Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_getmaps.c,v 1.11 1999/01/31 20:45:31 christos Exp $       */
+/*     $NetBSD: pmap_getmaps.c,v 1.12 1999/03/25 01:16:11 lukem Exp $  */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)pmap_getmaps.c      2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: pmap_getmaps.c,v 1.11 1999/01/31 20:45:31 christos Exp $");
+__RCSID("$NetBSD: pmap_getmaps.c,v 1.12 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -97,8 +97,6 @@
                }
                CLNT_DESTROY(client);
        }
-       if (sock != -1)
-               (void)close(sock);
        address->sin_port = 0;
        return (head);
 }
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/pmap_getport.c
--- a/lib/libc/rpc/pmap_getport.c       Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/pmap_getport.c       Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_getport.c,v 1.11 1999/01/31 20:45:31 christos Exp $       */
+/*     $NetBSD: pmap_getport.c,v 1.12 1999/03/25 01:16:11 lukem Exp $  */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)pmap_getport.c      2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: pmap_getport.c,v 1.11 1999/01/31 20:45:31 christos Exp $");
+__RCSID("$NetBSD: pmap_getport.c,v 1.12 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -101,8 +101,6 @@
                }
                CLNT_DESTROY(client);
        }
-       if (sock != -1)
-               (void)close(sock);
        address->sin_port = 0;
        return (port);
 }
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/pmap_rmt.c
--- a/lib/libc/rpc/pmap_rmt.c   Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/pmap_rmt.c   Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_rmt.c,v 1.19 1999/01/31 20:45:31 christos Exp $   */
+/*     $NetBSD: pmap_rmt.c,v 1.20 1999/03/25 01:16:11 lukem Exp $      */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)pmap_rmt.c  2.2 88/08/01 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: pmap_rmt.c,v 1.19 1999/01/31 20:45:31 christos Exp $");
+__RCSID("$NetBSD: pmap_rmt.c,v 1.20 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -123,8 +123,6 @@
        } else {
                stat = RPC_FAILED;
        }
-       if (sock != -1)
-               (void)close(sock);
        addr->sin_port = 0;
        return (stat);
 }
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/svc_tcp.c
--- a/lib/libc/rpc/svc_tcp.c    Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/svc_tcp.c    Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svc_tcp.c,v 1.21 1999/01/20 11:37:39 lukem Exp $       */
+/*     $NetBSD: svc_tcp.c,v 1.22 1999/03/25 01:16:11 lukem Exp $       */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,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_tcp.c,v 1.21 1999/01/20 11:37:39 lukem Exp $");
+__RCSID("$NetBSD: svc_tcp.c,v 1.22 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -295,7 +295,8 @@
        struct tcp_conn *cd = (struct tcp_conn *)xprt->xp_p1;
 
        xprt_unregister(xprt);
-       (void)close(xprt->xp_sock);
+       if (xprt->xp_sock != -1)
+               (void)close(xprt->xp_sock);
        if (xprt->xp_port != 0) {
                /* a rendezvouser socket */
                xprt->xp_port = 0;
diff -r 7f38727cee8d -r d9d2fd604bf0 lib/libc/rpc/svc_udp.c
--- a/lib/libc/rpc/svc_udp.c    Thu Mar 25 01:00:18 1999 +0000
+++ b/lib/libc/rpc/svc_udp.c    Thu Mar 25 01:16:10 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: svc_udp.c,v 1.16 1999/01/20 11:37:40 lukem Exp $       */
+/*     $NetBSD: svc_udp.c,v 1.17 1999/03/25 01:16:11 lukem Exp $       */
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -35,7 +35,7 @@
 static char *sccsid = "@(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";
 static char *sccsid = "@(#)svc_udp.c   2.2 88/07/29 4.0 RPCSRC";
 #else
-__RCSID("$NetBSD: svc_udp.c,v 1.16 1999/01/20 11:37:40 lukem Exp $");
+__RCSID("$NetBSD: svc_udp.c,v 1.17 1999/03/25 01:16:11 lukem Exp $");
 #endif
 #endif
 
@@ -287,7 +287,8 @@
        struct svcudp_data *su = su_data(xprt);
 
        xprt_unregister(xprt);
-       (void)close(xprt->xp_sock);



Home | Main Index | Thread Index | Old Index