[lttng-dev] [PATCH lttng-tools] Fix: set errno with value from SO_ERROR on error.

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Tue Feb 20 22:06:31 EST 2018


Debugging output at the same time in case of asynchronous handling.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 src/common/sessiond-comm/inet.c  | 6 ++++++
 src/common/sessiond-comm/inet6.c | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/src/common/sessiond-comm/inet.c b/src/common/sessiond-comm/inet.c
index 25dbd21..0e72bb7 100644
--- a/src/common/sessiond-comm/inet.c
+++ b/src/common/sessiond-comm/inet.c
@@ -176,6 +176,8 @@ int connect_with_timeout(struct lttcomm_sock *sock)
 		goto success;
 	}
 
+	DBG("Asynchronous connect for sock %d, performing polling with"
+			" timeout: %lums", sock->fd, timeout);
 	/*
 	 * Perform poll loop following EINPROGRESS recommendation from
 	 * connect(2) man page.
@@ -202,12 +204,16 @@ int connect_with_timeout(struct lttcomm_sock *sock)
 			ret = getsockopt(sock->fd, SOL_SOCKET,
 				SO_ERROR, &optval, &optval_len);
 			if (ret) {
+				PERROR("getsockopt");
 				goto error;
 			}
 			if (!optval) {
+				/* errno is set to zero from getsockopt */
 				connect_ret = 0;
 				goto success;
 			} else {
+				/* Get actual connect() errno from opt_val */
+				errno = optval;
 				goto error;
 			}
 		}
diff --git a/src/common/sessiond-comm/inet6.c b/src/common/sessiond-comm/inet6.c
index 0b0383c..071fd52 100644
--- a/src/common/sessiond-comm/inet6.c
+++ b/src/common/sessiond-comm/inet6.c
@@ -174,6 +174,9 @@ int connect_with_timeout(struct lttcomm_sock *sock)
 		goto success;
 	}
 
+	DBG("Asynchronous connect for sock %d, performing polling with"
+			" timeout: %lums", sock->fd, timeout);
+
 	/*
 	 * Perform poll loop following EINPROGRESS recommendation from
 	 * connect(2) man page.
@@ -200,12 +203,16 @@ int connect_with_timeout(struct lttcomm_sock *sock)
 			ret = getsockopt(sock->fd, SOL_SOCKET,
 				SO_ERROR, &optval, &optval_len);
 			if (ret) {
+				PERROR("getsockopt");
 				goto error;
 			}
 			if (!optval) {
+				/* errno is set to zero from getsockopt */
 				connect_ret = 0;
 				goto success;
 			} else {
+				/* Get actual connect() errno from opt_val */
+				errno = optval;
 				goto error;
 			}
 		}
-- 
2.7.4



More information about the lttng-dev mailing list