Move errno-protection into string_open_failed()
[exim.git] / src / src / tls-gnu.c
index fa489902a923229e33d48cdb1f892215a95be526..6308f10df4d00bb29ef55b0f88c8365a200dbe3d 100644 (file)
@@ -424,11 +424,16 @@ record_io_error(exim_gnutls_state_st *state, int rc, uschar *when, uschar *text)
 const uschar * msg;
 uschar * errstr;
 
-if (rc == GNUTLS_E_FATAL_ALERT_RECEIVED)
-  msg = string_sprintf("A TLS fatal alert has been received: %s",
-    US gnutls_alert_get_name(gnutls_alert_get(state->session)));
-else
-  msg = US gnutls_strerror(rc);
+msg = rc == GNUTLS_E_FATAL_ALERT_RECEIVED
+  ? string_sprintf("A TLS fatal alert has been received: %s",
+      US gnutls_alert_get_name(gnutls_alert_get(state->session)))
+#ifdef GNUTLS_E_PREMATURE_TERMINATION
+  : rc == GNUTLS_E_PREMATURE_TERMINATION && errno
+  ? errno == ECONNRESET                /* Outlook does this to us right after sending us QUIT */
+  ? string_sprintf("syscall: %s", strerror(errno))
+  : string_sprintf("%s: syscall: %s", US gnutls_strerror(rc), strerror(errno))
+#endif
+  : US gnutls_strerror(rc);
 
 (void) tls_error(when, msg, state->host, &errstr);
 
@@ -723,7 +728,7 @@ else if (errno == ENOENT)
     debug_printf("D-H parameter cache file \"%s\" does not exist\n", filename);
   }
 else
-  return tls_error(string_open_failed(errno, "\"%s\" for reading", filename),
+  return tls_error(string_open_failed("\"%s\" for reading", filename),
       NULL, NULL, errstr);
 
 /* If ret < 0, either the cache file does not exist, or the data it contains