summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-12-15 14:48:07 -0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-12-15 14:48:07 -0800
commitb6061ea5b82fd0aa7dbf033fe40fc1235ec0f987 (patch)
tree1baa187e93b6ef5cd20bd568f3867db1e68948f2
parentd36c45c55a412204c9a14ba2ebd15319b3e51eda (diff)
downloadbluez-b6061ea5b82fd0aa7dbf033fe40fc1235ec0f987.tar.gz
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.
-rw-r--r--src/device.c12
1 files 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 <errno.h>
#include <dirent.h>
#include <time.h>
+#include <sys/stat.h>
#include <glib.h>
#include <dbus/dbus.h>
@@ -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;