All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: linux-bluetooth@vger.kernel.org
Cc: David Lechner <david@lechnology.com>
Subject: [PATCH BlueZ] device: delete cache file when device is removed
Date: Wed, 25 Aug 2021 12:29:36 -0500	[thread overview]
Message-ID: <20210825172936.2691027-1-david@lechnology.com> (raw)

When a device is removed from BlueZ, it should be completely forgotten
so that when it is seen again, it behaves exactly the same as if this
was the first time the device was ever seen.

So instead of just deleting one section of the cache file, we delete
the entire file.

This fixes issues with the GATT cache being retained and used for
devices that don't have ServicesChanged or Database Hash characteristics
to indicate that the attributes on the device have changed.

Issue: https://github.com/bluez/bluez/issues/191
Signed-off-by: David Lechner <david@lechnology.com>
---
 src/device.c | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/src/device.c b/src/device.c
index 6d534c488..b51d9df4d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4485,9 +4485,6 @@ static void device_remove_stored(struct btd_device *device)
 {
 	char device_addr[18];
 	char filename[PATH_MAX];
-	GKeyFile *key_file;
-	char *data;
-	gsize length = 0;
 
 	if (device->bredr_state.bonded)
 		device_remove_bonding(device, BDADDR_BREDR);
@@ -4511,19 +4508,7 @@ static void device_remove_stored(struct btd_device *device)
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s",
 				btd_adapter_get_storage_dir(device->adapter),
 				device_addr);
-
-	key_file = g_key_file_new();
-	g_key_file_load_from_file(key_file, filename, 0, NULL);
-	g_key_file_remove_group(key_file, "ServiceRecords", NULL);
-
-	data = g_key_file_to_data(key_file, &length, NULL);
-	if (length > 0) {
-		create_file(filename, 0600);
-		g_file_set_contents(filename, data, length, NULL);
-	}
-
-	g_free(data);
-	g_key_file_free(key_file);
+	unlink(filename);
 }
 
 void device_remove(struct btd_device *device, gboolean remove_stored)
-- 
2.25.1


             reply	other threads:[~2021-08-25 17:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-25 17:29 David Lechner [this message]
2021-08-25 17:57 ` [BlueZ] device: delete cache file when device is removed bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210825172936.2691027-1-david@lechnology.com \
    --to=david@lechnology.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.