From b6061ea5b82fd0aa7dbf033fe40fc1235ec0f987 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. --- src/device.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/device.c b/src/device.c index 0e2612825..982b7979e 100644 --- a/src/device.c +++ b/src/device.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -3614,6 +3615,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; @@ -3623,12 +3625,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, @@ -3637,6 +3640,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.47.3