Fri Nov 6 23:05:09 2015 UTC ()
Don't use macros as types or variable names.


(joerg)
diff -r1.9 -r1.10 src/lib/libc/rpc/rpc_commondata.c
diff -r1.2 -r1.3 src/lib/libc/rpc/svc_fdset.c

cvs diff -r1.9 -r1.10 src/lib/libc/rpc/rpc_commondata.c (switch to unified diff)

--- src/lib/libc/rpc/rpc_commondata.c 2013/03/11 20:19:29 1.9
+++ src/lib/libc/rpc/rpc_commondata.c 2015/11/06 23:05:09 1.10
@@ -1,55 +1,57 @@ @@ -1,55 +1,57 @@
1/* $NetBSD: rpc_commondata.c,v 1.9 2013/03/11 20:19:29 tron Exp $ */ 1/* $NetBSD: rpc_commondata.c,v 1.10 2015/11/06 23:05:09 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010, Oracle America, Inc. 4 * Copyright (c) 2010, Oracle America, Inc.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above 12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following 13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials 14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution. 15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its 16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived 17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission. 18 * from this software without specific prior written permission.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
 34#define SVC_LEGACY
 35
34#include <sys/cdefs.h> 36#include <sys/cdefs.h>
35#if defined(LIBC_SCCS) && !defined(lint) 37#if defined(LIBC_SCCS) && !defined(lint)
36#if 0 38#if 0
37static char *sccsid = "@(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC"; 39static char *sccsid = "@(#)rpc_commondata.c 2.1 88/07/29 4.0 RPCSRC";
38#else 40#else
39__RCSID("$NetBSD: rpc_commondata.c,v 1.9 2013/03/11 20:19:29 tron Exp $"); 41__RCSID("$NetBSD: rpc_commondata.c,v 1.10 2015/11/06 23:05:09 joerg Exp $");
40#endif 42#endif
41#endif 43#endif
42 44
43#include <rpc/rpc.h> 45#include <rpc/rpc.h>
44 46
45/* 47/*
46 * This file should only contain common data (global data) that is exported 48 * This file should only contain common data (global data) that is exported
47 * by public interfaces  49 * by public interfaces
48 */ 50 */
49struct opaque_auth _null_auth; 51struct opaque_auth _null_auth;
50fd_set svc_fdset; 52fd_set svc_fdset;
51int svc_maxfd = -1; 53int svc_maxfd = -1;
52#ifndef _REENTRANT 54#ifndef _REENTRANT
53#undef rpc_createerr 55#undef rpc_createerr
54struct rpc_createerr rpc_createerr; 56struct rpc_createerr rpc_createerr;
55#endif 57#endif

cvs diff -r1.2 -r1.3 src/lib/libc/rpc/svc_fdset.c (switch to unified diff)

--- src/lib/libc/rpc/svc_fdset.c 2015/11/06 19:34:13 1.2
+++ src/lib/libc/rpc/svc_fdset.c 2015/11/06 23:05:09 1.3
@@ -1,300 +1,300 @@ @@ -1,300 +1,300 @@
1/* $NetBSD: svc_fdset.c,v 1.2 2015/11/06 19:34:13 christos Exp $ */ 1/* $NetBSD: svc_fdset.c,v 1.3 2015/11/06 23:05:09 joerg Exp $ */
2 2
3#include <sys/cdefs.h> 3#include <sys/cdefs.h>
4__RCSID("$NetBSD: svc_fdset.c,v 1.2 2015/11/06 19:34:13 christos Exp $"); 4__RCSID("$NetBSD: svc_fdset.c,v 1.3 2015/11/06 23:05:09 joerg Exp $");
5 5
6 6
7#include "reentrant.h" 7#include "reentrant.h"
8 8
9#include <sys/fd_set.h> 9#include <sys/fd_set.h>
10 10
11#include <rpc/rpc.h> 11#include <rpc/rpc.h>
12 12
13#include <stdlib.h> 13#include <stdlib.h>
14#include <string.h> 14#include <string.h>
15 15
16struct svc_fdset { 16struct my_svc_fdset {
17 fd_set *fdset; 17 fd_set *fdset;
18 int fdmax; 18 int fdmax;
19 int fdsize; 19 int fdsize;
20}; 20};
21 21
22 22
23/* The single threaded, one global fd_set version */ 23/* The single threaded, one global fd_set version */
24static fd_set *__svc_fdset; 24static fd_set *__svc_fdset;
25static int svc_fdsize = 0; 25static int svc_fdsize = 0;
26 26
27/* 27/*
28 * Update the old global svc_fdset if needed for binary compatibility 28 * Update the old global svc_fdset if needed for binary compatibility
29 */ 29 */
30#define COMPAT_UPDATE(a) \ 30#define COMPAT_UPDATE(a) \
31 do \ 31 do \
32 if ((a) == __svc_fdset) \ 32 if ((a) == __svc_fdset) \
33 svc_fdset = *__svc_fdset; \ 33 svc_fdset = *__svc_fdset; \
34 while (/*CONSTCOND*/0) 34 while (/*CONSTCOND*/0)
35 35
36static thread_key_t fdsetkey = -2; 36static thread_key_t fdsetkey = -2;
37 37
38#ifdef FDSET_DEBUG 38#ifdef FDSET_DEBUG
39#include <stdio.h> 39#include <stdio.h>
40#include <stdarg.h> 40#include <stdarg.h>
41#include <unistd.h> 41#include <unistd.h>
42#include <lwp.h> 42#include <lwp.h>
43 43
44static void __printflike(3, 0) 44static void __printflike(3, 0)
45svc_header(const char *func, size_t line, const char *fmt, va_list ap) 45svc_header(const char *func, size_t line, const char *fmt, va_list ap)
46{ 46{
47 fprintf(stderr, "%s[%d.%d]: %s, %zu: ", getprogname(), (int)getpid(), 47 fprintf(stderr, "%s[%d.%d]: %s, %zu: ", getprogname(), (int)getpid(),
48 (int)_lwp_self(), func, line); 48 (int)_lwp_self(), func, line);
49 vfprintf(stderr, fmt, ap); 49 vfprintf(stderr, fmt, ap);
50 va_end(ap); 50 va_end(ap);
51} 51}
52 52
53static void __printflike(5, 6) 53static void __printflike(5, 6)
54svc_fdset_print(const char *func, size_t line, const fd_set *fds, int fdmax, 54svc_fdset_print(const char *func, size_t line, const fd_set *fds, int fdmax,
55 const char *fmt, ...) 55 const char *fmt, ...)
56{ 56{
57 va_list ap; 57 va_list ap;
58 const char *did = ""; 58 const char *did = "";
59 59
60 va_start(ap, fmt); 60 va_start(ap, fmt);
61 svc_header(func, line, fmt, ap); 61 svc_header(func, line, fmt, ap);
62 va_end(ap); 62 va_end(ap);
63 63
64 if (fdmax == 0) 64 if (fdmax == 0)
65 fdmax = FD_SETSIZE; 65 fdmax = FD_SETSIZE;
66 66
67 fprintf(stderr, "%p[%d] <", fds, fdmax); 67 fprintf(stderr, "%p[%d] <", fds, fdmax);
68 for (int i = 0; i <= fdmax; i++) { 68 for (int i = 0; i <= fdmax; i++) {
69 if (!FD_ISSET(i, fds)) 69 if (!FD_ISSET(i, fds))
70 continue; 70 continue;
71 fprintf(stderr, "%s%d", did, i); 71 fprintf(stderr, "%s%d", did, i);
72 did = ", "; 72 did = ", ";
73 } 73 }
74 fprintf(stderr, ">\n"); 74 fprintf(stderr, ">\n");
75} 75}
76 76
77static void __printflike(3, 4) 77static void __printflike(3, 4)
78svc_print(const char *func, size_t line, const char *fmt, ...) 78svc_print(const char *func, size_t line, const char *fmt, ...)
79{ 79{
80 va_list ap; 80 va_list ap;
81 81
82 va_start(ap, fmt); 82 va_start(ap, fmt);
83 svc_header(func, line, fmt, ap); 83 svc_header(func, line, fmt, ap);
84 va_end(ap); 84 va_end(ap);
85 fprintf(stderr, "\n"); 85 fprintf(stderr, "\n");
86} 86}
87 87
88#define DPRINTF_FDSET(...) svc_fdset_print(__func__, __LINE__, __VA_ARGS__) 88#define DPRINTF_FDSET(...) svc_fdset_print(__func__, __LINE__, __VA_ARGS__)
89#define DPRINTF(...) svc_print(__func__, __LINE__, __VA_ARGS__) 89#define DPRINTF(...) svc_print(__func__, __LINE__, __VA_ARGS__)
90#else 90#else
91#define DPRINTF_FDSET(...) 91#define DPRINTF_FDSET(...)
92#define DPRINTF(...) 92#define DPRINTF(...)
93#endif 93#endif
94 94
95 95
96static void 96static void
97svc_fdset_free(void *v) 97svc_fdset_free(void *v)
98{ 98{
99 struct svc_fdset *rv = v; 99 struct my_svc_fdset *rv = v;
100 DPRINTF_FDSET(rv->fdset, 0, "free"); 100 DPRINTF_FDSET(rv->fdset, 0, "free");
101 101
102 free(rv->fdset); 102 free(rv->fdset);
103 free(rv); 103 free(rv);
104} 104}
105 105
106static fd_set * 106static fd_set *
107svc_fdset_resize(int fd, fd_set **fdset, int *fdsize) 107svc_fdset_resize(int fd, fd_set **fdset, int *fdsize)
108{ 108{
109 if (*fdset && fd < *fdsize) { 109 if (*fdset && fd < *fdsize) {
110 DPRINTF_FDSET(*fdset, 0, "keeping %d < %d", 110 DPRINTF_FDSET(*fdset, 0, "keeping %d < %d",
111 fd, *fdsize); 111 fd, *fdsize);
112 return *fdset; 112 return *fdset;
113 } 113 }
114 114
115 fd += FD_SETSIZE;  115 fd += FD_SETSIZE;
116 if (fd == 517) 116 if (fd == 517)
117 abort(); 117 abort();
118 118
119 char *newfdset = realloc(*fdset, __NFD_BYTES(fd)); 119 char *newfdset = realloc(*fdset, __NFD_BYTES(fd));
120 if (newfdset == NULL) 120 if (newfdset == NULL)
121 return NULL; 121 return NULL;
122 122
123 memset(newfdset + __NFD_BYTES(*fdsize), 0, 123 memset(newfdset + __NFD_BYTES(*fdsize), 0,
124 __NFD_BYTES(fd) - __NFD_BYTES(*fdsize)); 124 __NFD_BYTES(fd) - __NFD_BYTES(*fdsize));
125 125
126 126
127 *fdset = (void *)newfdset; 127 *fdset = (void *)newfdset;
128 DPRINTF_FDSET(*fdset, 0, "resize %d > %d", fd, *fdsize); 128 DPRINTF_FDSET(*fdset, 0, "resize %d > %d", fd, *fdsize);
129 *fdsize = fd; 129 *fdsize = fd;
130 130
131 COMPAT_UPDATE(*fdset); 131 COMPAT_UPDATE(*fdset);
132 132
133 return *fdset; 133 return *fdset;
134} 134}
135 135
136static struct svc_fdset * 136static struct my_svc_fdset *
137svc_fdset_alloc(int fd) 137svc_fdset_alloc(int fd)
138{ 138{
139 struct svc_fdset *rv; 139 struct my_svc_fdset *rv;
140 140
141 if (fdsetkey == -1) 141 if (fdsetkey == -1)
142 thr_keycreate(&fdsetkey, svc_fdset_free); 142 thr_keycreate(&fdsetkey, svc_fdset_free);
143 143
144 if ((rv = thr_getspecific(fdsetkey)) == NULL) { 144 if ((rv = thr_getspecific(fdsetkey)) == NULL) {
145 145
146 rv = calloc(1, sizeof(*rv)); 146 rv = calloc(1, sizeof(*rv));
147 if (rv == NULL) 147 if (rv == NULL)
148 return NULL; 148 return NULL;
149 149
150 (void)thr_setspecific(fdsetkey, rv); 150 (void)thr_setspecific(fdsetkey, rv);
151 151
152 if (svc_fdsize != 0) { 152 if (svc_fdsize != 0) {
153 rv->fdset = __svc_fdset; 153 rv->fdset = __svc_fdset;
154 DPRINTF("switching to %p", rv->fdset); 154 DPRINTF("switching to %p", rv->fdset);
155 rv->fdmax = svc_maxfd; 155 rv->fdmax = svc_maxfd;
156 rv->fdsize = svc_fdsize; 156 rv->fdsize = svc_fdsize;
157 157
158 svc_fdsize = 0; 158 svc_fdsize = 0;
159 } else { 159 } else {
160 DPRINTF("first thread time %p", rv->fdset); 160 DPRINTF("first thread time %p", rv->fdset);
161 } 161 }
162 } else { 162 } else {
163 DPRINTF("again for %p", rv->fdset); 163 DPRINTF("again for %p", rv->fdset);
164 if (fd < rv->fdsize) 164 if (fd < rv->fdsize)
165 return rv; 165 return rv;
166 } 166 }
167 if (svc_fdset_resize(fd, &rv->fdset, &rv->fdsize) == NULL) 167 if (svc_fdset_resize(fd, &rv->fdset, &rv->fdsize) == NULL)
168 return NULL; 168 return NULL;
169 return rv; 169 return rv;
170} 170}
171 171
172static fd_set * 172static fd_set *
173svc_fdset_get_internal(int fd) 173svc_fdset_get_internal(int fd)
174{ 174{
175 struct svc_fdset *rv; 175 struct my_svc_fdset *rv;
176 176
177 if (!__isthreaded || fdsetkey == -2) 177 if (!__isthreaded || fdsetkey == -2)
178 return svc_fdset_resize(fd, &__svc_fdset, &svc_fdsize); 178 return svc_fdset_resize(fd, &__svc_fdset, &svc_fdsize);
179 179
180 rv = svc_fdset_alloc(fd); 180 rv = svc_fdset_alloc(fd);
181 if (rv == NULL) 181 if (rv == NULL)
182 return NULL; 182 return NULL;
183 return rv->fdset; 183 return rv->fdset;
184} 184}
185 185
186 186
187/* allow each thread to have their own copy */ 187/* allow each thread to have their own copy */
188void 188void
189svc_fdset_init(int flags) 189svc_fdset_init(int flags)
190{ 190{
191 DPRINTF("%x", flags); 191 DPRINTF("%x", flags);
192 if ((flags & SVC_FDSET_MT) && fdsetkey == -2) 192 if ((flags & SVC_FDSET_MT) && fdsetkey == -2)
193 fdsetkey = -1; 193 fdsetkey = -1;
194} 194}
195 195
196void 196void
197svc_fdset_zero(void) 197svc_fdset_zero(void)
198{ 198{
199 DPRINTF("zero"); 199 DPRINTF("zero");
200 fd_set *fds = svc_fdset_get_internal(0); 200 fd_set *fds = svc_fdset_get_internal(0);
201 int size = svc_fdset_getsize(0); 201 int size = svc_fdset_getsize(0);
202 memset(fds, 0, __NFD_BYTES(size)); 202 memset(fds, 0, __NFD_BYTES(size));
203 *svc_fdset_getmax() = 0; 203 *svc_fdset_getmax() = 0;
204 204
205 COMPAT_UPDATE(fds); 205 COMPAT_UPDATE(fds);
206 206
207} 207}
208 208
209void 209void
210svc_fdset_set(int fd) 210svc_fdset_set(int fd)
211{ 211{
212 fd_set *fds = svc_fdset_get_internal(fd); 212 fd_set *fds = svc_fdset_get_internal(fd);
213 int *fdmax = svc_fdset_getmax(); 213 int *fdmax = svc_fdset_getmax();
214 FD_SET(fd, fds); 214 FD_SET(fd, fds);
215 if (fd > *fdmax) 215 if (fd > *fdmax)
216 *fdmax = fd; 216 *fdmax = fd;
217 DPRINTF_FDSET(fds, *fdmax, "%d", fd); 217 DPRINTF_FDSET(fds, *fdmax, "%d", fd);
218 218
219 COMPAT_UPDATE(fds); 219 COMPAT_UPDATE(fds);
220} 220}
221 221
222int 222int
223svc_fdset_isset(int fd) 223svc_fdset_isset(int fd)
224{ 224{
225 fd_set *fds = svc_fdset_get_internal(fd); 225 fd_set *fds = svc_fdset_get_internal(fd);
226 DPRINTF_FDSET(fds, 0, "%d", fd); 226 DPRINTF_FDSET(fds, 0, "%d", fd);
227 return FD_ISSET(fd, fds); 227 return FD_ISSET(fd, fds);
228} 228}
229 229
230void 230void
231svc_fdset_clr(int fd) 231svc_fdset_clr(int fd)
232{ 232{
233 fd_set *fds = svc_fdset_get_internal(fd); 233 fd_set *fds = svc_fdset_get_internal(fd);
234 FD_CLR(fd, fds); 234 FD_CLR(fd, fds);
235 /* XXX: update fdmax? */ 235 /* XXX: update fdmax? */
236 DPRINTF_FDSET(fds, 0, "%d", fd); 236 DPRINTF_FDSET(fds, 0, "%d", fd);
237 237
238 COMPAT_UPDATE(fds); 238 COMPAT_UPDATE(fds);
239} 239}
240 240
241fd_set * 241fd_set *
242svc_fdset_copy(const fd_set *orig) 242svc_fdset_copy(const fd_set *orig)
243{ 243{
244 int len, fdmax; 244 int len, fdmax;
245 fd_set *fds; 245 fd_set *fds;
246  246
247 len = 0; 247 len = 0;
248 fds = 0; 248 fds = 0;
249 fdmax = *svc_fdset_getmax(); 249 fdmax = *svc_fdset_getmax();
250 250
251 DPRINTF_FDSET(orig, 0, "[orig]"); 251 DPRINTF_FDSET(orig, 0, "[orig]");
252 fds = svc_fdset_resize(fdmax, &fds, &len); 252 fds = svc_fdset_resize(fdmax, &fds, &len);
253 if (fds == NULL) 253 if (fds == NULL)
254 return NULL; 254 return NULL;
255 255
256 if (orig) 256 if (orig)
257 memcpy(fds, orig, __NFD_BYTES(fdmax)); 257 memcpy(fds, orig, __NFD_BYTES(fdmax));
258 DPRINTF_FDSET(fds, 0, "[copy]"); 258 DPRINTF_FDSET(fds, 0, "[copy]");
259 return fds; 259 return fds;
260} 260}
261 261
262fd_set * 262fd_set *
263svc_fdset_get(void) 263svc_fdset_get(void)
264{ 264{
265 fd_set *fds = svc_fdset_get_internal(0); 265 fd_set *fds = svc_fdset_get_internal(0);
266 DPRINTF_FDSET(fds, 0, "get"); 266 DPRINTF_FDSET(fds, 0, "get");
267 return fds; 267 return fds;
268} 268}
269 269
270int * 270int *
271svc_fdset_getmax(void) 271svc_fdset_getmax(void)
272{ 272{
273 struct svc_fdset *rv; 273 struct my_svc_fdset *rv;
274 274
275 if (!__isthreaded || fdsetkey == -2) 275 if (!__isthreaded || fdsetkey == -2)
276 return &svc_maxfd; 276 return &svc_maxfd;
277  277
278 rv = svc_fdset_alloc(0); 278 rv = svc_fdset_alloc(0);
279 if (rv == NULL) 279 if (rv == NULL)
280 return NULL; 280 return NULL;
281 return &rv->fdmax; 281 return &rv->fdmax;
282} 282}
283 283
284int 284int
285svc_fdset_getsize(int fd) 285svc_fdset_getsize(int fd)
286{ 286{
287 struct svc_fdset *rv; 287 struct my_svc_fdset *rv;
288 288
289 if (!__isthreaded || fdsetkey == -2) { 289 if (!__isthreaded || fdsetkey == -2) {
290 if (svc_fdset_resize(fd, &__svc_fdset, &svc_fdsize) == NULL) 290 if (svc_fdset_resize(fd, &__svc_fdset, &svc_fdsize) == NULL)
291 return -1; 291 return -1;
292 else 292 else
293 return svc_fdsize; 293 return svc_fdsize;
294 } 294 }
295 295
296 rv = svc_fdset_alloc(fd); 296 rv = svc_fdset_alloc(fd);
297 if (rv == NULL) 297 if (rv == NULL)
298 return -1; 298 return -1;
299 return rv->fdsize; 299 return rv->fdsize;
300} 300}