Diff between 5008dc2ba9730f3280cf8fae43fa5e1d0fa175eb and 17fff52ab12fe874468cf455795c42f42341ab89

Changed Files

File Additions Deletions Status
Makefile.tools +3 -1 modified
tools/btmgmt.c +13 -0 modified

Full Patch

diff --git a/Makefile.tools b/Makefile.tools
index bda4465..4d45682 100644
--- a/Makefile.tools
+++ b/Makefile.tools
@@ -168,7 +168,9 @@ tools_hcieventmask_LDADD = lib/libbluetooth-private.la
 
 tools_hwdb_LDADD = lib/libbluetooth-private.la
 
-tools_btmgmt_SOURCES = tools/btmgmt.c src/glib-helper.c src/eir.c
+tools_btmgmt_SOURCES = tools/btmgmt.c src/glib-helper.c src/eir.c \
+				src/shared/util.h src/shared/util.c \
+				src/shared/mgmt.h src/shared/mgmt.c
 tools_btmgmt_LDADD = lib/libbluetooth-private.la @GLIB_LIBS@
 
 tools_btiotest_SOURCES = tools/btiotest.c btio/btio.h btio/btio.c
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 6cde49e..55cf9ad 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -42,6 +42,7 @@
 
 #include <glib.h>
 
+#include "src/shared/mgmt.h"
 #include "glib-helper.h"
 #include "lib/mgmt.h"
 #include "eir.h"
@@ -1974,6 +1975,7 @@ int main(int argc, char *argv[])
 	int opt, i, mgmt_sk;
 	uint16_t index = MGMT_INDEX_NONE;
 	struct pollfd pollfd;
+	struct mgmt *mgmt;
 
 	while ((opt = getopt_long(argc, argv, "+hvi:",
 						main_options, NULL)) != -1) {
@@ -2024,6 +2026,13 @@ int main(int argc, char *argv[])
 		return -1;
 	}
 
+	mgmt = mgmt_new_default();
+	if (!mgmt) {
+		fprintf(stderr, "Unable to open mgmt_socket\n");
+		close(mgmt_sk);
+		return -1;
+	}
+
 	pollfd.fd = mgmt_sk;
 	pollfd.events = POLLIN;
 	pollfd.revents = 0;
@@ -2038,6 +2047,10 @@ int main(int argc, char *argv[])
 		pollfd.revents = 0;
 	}
 
+	mgmt_cancel_all(mgmt);
+	mgmt_unregister_all(mgmt);
+	mgmt_unref(mgmt);
+
 	close(mgmt_sk);
 
 	return 0;