From a7ded163dbe548075d65219c6189f059da2d99bb Mon Sep 17 00:00:00 2001 From: Andreas Färber Date: Thu, 17 Apr 2014 18:19:14 +0200 Subject: qtest: Assure that init_socket()'s listen() does not fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In practice this seems very unlikely, so cleanup is neglected, as done for bind(). Reviewed-by: Stefan Hajnoczi Signed-off-by: Andreas Färber --- tests/libqtest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index 8155695848..232f781639 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -72,7 +72,8 @@ static int init_socket(const char *socket_path) ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); } while (ret == -1 && errno == EINTR); g_assert_no_errno(ret); - listen(sock, 1); + ret = listen(sock, 1); + g_assert_no_errno(ret); return sock; } -- cgit 1.4.1 From a7d915f388355f5353f2b692a1abd7868b8307a1 Mon Sep 17 00:00:00 2001 From: Andreas Färber Date: Thu, 17 Apr 2014 18:38:25 +0200 Subject: qtest: Add error reporting to socket_accept() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're not using the GLib infrastructure here, to allow cleaning up the sockets. Still, knowing why a certain test run failed can be valuable. Reviewed-by: Stefan Hajnoczi Signed-off-by: Andreas Färber --- tests/libqtest.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index 232f781639..4b90d9112a 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -93,6 +93,9 @@ static int socket_accept(int sock) do { ret = accept(sock, (struct sockaddr *)&addr, &addrlen); } while (ret == -1 && errno == EINTR); + if (ret == -1) { + fprintf(stderr, "%s failed: %s\n", __func__, strerror(errno)); + } close(sock); return ret; -- cgit 1.4.1 From 535b45631ad7176e10dab89d55443b5a096500b9 Mon Sep 17 00:00:00 2001 From: Andreas Färber Date: Thu, 17 Apr 2014 19:21:12 +0200 Subject: qtest: Be paranoid about accept() addrlen argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit POSIX specifies that address_len shall on output specify the length of the stored address; it does not however specify whether it may get updated on failure as well to, e.g., zero. In case EINTR occurs, re-initialize the variable to the desired value. Reviewed-by: Eric Blake Signed-off-by: Andreas Färber --- tests/libqtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/libqtest.c') diff --git a/tests/libqtest.c b/tests/libqtest.c index 4b90d9112a..71468ac9c7 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -89,8 +89,8 @@ static int socket_accept(int sock) setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout, sizeof(timeout)); - addrlen = sizeof(addr); do { + addrlen = sizeof(addr); ret = accept(sock, (struct sockaddr *)&addr, &addrlen); } while (ret == -1 && errno == EINTR); if (ret == -1) { -- cgit 1.4.1