Merge lp:~schuster/mysql-proxy/remove_unix_socket into lp:mysql-proxy
- remove_unix_socket
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 1081 |
Proposed branch: | lp:~schuster/mysql-proxy/remove_unix_socket |
Merge into: | lp:mysql-proxy |
Diff against target: |
231 lines (+130/-5) 4 files modified
src/network-address.c (+28/-1) src/network-address.h (+1/-1) src/network-socket.c (+1/-0) tests/unit/t_network_socket.c (+100/-3) |
To merge this branch: | bzr merge lp:~schuster/mysql-proxy/remove_unix_socket |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jan Kneschke (community) | Approve | ||
Review via email: mp+23652@code.launchpad.net |
Commit message
Description of the change
Jan Kneschke (jan-kneschke) wrote : | # |
Michael Schuster (schuster) wrote : | # |
On 04/19/10 09:39, Jan Kneschke wrote:
> Am 19.04.2010 um 08:48 schrieb Michael Schuster:
>
>> Michael Schuster has proposed merging lp:~schuster/mysql-proxy/remove_unix_socket into lp:mysql-proxy.
>>
>> Requested reviews:
>> MySQL Proxy Developers (mysql-
>>
>> --
>> https:/
>> Your team MySQL Proxy Developers is subscribed to branch lp:mysql-proxy.
>> === modified file 'src/network-
>> --- src/network-
>> +++ src/network-
>> @@ -45,6 +45,8 @@
>> #include <string.h>
>> #include <errno.h>
>> #include <fcntl.h>
>> +#include <glib.h>
>> +#include <glib/gstdio.h>
>>
>> #include "network-address.h"
>> #include "glib-ext.h"
>> @@ -63,10 +65,33 @@
>> }
>>
>> void network_
>> +
>> if (!addr) return;
>>
>> +#ifndef WIN32
>> + /*
>> + * if the name we're freeing starts with a '/', we're
>> + * looking at a unix socket which needs to be removed
>> + */
>> + if (addr->fail_errno == 0 && addr->name != NULL &&
>> + addr->name->str != NULL) {
>> + gchar *name;
>> + int ret;
>> +
>> + name = addr->name->str;
>> + if (name[0] == '/' && g_access(name, 0) == 0) {
>> + ret = g_remove(name);
>
> Only try to remove it if we can to hide the error-msg (aka noise) for it ?
sorry, don't understand the question :-(
>> +
>> + if (ret == 0)
>> + g_debug("%s removing socket %s successful",
>> + G_STRLOC, name);
>> + else
>> + g_debug("%s removing socket %s failed: %s (%d)",
>> + G_STRLOC, name, strerror(errno));
>
> ... in that case the g_debug() is perhaps better a g_critical() ?
ok.
Michael
- 1049. By Michael Schuster
-
change warning level for failure to remove socket
Jan Kneschke (jan-kneschke) wrote : | # |
Am 19.04.2010 um 10:45 schrieb Michael Schuster:
> On 04/19/10 09:39, Jan Kneschke wrote:
>> Am 19.04.2010 um 08:48 schrieb Michael Schuster:
>>
>>> Michael Schuster has proposed merging lp:~schuster/mysql-proxy/remove_unix_socket into lp:mysql-proxy.
>>>
>>> Requested reviews:
>>> MySQL Proxy Developers (mysql-
>>>
>>> --
>>> https:/
>>> Your team MySQL Proxy Developers is subscribed to branch lp:mysql-proxy.
>>> === modified file 'src/network-
>>> --- src/network-
>>> +++ src/network-
>>> @@ -45,6 +45,8 @@
>>> #include <string.h>
>>> #include <errno.h>
>>> #include <fcntl.h>
>>> +#include <glib.h>
>>> +#include <glib/gstdio.h>
>>>
>>> #include "network-address.h"
>>> #include "glib-ext.h"
>>> @@ -63,10 +65,33 @@
>>> }
>>>
>>> void network_
>>> +
>>> if (!addr) return;
>>>
>>> +#ifndef WIN32
>>> + /*
>>> + * if the name we're freeing starts with a '/', we're
>>> + * looking at a unix socket which needs to be removed
>>> + */
>>> + if (addr->fail_errno == 0 && addr->name != NULL &&
>>> + addr->name->str != NULL) {
>>> + gchar *name;
>>> + int ret;
>>> +
>>> + name = addr->name->str;
>>> + if (name[0] == '/' && g_access(name, 0) == 0) {
>>> + ret = g_remove(name);
>>
>> Only try to remove it if we can to hide the error-msg (aka noise) for it ?
>
> sorry, don't understand the question :-(
I tried to figure out the reason for the g_access() and assumed it is to check if the g_remove() could succeed without a permission problem.
Problem with access() is that it creates a race-condition before the the permission check and the g_remove(). Instead just unlink() it and check for the 'errno != EPERM' to see if we can't delete the socket as we drop the privileges.
>>> +
>>> + if (ret == 0)
>>> + g_debug("%s removing socket %s successful",
>>> + G_STRLOC, name);
>>> + else
>>> + g_debug("%s removing socket %s failed: %s (%d)",
>>> + G_STRLOC, name, strerror(errno));
>>
>> ... in that case the g_debug() is perhaps better a g_critical() ?
>
> ok.
The whole patch does unlink() any file that is set as address. In the case of a network_
Instead of ->fail_errno use a gboolean to track if you want to unlink the socket file on free and only set it to true in the case of a successful network_
> Michael
> --
> https:/
> Your team MySQL Proxy Developers is subscribed to branch lp:mysql-proxy.
Jan Kneschke (jan-kneschke) wrote : | # |
A test-case to verify that we don't unlink() socket-files we havn't bound
1 | === modified file 'tests/unit/t_network_address.c' | |||
2 | --- tests/unit/t_network_address.c revid:michael.schuster@oracle.com-20100423113047-u7cepgr9b32hgxag | |||
3 | +++ tests/unit/t_network_address.c 2010-04-28 07:07:30 +0000 | |||
4 | @@ -21,9 +21,14 @@ | |||
5 | 21 | #include <stdio.h> | 21 | #include <stdio.h> |
6 | 22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
7 | 23 | #include <string.h> | 23 | #include <string.h> |
8 | 24 | #include <fcntl.h> | ||
9 | 24 | 25 | ||
10 | 25 | #include <glib.h> | 26 | #include <glib.h> |
11 | 26 | 27 | ||
12 | 28 | #ifndef _WIN32 | ||
13 | 29 | #include <unistd.h> | ||
14 | 30 | #endif | ||
15 | 31 | |||
16 | 27 | #include "network-socket.h" | 32 | #include "network-socket.h" |
17 | 28 | 33 | ||
18 | 29 | #if GLIB_CHECK_VERSION(2, 16, 0) | 34 | #if GLIB_CHECK_VERSION(2, 16, 0) |
19 | @@ -80,6 +85,38 @@ | |||
20 | 80 | network_address_free(addr); | 85 | network_address_free(addr); |
21 | 81 | } | 86 | } |
22 | 82 | 87 | ||
23 | 88 | /** | ||
24 | 89 | * test if we decode the port number correctly | ||
25 | 90 | */ | ||
26 | 91 | void t_network_address_free_unix_socket() { | ||
27 | 92 | network_address *addr; | ||
28 | 93 | int fd; | ||
29 | 94 | |||
30 | 95 | #define TESTFILE "/tmp/mysql-proxy-t_network_address_free_unix_socket.sock" | ||
31 | 96 | unlink(TESTFILE); /* remove the file if a previous test-run failed */ | ||
32 | 97 | |||
33 | 98 | /* create the test-file */ | ||
34 | 99 | fd = open(TESTFILE, O_RDONLY | O_CREAT | O_EXCL, 0600); | ||
35 | 100 | if (fd != -1) close(fd); | ||
36 | 101 | |||
37 | 102 | g_assert_cmpint(fd, >, 0); /* creating the file should have succeeded */ | ||
38 | 103 | |||
39 | 104 | addr = network_address_new(); | ||
40 | 105 | network_address_set_address(addr, TESTFILE); | ||
41 | 106 | |||
42 | 107 | network_address_free(addr); /* the free shouldn't remove the file as we didn't call bind() on it */ | ||
43 | 108 | |||
44 | 109 | /* file should still be there */ | ||
45 | 110 | fd = open(TESTFILE, O_RDONLY); | ||
46 | 111 | if (fd != -1) close(fd); | ||
47 | 112 | |||
48 | 113 | g_assert_cmpint(fd, >, 0); | ||
49 | 114 | |||
50 | 115 | unlink(TESTFILE); /* cleanup */ | ||
51 | 116 | #undef TESTFILE | ||
52 | 117 | } | ||
53 | 118 | |||
54 | 119 | |||
55 | 83 | 120 | ||
56 | 84 | int main(int argc, char **argv) { | 121 | int main(int argc, char **argv) { |
57 | 85 | g_test_init(&argc, &argv, NULL); | 122 | g_test_init(&argc, &argv, NULL); |
58 | @@ -88,6 +125,7 @@ | |||
59 | 88 | g_test_add_func("/core/network_address_new", t_network_address_new); | 125 | g_test_add_func("/core/network_address_new", t_network_address_new); |
60 | 89 | g_test_add_func("/core/network_address_set", t_network_address_set); | 126 | g_test_add_func("/core/network_address_set", t_network_address_set); |
61 | 90 | g_test_add_func("/core/network_address_resolve", t_network_address_resolve); | 127 | g_test_add_func("/core/network_address_resolve", t_network_address_resolve); |
62 | 128 | g_test_add_func("/core/network_address_free_unix_socket", t_network_address_free_unix_socket); | ||
63 | 91 | 129 | ||
64 | 92 | return g_test_run(); | 130 | return g_test_run(); |
65 | 93 | } | 131 | } |
- 1050. By Michael Schuster
-
remove unix socket at shutdown: remove race window, make logic for "remove the once we created only" better
- 1051. By Michael Schuster
-
add check for local socket removal to "is local" testcase
- 1052. By Michael Schuster
-
make sure socket is removed if assertion fails: add sig handler for SIGARBT
Jan Kneschke (jan-kneschke) wrote : | # |
* remove the commented lines:
/* printf("debug: socket name is %s (addr: %p)\n", pp->sockname, pp); */
/* g_test_
* stay with the existing coding style (no line-break after function declarations)
* The signal-handler for SIGABRT is installed for _all_ tests of this test-suite. Instead it should be added in the setup and turned back into SIG_DFL in teardown.
* void t_network_
Jan Kneschke (jan-kneschke) wrote : | # |
g_debug("%s removing socket %s successful", ... is missing a colon after the first %s
Jan Kneschke (jan-kneschke) : | # |
Michael Schuster (schuster) wrote : | # |
Jan,
thx for review, comments in-line.
On 04.05.10 13:50, Jan Kneschke wrote:
> * remove the commented lines:
>
> /* printf("debug: socket name is %s (addr: %p)\n", pp->sockname, pp); */
> /* g_test_
done
> * stay with the existing coding style (no line-break after function declarations)
ack, done.
> * The signal-handler for SIGABRT is installed for _all_ tests of this test-suite. Instead it should be added in the setup and turned back into SIG_DFL in teardown.
done
> * void t_network_
ack
> g_debug("%s removing socket %s successful", ... is missing a colon after the first %s
this is now gone.
Michael
--
Michael Schuster http://
Recursion, n.: see 'Recursion'
- 1053. By Michael Schuster
-
fix diversion
Jan Kneschke (jan-kneschke) wrote : | # |
approved. will merge it to trunk
Jan Kneschke (jan-kneschke) wrote : | # |
65 === modified file 'src/network-
66 --- src/network-
67 +++ src/network-
...
In static network_
76 @@ -660,6 +661,7 @@
77 }
78 }
79
80 + con->dst-
81 return NETWORK_
82 }
which would mean:
"unlink socket after successful write" which isn't what we want. Seems to a broken merge. The rest looks good.
- 1054. By Michael Schuster
-
mismerge fixed
Jan Kneschke (jan-kneschke) : | # |
Preview Diff
1 | === modified file 'src/network-address.c' | |||
2 | --- src/network-address.c 2010-04-07 12:44:32 +0000 | |||
3 | +++ src/network-address.c 2010-05-10 12:15:45 +0000 | |||
4 | @@ -45,6 +45,8 @@ | |||
5 | 45 | #include <string.h> | 45 | #include <string.h> |
6 | 46 | #include <errno.h> | 46 | #include <errno.h> |
7 | 47 | #include <fcntl.h> | 47 | #include <fcntl.h> |
8 | 48 | #include <glib.h> | ||
9 | 49 | #include <glib/gstdio.h> | ||
10 | 48 | 50 | ||
11 | 49 | #include "network-address.h" | 51 | #include "network-address.h" |
12 | 50 | #include "glib-ext.h" | 52 | #include "glib-ext.h" |
13 | @@ -63,10 +65,35 @@ | |||
14 | 63 | } | 65 | } |
15 | 64 | 66 | ||
16 | 65 | void network_address_free(network_address *addr) { | 67 | void network_address_free(network_address *addr) { |
17 | 68 | |||
18 | 66 | if (!addr) return; | 69 | if (!addr) return; |
19 | 67 | 70 | ||
20 | 71 | #ifndef WIN32 | ||
21 | 72 | /* | ||
22 | 73 | * if the name we're freeing starts with a '/', we're | ||
23 | 74 | * looking at a unix socket which needs to be removed | ||
24 | 75 | */ | ||
25 | 76 | if (addr->can_unlink_socket == TRUE && addr->name != NULL && | ||
26 | 77 | addr->name->str != NULL) { | ||
27 | 78 | gchar *name; | ||
28 | 79 | int ret; | ||
29 | 80 | |||
30 | 81 | name = addr->name->str; | ||
31 | 82 | if (name[0] == '/') { | ||
32 | 83 | ret = g_remove(name); | ||
33 | 84 | if (ret == 0) { | ||
34 | 85 | g_debug("%s: removing socket %s successful", | ||
35 | 86 | G_STRLOC, name); | ||
36 | 87 | } else { | ||
37 | 88 | if (errno != EPERM && errno != EACCES) | ||
38 | 89 | g_critical("%s: removing socket %s failed: %s (%d)", | ||
39 | 90 | G_STRLOC, name, strerror(errno)); | ||
40 | 91 | } | ||
41 | 92 | } | ||
42 | 93 | } | ||
43 | 94 | #endif /* WIN32 */ | ||
44 | 95 | |||
45 | 68 | g_string_free(addr->name, TRUE); | 96 | g_string_free(addr->name, TRUE); |
46 | 69 | |||
47 | 70 | g_free(addr); | 97 | g_free(addr); |
48 | 71 | } | 98 | } |
49 | 72 | 99 | ||
50 | 73 | 100 | ||
51 | === modified file 'src/network-address.h' | |||
52 | --- src/network-address.h 2010-04-06 14:26:51 +0000 | |||
53 | +++ src/network-address.h 2010-05-10 12:15:45 +0000 | |||
54 | @@ -63,8 +63,8 @@ | |||
55 | 63 | } addr; | 63 | } addr; |
56 | 64 | 64 | ||
57 | 65 | GString *name; | 65 | GString *name; |
58 | 66 | |||
59 | 67 | network_socklen_t len; | 66 | network_socklen_t len; |
60 | 67 | gboolean can_unlink_socket; /* set TRUE *only* after successful bind */ | ||
61 | 68 | } network_address; | 68 | } network_address; |
62 | 69 | 69 | ||
63 | 70 | NETWORK_API network_address *network_address_new(void); | 70 | NETWORK_API network_address *network_address_new(void); |
64 | 71 | 71 | ||
65 | === modified file 'src/network-socket.c' | |||
66 | --- src/network-socket.c 2010-05-03 14:26:32 +0000 | |||
67 | +++ src/network-socket.c 2010-05-10 12:15:45 +0000 | |||
68 | @@ -431,6 +431,7 @@ | |||
69 | 431 | } | 431 | } |
70 | 432 | } | 432 | } |
71 | 433 | 433 | ||
72 | 434 | con->dst->can_unlink_socket = TRUE; | ||
73 | 434 | return NETWORK_SOCKET_SUCCESS; | 435 | return NETWORK_SOCKET_SUCCESS; |
74 | 435 | } | 436 | } |
75 | 436 | 437 | ||
76 | 437 | 438 | ||
77 | === modified file 'tests/unit/t_network_socket.c' | |||
78 | --- tests/unit/t_network_socket.c 2010-04-07 12:44:32 +0000 | |||
79 | +++ tests/unit/t_network_socket.c 2010-05-10 12:15:45 +0000 | |||
80 | @@ -23,6 +23,12 @@ | |||
81 | 23 | #include <string.h> | 23 | #include <string.h> |
82 | 24 | #include <errno.h> | 24 | #include <errno.h> |
83 | 25 | 25 | ||
84 | 26 | #ifndef WIN32 | ||
85 | 27 | #include <unistd.h> | ||
86 | 28 | #include <stdlib.h> | ||
87 | 29 | #include <fcntl.h> | ||
88 | 30 | #endif /* WIN32 */ | ||
89 | 31 | |||
90 | 26 | #include <glib.h> | 32 | #include <glib.h> |
91 | 27 | #include <glib/gstdio.h> /* for g_unlink */ | 33 | #include <glib/gstdio.h> /* for g_unlink */ |
92 | 28 | 34 | ||
93 | @@ -31,6 +37,17 @@ | |||
94 | 31 | #if GLIB_CHECK_VERSION(2, 16, 0) | 37 | #if GLIB_CHECK_VERSION(2, 16, 0) |
95 | 32 | #define C(x) x, sizeof(x) - 1 | 38 | #define C(x) x, sizeof(x) - 1 |
96 | 33 | 39 | ||
97 | 40 | #ifndef WIN32 | ||
98 | 41 | #define LOCAL_SOCK "/tmp/mysql-proxy-test.socket" | ||
99 | 42 | |||
100 | 43 | typedef struct { | ||
101 | 44 | char sockname[sizeof(LOCAL_SOCK) + 10]; | ||
102 | 45 | } local_unix_t; | ||
103 | 46 | |||
104 | 47 | static local_unix_t *pp = NULL; | ||
105 | 48 | static local_unix_t local_test_arg; | ||
106 | 49 | #endif /* WIN32 */ | ||
107 | 50 | |||
108 | 34 | void test_network_socket_new() { | 51 | void test_network_socket_new() { |
109 | 35 | network_socket *sock; | 52 | network_socket *sock; |
110 | 36 | 53 | ||
111 | @@ -295,6 +312,8 @@ | |||
112 | 295 | network_socket_free(server); | 312 | network_socket_free(server); |
113 | 296 | } | 313 | } |
114 | 297 | 314 | ||
115 | 315 | #ifndef WIN32 | ||
116 | 316 | |||
117 | 298 | /** | 317 | /** |
118 | 299 | * test if _is_local() works on unix-domain sockets | 318 | * test if _is_local() works on unix-domain sockets |
119 | 300 | * | 319 | * |
120 | @@ -314,6 +333,7 @@ | |||
121 | 314 | c_sock = network_socket_new(); | 333 | c_sock = network_socket_new(); |
122 | 315 | network_address_set_address(c_sock->dst, "/tmp/mysql-proxy-test.socket"); | 334 | network_address_set_address(c_sock->dst, "/tmp/mysql-proxy-test.socket"); |
123 | 316 | 335 | ||
124 | 336 | |||
125 | 317 | /* hack together a network_socket_accept() which we don't have in this tree yet */ | 337 | /* hack together a network_socket_accept() which we don't have in this tree yet */ |
126 | 318 | g_assert_cmpint(NETWORK_SOCKET_SUCCESS, ==, network_socket_bind(s_sock)); | 338 | g_assert_cmpint(NETWORK_SOCKET_SUCCESS, ==, network_socket_bind(s_sock)); |
127 | 319 | 339 | ||
128 | @@ -331,6 +351,76 @@ | |||
129 | 331 | g_unlink("/tmp/mysql-proxy-test.socket"); | 351 | g_unlink("/tmp/mysql-proxy-test.socket"); |
130 | 332 | } | 352 | } |
131 | 333 | 353 | ||
132 | 354 | void t_network_localsocket_setup(local_unix_t *p) { | ||
133 | 355 | g_assert(p != NULL); | ||
134 | 356 | snprintf(p->sockname, sizeof(p->sockname), LOCAL_SOCK ".%d", (int)getpid()); | ||
135 | 357 | pp = p; | ||
136 | 358 | } | ||
137 | 359 | |||
138 | 360 | void t_network_localsocket_teardown(local_unix_t *p) { | ||
139 | 361 | g_assert(p != NULL); | ||
140 | 362 | if (p->sockname[0] != '\0') { | ||
141 | 363 | (void) g_unlink(p->sockname); | ||
142 | 364 | p->sockname[0] = '\0'; | ||
143 | 365 | } | ||
144 | 366 | pp = NULL; | ||
145 | 367 | } | ||
146 | 368 | |||
147 | 369 | void exitfunc(int sig) { | ||
148 | 370 | if (pp != NULL && pp->sockname[0] != '\0') | ||
149 | 371 | (void) g_unlink(pp->sockname); | ||
150 | 372 | |||
151 | 373 | abort(); | ||
152 | 374 | } | ||
153 | 375 | |||
154 | 376 | /** | ||
155 | 377 | * test if local sockets are removed at shutdown | ||
156 | 378 | * this is an extension of _is_local_unix(), therefore looks much like it; | ||
157 | 379 | * just in case, we leave all tests from that function in as well. | ||
158 | 380 | */ | ||
159 | 381 | void t_network_socket_rem_local_unix(local_unix_t *p) { | ||
160 | 382 | network_socket *s_sock; /* the server side socket, listening for requests */ | ||
161 | 383 | network_socket *c_sock; /* the client side socket, that connects */ | ||
162 | 384 | network_socket *a_sock; /* the server side, accepted socket */ | ||
163 | 385 | |||
164 | 386 | /* | ||
165 | 387 | * if an assertion fails, we receive the ABORT signal. We need to | ||
166 | 388 | * close the unix socket in that case too. The regular teardown function | ||
167 | 389 | * is not called in this case, so we install our own handler. | ||
168 | 390 | */ | ||
169 | 391 | signal(SIGABRT, exitfunc); | ||
170 | 392 | g_test_bug("42220"); | ||
171 | 393 | g_log_set_always_fatal(G_LOG_FATAL_MASK); /* gtest modifies the fatal-mask */ | ||
172 | 394 | |||
173 | 395 | s_sock = network_socket_new(); | ||
174 | 396 | network_address_set_address(s_sock->dst, p->sockname); | ||
175 | 397 | |||
176 | 398 | c_sock = network_socket_new(); | ||
177 | 399 | network_address_set_address(c_sock->dst, p->sockname); | ||
178 | 400 | |||
179 | 401 | g_assert_cmpint(NETWORK_SOCKET_SUCCESS, ==, network_socket_bind(s_sock)); | ||
180 | 402 | |||
181 | 403 | g_assert_cmpint(g_access(p->sockname, 0), ==, 0); | ||
182 | 404 | |||
183 | 405 | g_assert_cmpint(NETWORK_SOCKET_SUCCESS, ==, network_socket_connect(c_sock)); | ||
184 | 406 | |||
185 | 407 | a_sock = network_socket_accept(s_sock); | ||
186 | 408 | g_assert(a_sock); | ||
187 | 409 | |||
188 | 410 | g_assert_cmpint(TRUE, ==, network_address_is_local(s_sock->dst, a_sock->dst)); | ||
189 | 411 | |||
190 | 412 | network_socket_free(a_sock); | ||
191 | 413 | g_assert_cmpint(g_access(p->sockname, 0), ==, 0); | ||
192 | 414 | network_socket_free(c_sock); | ||
193 | 415 | g_assert_cmpint(g_access(p->sockname, 0), ==, 0); | ||
194 | 416 | network_socket_free(s_sock); | ||
195 | 417 | g_assert_cmpint(g_access(p->sockname, 0), ==, -1); | ||
196 | 418 | |||
197 | 419 | /* re-establish default signal disposition */ | ||
198 | 420 | signal(SIGABRT, SIG_DFL); | ||
199 | 421 | } | ||
200 | 422 | |||
201 | 423 | #endif /* WIN32 */ | ||
202 | 334 | 424 | ||
203 | 335 | int main(int argc, char **argv) { | 425 | int main(int argc, char **argv) { |
204 | 336 | g_test_init(&argc, &argv, NULL); | 426 | g_test_init(&argc, &argv, NULL); |
205 | @@ -342,7 +432,14 @@ | |||
206 | 342 | g_test_add_func("/core/network_queue_append", test_network_queue_append); | 432 | g_test_add_func("/core/network_queue_append", test_network_queue_append); |
207 | 343 | g_test_add_func("/core/network_queue_peek_string", test_network_queue_peek_string); | 433 | g_test_add_func("/core/network_queue_peek_string", test_network_queue_peek_string); |
208 | 344 | g_test_add_func("/core/network_queue_pop_string", test_network_queue_pop_string); | 434 | g_test_add_func("/core/network_queue_pop_string", test_network_queue_pop_string); |
210 | 345 | g_test_add_func("/core/network_socket_is_local_unix", t_network_socket_is_local_unix); | 435 | #ifndef WIN32 |
211 | 436 | g_test_add_func("/core/network_socket_is_local_unix",t_network_socket_is_local_unix); | ||
212 | 437 | |||
213 | 438 | g_test_add("/core/network_socket_rem_local_unix", local_unix_t, | ||
214 | 439 | &local_test_arg, | ||
215 | 440 | t_network_localsocket_setup, t_network_socket_rem_local_unix, | ||
216 | 441 | t_network_localsocket_teardown); | ||
217 | 442 | #endif /* WIN32 */ | ||
218 | 346 | #if 0 | 443 | #if 0 |
219 | 347 | /** | 444 | /** |
220 | 348 | * disabled for now until we fixed the _to_read() on HP/UX and AIX (and MacOS X) | 445 | * disabled for now until we fixed the _to_read() on HP/UX and AIX (and MacOS X) |
221 | @@ -354,8 +451,8 @@ | |||
222 | 354 | 451 | ||
223 | 355 | return g_test_run(); | 452 | return g_test_run(); |
224 | 356 | } | 453 | } |
226 | 357 | #else | 454 | #else /* GLIB_CHECK_VERSION */ |
227 | 358 | int main() { | 455 | int main() { |
228 | 359 | return 77; | 456 | return 77; |
229 | 360 | } | 457 | } |
231 | 361 | #endif | 458 | #endif /* GLIB_CHECK_VERSION */ |
Am 19.04.2010 um 08:48 schrieb Michael Schuster:
> Michael Schuster has proposed merging lp:~schuster/mysql-proxy/remove_unix_socket into lp:mysql-proxy. proxy-developer s) /code.launchpad .net/~schuster/ mysql-proxy/ remove_ unix_socket/ +merge/ 23652 address. c' address. c 2010-04-07 12:44:32 +0000 address. c 2010-04-19 06:48:19 +0000 address_ free(network_ address *addr) {
>
> Requested reviews:
> MySQL Proxy Developers (mysql-
>
> --
> https:/
> Your team MySQL Proxy Developers is subscribed to branch lp:mysql-proxy.
> === modified file 'src/network-
> --- src/network-
> +++ src/network-
> @@ -45,6 +45,8 @@
> #include <string.h>
> #include <errno.h>
> #include <fcntl.h>
> +#include <glib.h>
> +#include <glib/gstdio.h>
>
> #include "network-address.h"
> #include "glib-ext.h"
> @@ -63,10 +65,33 @@
> }
>
> void network_
> +
> if (!addr) return;
>
> +#ifndef WIN32
> + /*
> + * if the name we're freeing starts with a '/', we're
> + * looking at a unix socket which needs to be removed
> + */
> + if (addr->fail_errno == 0 && addr->name != NULL &&
> + addr->name->str != NULL) {
> + gchar *name;
> + int ret;
> +
> + name = addr->name->str;
> + if (name[0] == '/' && g_access(name, 0) == 0) {
> + ret = g_remove(name);
Only try to remove it if we can to hide the error-msg (aka noise) for it ?
> +
> + if (ret == 0)
> + g_debug("%s removing socket %s successful",
> + G_STRLOC, name);
> + else
> + g_debug("%s removing socket %s failed: %s (%d)",
> + G_STRLOC, name, strerror(errno));
... in that case the g_debug() is perhaps better a g_critical() ?
> + } free(addr- >name, TRUE); address. h' address. h 2010-04-06 14:26:51 +0000 address. h 2010-04-19 06:48:19 +0000 address_ new(void) ; socket. c' socket. c 2010-04-06 14:26:51 +0000 socket. c 2010-04-19 06:48:19 +0000 >name-> str, >fail_errno = errno; /* if a unix socket, this tells us "don't remove" */ SOCKET_ ERROR;
> + }
> +#endif /* WIN32 */
> +
> g_string_
> -
> g_free(addr);
> }
>
>
> === modified file 'src/network-
> --- src/network-
> +++ src/network-
> @@ -63,8 +63,8 @@
> } addr;
>
> GString *name;
> -
> network_socklen_t len;
> + int fail_errno; /* != 0: don't remove ... I guess */
> } network_address;
>
> NETWORK_API network_address *network_
>
> === modified file 'src/network-
> --- src/network-
> +++ src/network-
> @@ -397,6 +397,7 @@
> G_STRLOC,
> con->dst-
> g_strerror(errno), errno);
> + con->dst-
> return NETWORK_
> }
>
>