]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock_inet: report the errno string in binding errors
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Sep 2020 06:32:17 +0000 (08:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Sep 2020 06:32:17 +0000 (08:32 +0200)
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

index 7c814d05591af0f69270d5d882f9df1e4d4cf04e..3b7b0feff4384b79ce3aef268fac59830d44bf3a 100644 (file)
@@ -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;
        }