From: Willy Tarreau Date: Thu, 17 Sep 2020 06:35:38 +0000 (+0200) Subject: MINOR: sock_unix: report the errno string in binding errors X-Git-Tag: v2.3-dev5~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3cd58bf80555fd22687a11672d5c0dd4c11c2089;p=thirdparty%2Fhaproxy.git MINOR: sock_unix: report the errno string in binding errors 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] --- diff --git a/src/sock_unix.c b/src/sock_unix.c index cf3e49cb50..a3056df934 100644 --- a/src/sock_unix.c +++ b/src/sock_unix.c @@ -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; }