mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
MINOR: proto_uxst: copy errno in errmsg for syscalls
Let's copy errno in error messages, which we emit in cases when listen() or connect() fail. This is helpful for debugging.
This commit is contained in:
parent
16e89f6b5c
commit
9fc69ebc0a
@ -107,10 +107,16 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
|||||||
{
|
{
|
||||||
int fd, err;
|
int fd, err;
|
||||||
int ready;
|
int ready;
|
||||||
char *msg = NULL;
|
struct buffer *msg = alloc_trash_chunk();
|
||||||
|
|
||||||
err = ERR_NONE;
|
err = ERR_NONE;
|
||||||
|
|
||||||
|
if (!msg) {
|
||||||
|
if (errlen)
|
||||||
|
snprintf(errmsg, errlen, "out of memory");
|
||||||
|
return ERR_ALERT | ERR_FATAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* ensure we never return garbage */
|
/* ensure we never return garbage */
|
||||||
if (errlen)
|
if (errlen)
|
||||||
*errmsg = 0;
|
*errmsg = 0;
|
||||||
@ -119,7 +125,7 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
|||||||
return ERR_NONE; /* already bound */
|
return ERR_NONE; /* already bound */
|
||||||
|
|
||||||
if (!(listener->rx.flags & RX_F_BOUND)) {
|
if (!(listener->rx.flags & RX_F_BOUND)) {
|
||||||
msg = "receiving socket not bound";
|
chunk_appendf(msg, "receiving socket not bound");
|
||||||
err |= ERR_FATAL | ERR_ALERT;
|
err |= ERR_FATAL | ERR_ALERT;
|
||||||
goto uxst_return;
|
goto uxst_return;
|
||||||
}
|
}
|
||||||
@ -133,14 +139,14 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
|||||||
if (!ready && /* only listen if not already done by external process */
|
if (!ready && /* only listen if not already done by external process */
|
||||||
listen(fd, listener_backlog(listener)) < 0) {
|
listen(fd, listener_backlog(listener)) < 0) {
|
||||||
err |= ERR_FATAL | ERR_ALERT;
|
err |= ERR_FATAL | ERR_ALERT;
|
||||||
msg = "cannot listen to UNIX socket";
|
chunk_appendf(msg, "cannot listen on UNIX socket (%s)", strerror(errno));
|
||||||
goto uxst_close_return;
|
goto uxst_close_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
/* the socket is now listening */
|
/* the socket is now listening */
|
||||||
listener_set_state(listener, LI_LISTEN);
|
listener_set_state(listener, LI_LISTEN);
|
||||||
return err;
|
goto uxst_return;
|
||||||
|
|
||||||
uxst_close_return:
|
uxst_close_return:
|
||||||
fd_delete(fd);
|
fd_delete(fd);
|
||||||
@ -149,9 +155,11 @@ static int uxst_bind_listener(struct listener *listener, char *errmsg, int errle
|
|||||||
char *path_str;
|
char *path_str;
|
||||||
|
|
||||||
path_str = sa2str((struct sockaddr_storage *)&listener->rx.addr, 0, 0);
|
path_str = sa2str((struct sockaddr_storage *)&listener->rx.addr, 0, 0);
|
||||||
snprintf(errmsg, errlen, "%s for [%s]", msg, ((path_str) ? path_str : ""));
|
snprintf(errmsg, errlen, "%s for [%s]", msg->area, ((path_str) ? path_str : ""));
|
||||||
ha_free(&path_str);
|
ha_free(&path_str);
|
||||||
}
|
}
|
||||||
|
free_trash_chunk(msg);
|
||||||
|
msg = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,9 +277,9 @@ static int uxst_connect_server(struct connection *conn, int flags)
|
|||||||
conn->err_code = CO_ER_ADDR_INUSE;
|
conn->err_code = CO_ER_ADDR_INUSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
qfprintf(stderr,"Connect() failed for backend %s: %s.\n", be->id, msg);
|
qfprintf(stderr,"Connect() failed for backend %s: %s (%s).\n", be->id, msg, strerror(errno));
|
||||||
close(fd);
|
close(fd);
|
||||||
send_log(be, LOG_ERR, "Connect() failed for backend %s: %s.\n", be->id, msg);
|
send_log(be, LOG_ERR, "Connect() failed for backend %s: %s (%s).\n", be->id, msg, strerror(errno));
|
||||||
conn->flags |= CO_FL_ERROR;
|
conn->flags |= CO_FL_ERROR;
|
||||||
return SF_ERR_RESOURCE;
|
return SF_ERR_RESOURCE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user