From 7d1f4920efe33a4d025b9ba632ffbe73557d9636 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 9 Nov 2020 11:40:37 -0500 Subject: [PATCH] port: shutdown(2) can return ENOTCONN on FreeBSD MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit On FreeBSD shutdown(2) will return ENOTCONN when called on a disconnected socket which is not the case on Linux. It will however still run the shutdown code on the socket and wakeup threads waiting on the socket, so we can safely ignore this specific error. For more details see this bug report: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227259 Change-Id: I0046382ab996060f940dd1283d18447792cf1fd3 Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- src/common/unix.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/unix.cpp b/src/common/unix.cpp index 0a1b1a5a5..0548aaccb 100644 --- a/src/common/unix.cpp +++ b/src/common/unix.cpp @@ -379,7 +379,16 @@ int lttcomm_close_unix_sock(int sock) /* Shutdown receptions and transmissions */ ret = shutdown(sock, SHUT_RDWR); if (ret < 0) { - PERROR("shutdown"); + /* + * The socket is already disconnected, don't error out. + * This doesn't happen on Linux, but it does on FreeBSD, see: + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227259 + */ + if (errno == ENOTCONN) { + ret = 0; + } else { + PERROR("shutdown"); + } } closeret = close(sock); -- 2.34.1