From e432967ff78b578d8cdc985a12490fd75ab01951 Mon Sep 17 00:00:00 2001 From: benno Date: Wed, 27 Dec 2017 15:53:30 +0000 Subject: [PATCH] log specific error when connect() fails. ok claudio@, feedback bluhm@ --- usr.sbin/relayd/relay.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 1681b2e5a2f..510d867c162 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.236 2017/11/28 01:51:47 claudio Exp $ */ +/* $OpenBSD: relay.c,v 1.237 2017/12/27 15:53:30 benno Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -661,6 +661,7 @@ relay_connected(int fd, short sig, void *arg) evbuffercb outwr = relay_write; struct bufferevent *bev; struct ctl_relay_event *out = &con->se_out; + char *msg; socklen_t len; int error; @@ -670,13 +671,23 @@ relay_connected(int fd, short sig, void *arg) } len = sizeof(error); - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, - &len) == -1 || error) { - if (error) - errno = error; - relay_abort_http(con, 500, "socket error", 0); + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) == -1) { + relay_abort_http(con, 500, "getsockopt failed", 0); return; } + if (error) { + errno = error; + if (asprintf(&msg, "socket error: %s", + strerror(error)) >= 0) { + relay_abort_http(con, 500, msg, 0); + free(msg); + return; + } else { + relay_abort_http(con, 500, + "socket error and asprintf failed", 0); + return; + } + } if ((rlay->rl_conf.flags & F_TLSCLIENT) && (out->tls == NULL)) { relay_tls_transaction(con, out); -- 2.20.1