- if (error_msg)
- ssh_sharing_logf(cs->parent->ssh, cs->id, "%s", error_msg);
+
+ if (error_msg) {
+#ifdef BROKEN_PIPE_ERROR_CODE
+ /*
+ * Most of the time, we log what went wrong when a downstream
+ * disappears with a socket error. One exception, though, is
+ * receiving EPIPE when we haven't received a protocol version
+ * string from the downstream, because that can happen as a result
+ * of plink -shareexists (opening the connection and instantly
+ * closing it again without bothering to read our version string).
+ * So that one case is not treated as a log-worthy error.
+ */
+ if (error_code == BROKEN_PIPE_ERROR_CODE && !cs->got_verstring)
+ /* do nothing */;
+ else
+#endif
+ ssh_sharing_logf(cs->parent->ssh, cs->id,
+ "Socket error: %s", error_msg);
+ }