]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sock_unix: report the errno string in binding errors
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Sep 2020 06:35:38 +0000 (08:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Sep 2020 06:35:38 +0000 (08:35 +0200)
Just like with previous patch, let's report UNIX socket binding errors
in plain text. we can now see for example:

  [ALERT] 260/083531 (13365) : Starting frontend f: cannot switch final and temporary UNIX sockets (Operation not permitted) [/tmp/root.sock]
  [ALERT] 260/083640 (13375) : Starting frontend f: cannot change UNIX socket ownership (Operation not permitted) [/tmp/root.sock]

src/sock_unix.c

index cf3e49cb50be2729bc8149af88f608ad798b9413..a3056df9347f1d6eccd057c7f1776657d213dde9 100644 (file)
@@ -178,20 +178,20 @@ int sock_unix_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
                /* 2. clean existing orphaned entries */
                if (unlink(tempname) < 0 && errno != ENOENT) {
                        err |= ERR_FATAL | ERR_ALERT;
-                       memprintf(errmsg, "error when trying to unlink previous UNIX socket");
+                       memprintf(errmsg, "error when trying to unlink previous UNIX socket (%s)", strerror(errno));
                        goto bind_return;
                }
 
                if (unlink(backname) < 0 && errno != ENOENT) {
                        err |= ERR_FATAL | ERR_ALERT;
-                       memprintf(errmsg, "error when trying to unlink previous UNIX socket");
+                       memprintf(errmsg, "error when trying to unlink previous UNIX socket (%s)", strerror(errno));
                        goto bind_return;
                }
 
                /* 3. backup existing socket */
                if (link(path, backname) < 0 && errno != ENOENT) {
                        err |= ERR_FATAL | ERR_ALERT;
-                       memprintf(errmsg, "error when trying to preserve previous UNIX socket");
+                       memprintf(errmsg, "error when trying to preserve previous UNIX socket (%s)", strerror(errno));
                        goto bind_return;
                }
 
@@ -222,7 +222,7 @@ int sock_unix_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
        fd = socket(rx->proto->fam->sock_domain, rx->proto->sock_type, rx->proto->sock_prot);
        if (fd < 0) {
                err |= ERR_FATAL | ERR_ALERT;
-               memprintf(errmsg, "cannot create receiving socket");
+               memprintf(errmsg, "cannot create receiving socket (%s)", strerror(errno));
                goto bind_return;
        }
 
@@ -249,7 +249,7 @@ int sock_unix_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
                }
                else {
                        err |= ERR_FATAL | ERR_ALERT;
-                       memprintf(errmsg, "cannot bind UNIX socket");
+                       memprintf(errmsg, "cannot bind UNIX socket (%s)", strerror(errno));
                        goto bind_close_return;
                }
                goto err_unlink_temp;
@@ -265,7 +265,7 @@ int sock_unix_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
              (chown(tempname, rx->settings->ux.uid, rx->settings->ux.gid) == -1)) ||
             (rx->settings->ux.mode != 0 && chmod(tempname, rx->settings->ux.mode) == -1))) {
                err |= ERR_FATAL | ERR_ALERT;
-               memprintf(errmsg, "cannot change UNIX socket ownership");
+               memprintf(errmsg, "cannot change UNIX socket ownership (%s)", strerror(errno));
                goto err_unlink_temp;
        }
 
@@ -275,7 +275,7 @@ int sock_unix_bind_receiver(struct receiver *rx, void (*handler)(int fd), char *
         */
        if (!ext && path[0] && rename(tempname, path) < 0) {
                err |= ERR_FATAL | ERR_ALERT;
-               memprintf(errmsg, "cannot switch final and temporary UNIX sockets");
+               memprintf(errmsg, "cannot switch final and temporary UNIX sockets (%s)", strerror(errno));
                goto err_rename;
        }