diff mbox series

[BlueZ,1/1] isotest: Add check after accepting connection

Message ID 20230623074406.16522-2-iulia.tanasescu@nxp.com (mailing list archive)
State Accepted
Commit b00bc612fab842def22d042bad8919213bcb9b1a
Headers show
Series isotest: Add check after accepting connection | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/BuildEll success Build ELL PASS
tedd_an/BluezMake success Bluez Make PASS
tedd_an/MakeCheck success Bluez Make Check PASS
tedd_an/MakeDistcheck success Make Distcheck PASS
tedd_an/CheckValgrind success Check Valgrind PASS
tedd_an/CheckSmatch success CheckSparse PASS
tedd_an/bluezmakeextell success Make External ELL PASS
tedd_an/IncrementalBuild success Incremental Build PASS
tedd_an/ScanBuild success Scan Build PASS

Commit Message

Iulia Tanasescu June 23, 2023, 7:44 a.m. UTC
This checks for the POLLERR event on a newly accepted connection,
to determine if the connection was successful or not.

---
 tools/isotest.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

bluez.test.bot@gmail.com June 23, 2023, 9:19 a.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=759716

---Test result---

Test Summary:
CheckPatch                    PASS      0.36 seconds
GitLint                       PASS      0.24 seconds
BuildEll                      PASS      27.68 seconds
BluezMake                     PASS      884.65 seconds
MakeCheck                     PASS      12.42 seconds
MakeDistcheck                 PASS      159.39 seconds
CheckValgrind                 PASS      262.54 seconds
CheckSmatch                   PASS      340.96 seconds
bluezmakeextell               PASS      103.63 seconds
IncrementalBuild              PASS      715.11 seconds
ScanBuild                     PASS      1093.68 seconds



---
Regards,
Linux Bluetooth
diff mbox series

Patch

diff --git a/tools/isotest.c b/tools/isotest.c
index 0eae3cdc1..c71bc6fa0 100644
--- a/tools/isotest.c
+++ b/tools/isotest.c
@@ -33,6 +33,7 @@ 
 #include <time.h>
 #include <inttypes.h>
 #include <sys/wait.h>
+#include <poll.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
@@ -440,6 +441,9 @@  static void do_listen(char *filename, void (*handler)(int fd, int sk),
 	socklen_t optlen;
 	int sk, nsk, fd = -1;
 	char ba[18];
+	struct pollfd fds;
+	int err, sk_err;
+	socklen_t len;
 
 	if (filename) {
 		fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
@@ -529,6 +533,28 @@  static void do_listen(char *filename, void (*handler)(int fd, int sk),
 			goto error;
 		}
 
+		/* Check if connection was successful */
+		memset(&fds, 0, sizeof(fds));
+		fds.fd = nsk;
+		fds.events = POLLERR;
+
+		if (poll(&fds, 1, 0) > 0 && (fds.revents & POLLERR)) {
+			len = sizeof(sk_err);
+
+			if (getsockopt(nsk, SOL_SOCKET, SO_ERROR,
+						&sk_err, &len) < 0)
+				err = -errno;
+			else
+				err = -sk_err;
+
+			if (err < 0)
+				syslog(LOG_ERR, "Connection failed: %s (%d)",
+						strerror(-err), -err);
+
+			close(nsk);
+			continue;
+		}
+
 		if (fork()) {
 			/* Parent */
 			close(nsk);