From 36722d2274127ef91959296bb5299c8120b16ce7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 17 Sep 2020 08:32:17 +0200 Subject: [PATCH] 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] --- src/sock_inet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sock_inet.c b/src/sock_inet.c index 7c814d055..3b7b0feff 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; }