From 9534a4e704b3d8091410db31be21cb6ddc7378cb Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 15 Dec 2021 14:48:07 -0800 Subject: [PATCH] device: Fix bogus errors on load_att_info load_att_info would attempt to load attributes file from the storage but in case it doesn't exists it would print an error instead of just bailing out as attributes file is created on demand when there are something to be stored. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- src/device.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/device.c b/src/device.c index 058780ad..71c9dad3 100644 --- a/src/device.c +++ b/src/device.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -6139,6 +6140,7 @@ static void load_att_info(struct btd_device *device, const char *local, const char *peer) { char filename[PATH_MAX]; + struct stat st; GKeyFile *key_file; GError *gerr = NULL; char *prim_uuid, *str; @@ -6148,12 +6150,13 @@ static void load_att_info(struct btd_device *device, const char *local, char tmp[3]; int i; - sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID); - prim_uuid = bt_uuid2string(&uuid); - snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", local, peer); + /* Check if attributes file exists */ + if (stat(filename, &st) < 0) + return; + key_file = g_key_file_new(); if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) { error("Unable to load key file from %s: (%s)", filename, @@ -6162,6 +6165,9 @@ static void load_att_info(struct btd_device *device, const char *local, } groups = g_key_file_get_groups(key_file, NULL); + sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID); + prim_uuid = bt_uuid2string(&uuid); + for (handle = groups; *handle; handle++) { gboolean uuid_ok; int end; -- 2.34.1