unix: don't unlink UNIX socket on EADDRINUSE
It was a bad idea to start with...
This commit is contained in:
parent
2e3e658be1
commit
3604b8ddd3
@ -81,22 +81,10 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
|
||||
uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
|
||||
saddr.sun_family = AF_UNIX;
|
||||
|
||||
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
|
||||
/* On EADDRINUSE:
|
||||
*
|
||||
* We hold the file lock so there is no other process listening
|
||||
* on the socket. Ergo, it's stale - remove it.
|
||||
*
|
||||
* This assumes that the other process uses locking too
|
||||
* but that's a good enough assumption for now.
|
||||
*/
|
||||
if (errno != EADDRINUSE
|
||||
|| unlink(pipe_fname) == -1
|
||||
|| bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
|
||||
/* Convert ENOENT to EACCES for compatibility with Windows. */
|
||||
uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno);
|
||||
goto out;
|
||||
}
|
||||
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
|
||||
/* Convert ENOENT to EACCES for compatibility with Windows. */
|
||||
uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno);
|
||||
goto out;
|
||||
}
|
||||
bound = 1;
|
||||
|
||||
|
||||
@ -27,8 +27,10 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
# define BAD_PIPENAME "bad-pipe"
|
||||
# define UNLINK_PIPE(name)
|
||||
#else
|
||||
# define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
|
||||
# define UNLINK_PIPE(name) remove(name)
|
||||
#endif
|
||||
|
||||
|
||||
@ -45,6 +47,8 @@ TEST_IMPL(pipe_bind_error_addrinuse) {
|
||||
uv_pipe_t server1, server2;
|
||||
int r;
|
||||
|
||||
UNLINK_PIPE(TEST_PIPENAME);
|
||||
|
||||
r = uv_pipe_init(uv_default_loop(), &server1, 0);
|
||||
ASSERT(r == 0);
|
||||
r = uv_pipe_bind(&server1, TEST_PIPENAME);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user