Mon Jul 6 16:24:06 2020 UTC ()
don't open the socket twice.


(christos)
diff -r1.18 -r1.19 src/tests/net/net/t_unix.c

cvs diff -r1.18 -r1.19 src/tests/net/net/t_unix.c (expand / switch to unified diff)

--- src/tests/net/net/t_unix.c 2019/04/14 01:45:30 1.18
+++ src/tests/net/net/t_unix.c 2020/07/06 16:24:06 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_unix.c,v 1.18 2019/04/14 01:45:30 christos Exp $ */ 1/* $NetBSD: t_unix.c,v 1.19 2020/07/06 16:24:06 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc. 4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE. 36 * POSSIBILITY OF SUCH DAMAGE.
37 */ 37 */
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#ifdef __RCSID 40#ifdef __RCSID
41__RCSID("$Id: t_unix.c,v 1.18 2019/04/14 01:45:30 christos Exp $"); 41__RCSID("$Id: t_unix.c,v 1.19 2020/07/06 16:24:06 christos Exp $");
42#else 42#else
43#define getprogname() argv[0] 43#define getprogname() argv[0]
44#endif 44#endif
45 45
46#ifdef __linux__ 46#ifdef __linux__
47#define LX -1 47#define LX -1
48#else 48#else
49#define LX 49#define LX
50#endif 50#endif
51#include <sys/param.h> 51#include <sys/param.h>
52#include <sys/socket.h> 52#include <sys/socket.h>
53#include <sys/un.h> 53#include <sys/un.h>
54#include <sys/wait.h> 54#include <sys/wait.h>
@@ -152,37 +152,33 @@ test(bool forkit, bool closeit, size_t l @@ -152,37 +152,33 @@ test(bool forkit, bool closeit, size_t l
152 socklen_t sl; 152 socklen_t sl;
153 int srvr = -1, clnt = -1, acpt = -1; 153 int srvr = -1, clnt = -1, acpt = -1;
154 uid_t euid; 154 uid_t euid;
155 gid_t egid; 155 gid_t egid;
156 pid_t srvrpid, clntpid; 156 pid_t srvrpid, clntpid;
157 struct sockaddr_un *sock_addr = NULL, *sun = NULL; 157 struct sockaddr_un *sock_addr = NULL, *sun = NULL;
158 socklen_t sock_addrlen; 158 socklen_t sock_addrlen;
159 socklen_t peer_addrlen; 159 socklen_t peer_addrlen;
160 struct sockaddr_un peer_addr; 160 struct sockaddr_un peer_addr;
161 161
162 srvrpid = clntpid = getpid(); 162 srvrpid = clntpid = getpid();
163 srvr = socket(AF_UNIX, SOCK_STREAM, 0); 163 srvr = socket(AF_UNIX, SOCK_STREAM, 0);
164 if (srvr == -1) 164 if (srvr == -1)
165 FAIL("socket(srvrer)"); 165 FAIL("socket(server)");
166 166
167 slen = len + OF + 1; 167 slen = len + OF + 1;
168  168
169 if ((sun = calloc(1, slen)) == NULL) 169 if ((sun = calloc(1, slen)) == NULL)
170 FAIL("calloc"); 170 FAIL("calloc");
171 171
172 srvr = socket(AF_UNIX, SOCK_STREAM, 0); 
173 if (srvr == -1) 
174 FAIL("socket"); 
175 
176 memset(sun->sun_path, 'a', len); 172 memset(sun->sun_path, 'a', len);
177 sun->sun_path[len] = '\0'; 173 sun->sun_path[len] = '\0';
178 (void)unlink(sun->sun_path); 174 (void)unlink(sun->sun_path);
179 175
180 sl = SUN_LEN(sun); 176 sl = SUN_LEN(sun);
181#ifdef BSD4_4 177#ifdef BSD4_4
182 sun->sun_len = sl; 178 sun->sun_len = sl;
183#endif 179#endif
184 sun->sun_family = AF_UNIX; 180 sun->sun_family = AF_UNIX;
185 181
186 if (bind(srvr, (struct sockaddr *)sun, sl) == -1) { 182 if (bind(srvr, (struct sockaddr *)sun, sl) == -1) {
187 if (errno == EINVAL && sl >= 256) { 183 if (errno == EINVAL && sl >= 256) {
188 close(srvr); 184 close(srvr);