From 829dd84217ed9c32fda88a4ca2cb20b41c950f1e Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Tue, 31 Jan 2017 21:38:22 +0000 Subject: [PATCH] Fix error logged for send failure Broken-by: de6273b487f1 --- src/src/debug.c | 8 ++++++-- src/src/transports/smtp.c | 12 ++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/src/debug.c b/src/src/debug.c index cc60b44a6..8f9359b15 100644 --- a/src/src/debug.c +++ b/src/src/debug.c @@ -143,7 +143,8 @@ If debug_pid is nonzero, print the pid at the start of each line. This is for tidier output when running parallel remote deliveries with debugging turned on. Must do the whole thing with a single printf and flush, as otherwise output may get interleaved. Since some calls to debug_printf() don't end with newline, -we save up the text until we do get the newline. */ +we save up the text until we do get the newline. +Take care to not disturb errno. */ void debug_printf(const char *format, ...) @@ -157,7 +158,9 @@ va_end(ap); void debug_vprintf(const char *format, va_list ap) { -if (debug_file == NULL) return; +int save_errno = errno; + +if (!debug_file) return; /* Various things can be inserted at the start of a line. Don't use the tod_stamp() function for the timestamp, because that will overwrite the @@ -235,6 +238,7 @@ if (debug_ptr[-1] == '\n') debug_ptr = debug_buffer; debug_prefix_length = 0; } +errno = save_errno; } /* End of debug.c */ diff --git a/src/src/transports/smtp.c b/src/src/transports/smtp.c index 43b623513..e177ee9c3 100644 --- a/src/src/transports/smtp.c +++ b/src/src/transports/smtp.c @@ -1454,9 +1454,7 @@ smtp_setup_conn(smtp_context * sx, BOOL suppress_tls) dns_answer tlsa_dnsa; #endif BOOL pass_message = FALSE; - uschar * message = NULL; -int save_errno; int yield = OK; int rc; @@ -1551,14 +1549,13 @@ if (continue_hostname == NULL) if (sx->inblock.sock < 0) { uschar * msg = NULL; - int save_errno = errno; if (sx->verify) { msg = strerror(errno); HDEBUG(D_verify) debug_printf("connect: %s\n", msg); } set_errno_nohost(sx->addrlist, - save_errno == ETIMEDOUT ? ERRNO_CONNECTTIMEOUT : save_errno, + errno == ETIMEDOUT ? ERRNO_CONNECTTIMEOUT : errno, sx->verify ? string_sprintf("could not connect: %s", msg) : NULL, DEFER, FALSE); @@ -2104,13 +2101,13 @@ return OK; SEND_FAILED: code = '4'; message = US string_sprintf("send() to %s [%s] failed: %s", - sx->host->name, sx->host->address, strerror(save_errno)); + sx->host->name, sx->host->address, strerror(errno)); sx->send_quit = FALSE; goto FAILED; /* This label is jumped to directly when a TLS negotiation has failed, or was not done for a host for which it is required. Values will be set - in message and save_errno, and setting_up will always be true. Treat as + in message and errno, and setting_up will always be true. Treat as a temporary error. */ EHLOHELO_FAILED: @@ -2134,7 +2131,6 @@ return OK; tried again for a while. */ FAILED: - save_errno = errno; sx->ok = FALSE; /* For when reached by GOTO */ yield = code == '5' @@ -2143,7 +2139,7 @@ FAILED: #endif ? FAIL : DEFER; - set_errno(sx->addrlist, save_errno, message, yield, pass_message, sx->host + set_errno(sx->addrlist, errno, message, yield, pass_message, sx->host #ifdef EXPERIMENTAL_DSN_INFO , sx->smtp_greeting, sx->helo_response #endif -- 2.30.2