From: Willy Tarreau Date: Thu, 17 Sep 2020 06:32:17 +0000 (+0200) Subject: MINOR: sock_inet: report the errno string in binding errors X-Git-Tag: v2.3-dev5~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36722d227;p=thirdparty%2Fhaproxy.git MINOR: sock_inet: report the errno string in binding errors With the socket binding code cleanup it becomes easy to add more info to error messages. One missing thing used to be the error string, which is now added after the generic one, for example: [ALERT] 260/082852 (12974) : Starting frontend f: cannot bind socket (Permission denied) [0.0.0.0:4] [ALERT] 260/083053 (13292) : Starting frontend f: cannot bind socket (Address already in use) [0.0.0.0:4444] [ALERT] 260/083104 (13298) : Starting frontend f: cannot bind socket (Cannot assign requested address) [1.1.1.1:4444] --- diff --git a/src/sock_inet.c b/src/sock_inet.c index 7c814d0559..3b7b0feff4 100644 --- a/src/sock_inet.c +++ b/src/sock_inet.c @@ -293,7 +293,7 @@ int sock_inet_bind_receiver(struct receiver *rx, void (*handler)(int fd), char * rx->proto->sock_type, rx->proto->sock_prot); if (fd == -1) { err |= ERR_RETRYABLE | ERR_ALERT; - memprintf(errmsg, "cannot create receiving socket"); + memprintf(errmsg, "cannot create receiving socket (%s)", strerror(errno)); goto bind_return; } } @@ -347,7 +347,7 @@ int sock_inet_bind_receiver(struct receiver *rx, void (*handler)(int fd), char * if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, rx->settings->interface, strlen(rx->settings->interface) + 1) == -1) { - memprintf(errmsg, "cannot bind receiver to device"); + memprintf(errmsg, "cannot bind receiver to device (%s)", strerror(errno)); err |= ERR_WARN; } } @@ -369,7 +369,7 @@ int sock_inet_bind_receiver(struct receiver *rx, void (*handler)(int fd), char * if (!ext && bind(fd, (struct sockaddr *)&addr_inet, rx->proto->fam->sock_addrlen) == -1) { err |= ERR_RETRYABLE | ERR_ALERT; - memprintf(errmsg, "cannot bind socket"); + memprintf(errmsg, "cannot bind socket (%s)", strerror(errno)); goto bind_close_return; }