port: shutdown(2) can return ENOTCONN on FreeBSD
[lttng-tools.git] / src / common / unix.cpp
index 504970ea8ace30b19457aef27801bdbf91390b60..0548aaccbab6fccce6f98093cf7c98cceca4ebf7 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * SPDX-License-Identifier: GPL-2.0-only
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
  */
 
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <common/common.h>
-#include <common/compat/errno.h>
-#include <common/sessiond-comm/sessiond-comm.h>
-#include <common/fd-handle.h>
+#include <common/common.hpp>
+#include <common/compat/errno.hpp>
+#include <common/sessiond-comm/sessiond-comm.hpp>
+#include <common/fd-handle.hpp>
 
-#include "unix.h"
+#include "unix.hpp"
 
 /*
  * Connect to unix socket using the path name.
@@ -239,8 +239,11 @@ retry:
                        /*
                         * We consider EPIPE and EAGAIN/EWOULDBLOCK as expected.
                         */
+                       DIAGNOSTIC_PUSH
+                       DIAGNOSTIC_IGNORE_LOGICAL_OP
                        if (errno == EAGAIN || errno == EWOULDBLOCK ||
                                        errno == EPIPE) {
+                       DIAGNOSTIC_POP
                                /*
                                 * Nothing was recv.
                                 */
@@ -343,8 +346,11 @@ retry:
                        /*
                         * We consider EPIPE and EAGAIN/EWOULDBLOCK as expected.
                         */
+                       DIAGNOSTIC_PUSH
+                       DIAGNOSTIC_IGNORE_LOGICAL_OP
                        if (errno == EAGAIN || errno == EWOULDBLOCK ||
                                        errno == EPIPE) {
+                       DIAGNOSTIC_POP
                                /*
                                 * This can happen in non blocking mode.
                                 * Nothing was sent.
@@ -373,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);
@@ -569,7 +584,10 @@ retry:
                        /*
                         * We consider EPIPE and EAGAIN/EWOULDBLOCK as expected.
                         */
+                       DIAGNOSTIC_PUSH
+                       DIAGNOSTIC_IGNORE_LOGICAL_OP
                        if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                       DIAGNOSTIC_POP
                                /*
                                 * This can happen in non blocking mode.
                                 * Nothing was sent.
@@ -883,7 +901,10 @@ retry:
                        /*
                         * We consider EPIPE and EAGAIN/EWOULDBLOCK as expected.
                         */
+                       DIAGNOSTIC_PUSH
+                       DIAGNOSTIC_IGNORE_LOGICAL_OP
                        if (errno == EAGAIN || errno == EWOULDBLOCK) {
+                       DIAGNOSTIC_POP
                                /*
                                 * This can happen in non blocking mode.
                                 * Nothing was recv.
@@ -1138,7 +1159,7 @@ int lttcomm_setsockopt_creds_unix_sock(int sock)
        return ret;
 }
 #elif (defined(__FreeBSD__) || defined(__sun__) || defined(__APPLE__))
-int lttcomm_setsockopt_creds_unix_sock(int sock)
+int lttcomm_setsockopt_creds_unix_sock(int sock __attribute__((unused)))
 {
        return 0;
 }
This page took 0.032193 seconds and 4 git commands to generate.