Diff between d36c45c55a412204c9a14ba2ebd15319b3e51eda and b6061ea5b82fd0aa7dbf033fe40fc1235ec0f987

Changed Files

File Additions Deletions Status
src/device.c +9 -3 modified

Full Patch

diff --git a/src/device.c b/src/device.c
index 0e26128..982b797 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;