diff options
author | Max Kellermann <max@duempel.org> | 2009-06-10 08:01:07 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-06-10 08:01:07 +0200 |
commit | d5ddecb15a72aeb2beea4963af914ee828ce032b (patch) | |
tree | 90deb30579863ffa7446f972031bb564d82f7a41 /src | |
parent | 5bb8a5eeef1994238d90670160f6bec199d5dfab (diff) | |
download | mpd-d5ddecb15a72aeb2beea4963af914ee828ce032b.tar.gz mpd-d5ddecb15a72aeb2beea4963af914ee828ce032b.tar.xz mpd-d5ddecb15a72aeb2beea4963af914ee828ce032b.zip |
listen: bind() failure on secondary address is non-fatal
Several users had problems with binding MPD to "localhost". The cause
was duplicate /etc/hosts entries: the resolver library returns
127.0.0.1 twice, and of course, MPD attempts to bind to "both" of
them. This patch makes failures non-fatal, given that at least one
address was bound successfully. This is a workaround; users should
rather fix their /etc/hosts file.
Diffstat (limited to '')
-rw-r--r-- | src/listen.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/listen.c b/src/listen.c index 173ec762d..98108d9da 100644 --- a/src/listen.c +++ b/src/listen.c @@ -247,10 +247,32 @@ listen_add_host(const char *hostname, unsigned port, GError **error_r) } for (i = ai; i != NULL; i = i->ai_next) { + GError *error = NULL; + success = listen_add_address(i->ai_family, i->ai_addr, - i->ai_addrlen, error_r); - if (!success) - return false; + i->ai_addrlen, &error); + if (!success) { + if (i == ai) { + /* first bind has failed: fatal + error */ + g_propagate_error(error_r, error); + return false; + } else { + char *address_string = + sockaddr_to_string(i->ai_addr, + i->ai_addrlen, + NULL); + if (address_string == NULL) + address_string = g_strdup("[unknown]"); + + g_warning("bind to %s failed: %s " + "(continuing anyway, because at " + "least one address is bound)", + address_string, error->message); + g_free(address_string); + g_error_free(error); + } + } } freeaddrinfo(ai); |