From 0f0cc88589aea634cd66121fd0f473520f86e143 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 22 Aug 2013 13:02:59 +0200 Subject: [PATCH] Print error message when can't bind * on any address. --- src/redis.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/redis.c b/src/redis.c index 036fba7a..6ef2da1f 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1508,8 +1508,7 @@ void initServer() { for (j = 0; j < server.bindaddr_count || j == 0; j++) { if (server.bindaddr[j] == NULL) { /* Bind * for both IPv6 and IPv4, we enter here only if - * server.bindaddr_count == 0, so we try to bind and then - * break to exit the loop ASAP. */ + * server.bindaddr_count == 0. */ server.ipfd[server.ipfd_count] = anetTcp6Server(server.neterr,server.port,NULL); if (server.ipfd[server.ipfd_count] != ANET_ERR) @@ -1518,7 +1517,10 @@ void initServer() { anetTcpServer(server.neterr,server.port,NULL); if(server.ipfd[server.ipfd_count] != ANET_ERR) server.ipfd_count++; - break; + /* Exit the loop if we were able to bind * on IPv4 or IPv6, + * otherwise server.ipfd[server.ipfd_count] will be ANET_ERR + * and we'll print an error and exit. */ + if (server.ipfd_count) break; } else if (strchr(server.bindaddr[j],':')) { /* Bind IPv6 address. */ server.ipfd[server.ipfd_count] = anetTcp6Server(server.neterr,server.port,server.bindaddr[j]); -- GitLab