diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2014-11-11 04:51:50 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2014-11-11 04:51:50 +0000 |
commit | bf8686c7beaca76d4364d110a11e2a3e4c919304 (patch) | |
tree | b6062bf77488bd89790c9612bd23a24a1ef80935 /lib | |
parent | 79c58b06409c1edaf7dac80f878bba2472765f38 (diff) |
Merge from NetBSD from 1999-03-25:"
* 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>"
tested by many in snaps
ok schwarze@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/rpc/clnt_simple.c | 10 | ||||
-rw-r--r-- | lib/libc/rpc/clnt_tcp.c | 8 | ||||
-rw-r--r-- | lib/libc/rpc/clnt_udp.c | 8 | ||||
-rw-r--r-- | lib/libc/rpc/pmap_clnt.c | 17 | ||||
-rw-r--r-- | lib/libc/rpc/pmap_getmaps.c | 4 | ||||
-rw-r--r-- | lib/libc/rpc/pmap_getport.c | 4 | ||||
-rw-r--r-- | lib/libc/rpc/pmap_rmt.c | 4 |
7 files changed, 26 insertions, 29 deletions
diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index a2caca6e85c..7da3edd1085 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_simple.c,v 1.15 2010/09/01 14:43:34 millert Exp $ */ +/* $OpenBSD: clnt_simple.c,v 1.16 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -84,13 +84,15 @@ callrpc(char *host, int prognum, int versnum, int procnum, xdrproc_t inproc, /* 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 --git a/lib/libc/rpc/clnt_tcp.c b/lib/libc/rpc/clnt_tcp.c index 81d85f4f309..c40de1107a1 100644 --- a/lib/libc/rpc/clnt_tcp.c +++ b/lib/libc/rpc/clnt_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_tcp.c,v 1.25 2010/09/01 14:43:34 millert Exp $ */ +/* $OpenBSD: clnt_tcp.c,v 1.26 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -102,7 +102,9 @@ static int writetcp(struct ct_data *, caddr_t, int); * 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 + * 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. */ @@ -368,7 +370,7 @@ clnttcp_destroy(CLIENT *h) 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 --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c index c62a7f25d36..1939ac1cfce 100644 --- a/lib/libc/rpc/clnt_udp.c +++ b/lib/libc/rpc/clnt_udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clnt_udp.c,v 1.26 2010/09/01 14:43:34 millert Exp $ */ +/* $OpenBSD: clnt_udp.c,v 1.27 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -90,7 +90,9 @@ struct cu_data { * 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. * @@ -428,7 +430,7 @@ clntudp_destroy(CLIENT *cl) { 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 --git a/lib/libc/rpc/pmap_clnt.c b/lib/libc/rpc/pmap_clnt.c index 726920a77de..ca17a51504d 100644 --- a/lib/libc/rpc/pmap_clnt.c +++ b/lib/libc/rpc/pmap_clnt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap_clnt.c,v 1.16 2010/09/01 14:43:34 millert Exp $ */ +/* $OpenBSD: pmap_clnt.c,v 1.17 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -57,6 +57,7 @@ pmap_set(u_long program, u_long version, u_int protocol, int iport) CLIENT *client; struct pmap parms; bool_t rslt; + int save_errno; u_short port = iport; if (get_myaddress(&myaddress) != 0) @@ -72,15 +73,13 @@ pmap_set(u_long program, u_long version, u_int protocol, int iport) parms.pm_port = port; if (CLNT_CALL(client, PMAPPROC_SET, xdr_pmap, &parms, xdr_bool, &rslt, tottimeout) != RPC_SUCCESS) { - int save_errno = errno; - + save_errno = errno; clnt_perror(client, "Cannot register service"); - errno = save_errno; - return (FALSE); - } + rslt = FALSE; + } else + save_errno = errno; CLNT_DESTROY(client); - if (sock != -1) - (void)close(sock); + errno = save_errno; return (rslt); } @@ -110,7 +109,5 @@ pmap_unset(u_long program, u_long version) CLNT_CALL(client, PMAPPROC_UNSET, xdr_pmap, &parms, xdr_bool, &rslt, tottimeout); CLNT_DESTROY(client); - if (sock != -1) - (void)close(sock); return (rslt); } diff --git a/lib/libc/rpc/pmap_getmaps.c b/lib/libc/rpc/pmap_getmaps.c index 2be35a16f7d..fa570519af0 100644 --- a/lib/libc/rpc/pmap_getmaps.c +++ b/lib/libc/rpc/pmap_getmaps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap_getmaps.c,v 1.11 2010/09/01 14:43:34 millert Exp $ */ +/* $OpenBSD: pmap_getmaps.c,v 1.12 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -74,8 +74,6 @@ pmap_getmaps(struct sockaddr_in *address) } CLNT_DESTROY(client); } - if (sock != -1) - (void)close(sock); address->sin_port = 0; return (head); } diff --git a/lib/libc/rpc/pmap_getport.c b/lib/libc/rpc/pmap_getport.c index adc7df6dc3c..97f23ccca0c 100644 --- a/lib/libc/rpc/pmap_getport.c +++ b/lib/libc/rpc/pmap_getport.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap_getport.c,v 1.11 2010/09/01 14:43:34 millert Exp $ */ +/* $OpenBSD: pmap_getport.c,v 1.12 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -77,8 +77,6 @@ pmap_getport(struct sockaddr_in *address, u_long program, u_long version, } CLNT_DESTROY(client); } - if (sock != -1) - (void)close(sock); address->sin_port = 0; return (port); } diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c index 4e5a7021563..923dcb9674c 100644 --- a/lib/libc/rpc/pmap_rmt.c +++ b/lib/libc/rpc/pmap_rmt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap_rmt.c,v 1.30 2013/11/12 06:59:12 deraadt Exp $ */ +/* $OpenBSD: pmap_rmt.c,v 1.31 2014/11/11 04:51:49 guenther Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -91,8 +91,6 @@ pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc, } else { stat = RPC_FAILED; } - if (sock != -1) - (void)close(sock); addr->sin_port = 0; return (stat); } |