| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sdp_service.c,v 1.3 2010/11/13 19:43:56 plunky Exp $ */ | | 1 | /* $NetBSD: sdp_service.c,v 1.4 2010/11/20 12:12:21 plunky Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2009 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 Iain Hibbert. | | 8 | * by Iain Hibbert. |
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. |
| @@ -20,59 +20,60 @@ | | | @@ -20,59 +20,60 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __RCSID("$NetBSD: sdp_service.c,v 1.3 2010/11/13 19:43:56 plunky Exp $"); | | 33 | __RCSID("$NetBSD: sdp_service.c,v 1.4 2010/11/20 12:12:21 plunky Exp $"); |
| | | 34 | |
| | | 35 | #include <sys/atomic.h> |
34 | | | 36 | |
35 | #include <errno.h> | | 37 | #include <errno.h> |
36 | #include <limits.h> | | 38 | #include <limits.h> |
37 | #include <sdp.h> | | 39 | #include <sdp.h> |
38 | #include <stdlib.h> | | 40 | #include <stdlib.h> |
39 | #include <string.h> | | 41 | #include <string.h> |
40 | #include <unistd.h> | | 42 | #include <unistd.h> |
41 | | | 43 | |
42 | #include "sdp-int.h" | | 44 | #include "sdp-int.h" |
43 | | | 45 | |
44 | /* | | 46 | /* |
45 | * If AttributeIDList is given as NULL, request all attributes. | | 47 | * If AttributeIDList is given as NULL, request all attributes. |
| | | 48 | * (this is actually const data but we can't declare it const) |
46 | */ | | 49 | */ |
47 | static uint8_t ail_default[] = { 0x0a, 0x00, 0x00, 0xff, 0xff }; | | 50 | static uint8_t ail_default[] = { 0x0a, 0x00, 0x00, 0xff, 0xff }; |
48 | | | 51 | |
49 | /* | | 52 | /* |
50 | * This provides the maximum size that the response buffer will be | | 53 | * This provides the maximum size that the response buffer will be |
51 | * allowed to grow to. | | 54 | * allowed to grow to. |
52 | * | | 55 | * |
53 | * Default is UINT16_MAX but it can be overridden at runtime. | | 56 | * Default is UINT16_MAX but it can be overridden at runtime. |
54 | */ | | 57 | */ |
55 | static size_t | | 58 | static size_t |
56 | sdp_response_max(void) | | 59 | sdp_response_max(void) |
57 | { | | 60 | { |
58 | static size_t max = UINT16_MAX; | | 61 | static size_t max = UINT16_MAX; |
59 | static bool check = true; | | 62 | static unsigned int check = 1; |
60 | char *env, *ep; | | 63 | char *env, *ep; |
61 | unsigned long v; | | 64 | unsigned long v; |
62 | | | 65 | |
63 | while (check) { | | 66 | while (atomic_swap_uint(&check, 0)) { /* only check env once */ |
64 | check = false; /* only check env once */ | | | |
65 | | | | |
66 | env = getenv("SDP_RESPONSE_MAX"); | | 67 | env = getenv("SDP_RESPONSE_MAX"); |
67 | if (env == NULL) | | 68 | if (env == NULL) |
68 | break; | | 69 | break; |
69 | | | 70 | |
70 | errno = 0; | | 71 | errno = 0; |
71 | v = strtoul(env, &ep, 0); | | 72 | v = strtoul(env, &ep, 0); |
72 | if (env[0] == '\0' || *ep != '\0') | | 73 | if (env[0] == '\0' || *ep != '\0') |
73 | break; | | 74 | break; |
74 | | | 75 | |
75 | if (errno == ERANGE && v == ULONG_MAX) | | 76 | if (errno == ERANGE && v == ULONG_MAX) |
76 | break; | | 77 | break; |
77 | | | 78 | |
78 | /* lower limit is arbitrary */ | | 79 | /* lower limit is arbitrary */ |