* [PATCH] Bluetooth: Fix using locked state_change for A2MP chan
From: Andrei Emeltchenko @ 2012-11-30 14:51 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
A2MP channel do not have sk associated so use unlocked version
of state_change. chan is already locked.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
net/bluetooth/l2cap_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 2414cff..6de4287 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1276,7 +1276,7 @@ static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err)
}
if (chan->chan_type == L2CAP_CHAN_CONN_FIX_A2MP) {
- l2cap_state_change(chan, BT_DISCONN);
+ __l2cap_state_change(chan, BT_DISCONN);
return;
}
--
1.7.10.4
^ permalink raw reply related
* [RFC V3 12/12] event: Store long term key infos in device info file
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
---
src/event.c | 89 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 46 insertions(+), 43 deletions(-)
diff --git a/src/event.c b/src/event.c
index 5e83c09..61fa0f4 100644
--- a/src/event.c
+++ b/src/event.c
@@ -304,54 +304,59 @@ void btd_event_remote_name(const bdaddr_t *local, bdaddr_t *peer,
device_set_name(device, name);
}
-static char *buf2str(uint8_t *data, int datalen)
+static void store_longtermkey(bdaddr_t *local, bdaddr_t *peer,
+ uint8_t bdaddr_type, unsigned char *key,
+ uint8_t master, uint8_t authenticated,
+ uint8_t enc_size, uint16_t ediv,
+ uint8_t rand[8])
{
- char *buf;
+ char adapter_addr[18];
+ char device_addr[18];
+ char filename[PATH_MAX + 1];
+ GKeyFile *key_file;
+ char key_str[35];
+ char rand_str[19];
+ char *str;
int i;
+ gsize length = 0;
- buf = g_try_new0(char, (datalen * 2) + 1);
- if (buf == NULL)
- return NULL;
-
- for (i = 0; i < datalen; i++)
- sprintf(buf + (i * 2), "%2.2x", data[i]);
+ ba2str(local, adapter_addr);
+ ba2str(peer, device_addr);
- return buf;
-}
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+ device_addr);
+ filename[PATH_MAX] = '\0';
-static int store_longtermkey(bdaddr_t *local, bdaddr_t *peer,
- uint8_t bdaddr_type, unsigned char *key,
- uint8_t master, uint8_t authenticated,
- uint8_t enc_size, uint16_t ediv, uint8_t rand[8])
-{
- GString *newkey;
- char *val, *str;
- int err;
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
- val = buf2str(key, 16);
- if (val == NULL)
- return -ENOMEM;
+ key_str[0] = '0';
+ key_str[1] = 'x';
+ for (i = 0; i < 16; i++)
+ sprintf(key_str + 2 + (i * 2), "%2.2X", key[i]);
- newkey = g_string_new(val);
- g_free(val);
+ g_key_file_set_string(key_file, "LongTermKey", "Key", key_str);
- g_string_append_printf(newkey, " %d %d %d %d ", authenticated, master,
- enc_size, ediv);
+ g_key_file_set_integer(key_file, "LongTermKey", "Authenticated",
+ authenticated);
+ g_key_file_set_integer(key_file, "LongTermKey", "Master", master);
+ g_key_file_set_integer(key_file, "LongTermKey", "EncSize", enc_size);
+ g_key_file_set_integer(key_file, "LongTermKey", "EDiv", ediv);
- str = buf2str(rand, 8);
- if (str == NULL) {
- g_string_free(newkey, TRUE);
- return -ENOMEM;
- }
+ rand_str[0] = '0';
+ rand_str[1] = 'x';
+ for (i = 0; i < 8; i++)
+ sprintf(rand_str + 2 + (i * 2), "%2.2X", rand[i]);
- newkey = g_string_append(newkey, str);
- g_free(str);
+ g_key_file_set_string(key_file, "LongTermKey", "Rand", rand_str);
- err = write_longtermkeys(local, peer, bdaddr_type, newkey->str);
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- g_string_free(newkey, TRUE);
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, str, length, NULL);
+ g_free(str);
- return err;
+ g_key_file_free(key_file);
}
static void store_link_key(struct btd_adapter *adapter,
@@ -425,21 +430,19 @@ int btd_event_ltk_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
{
struct btd_adapter *adapter;
struct btd_device *device;
- int ret;
if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
return -ENODEV;
- ret = store_longtermkey(local, peer, bdaddr_type, key, master,
+ store_longtermkey(local, peer, bdaddr_type, key, master,
authenticated, enc_size, ediv, rand);
- if (ret == 0) {
- device_set_bonded(device, TRUE);
- if (device_is_temporary(device))
- device_set_temporary(device, FALSE);
- }
+ device_set_bonded(device, TRUE);
- return ret;
+ if (device_is_temporary(device))
+ device_set_temporary(device, FALSE);
+
+ return 0;
}
void btd_event_conn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 11/12] adapter: Upload long term keys from new storage
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Remove check of long term keys from device_create,
this moves to load_devices.
---
src/adapter.c | 127 +++++++++++++++++++++++----------------------------------
src/device.c | 6 ---
2 files changed, 51 insertions(+), 82 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index ff9d2e7..a0ae04c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1790,77 +1790,57 @@ failed:
return info;
}
-static struct smp_ltk_info *get_ltk_info(const char *addr, uint8_t bdaddr_type,
- const char *value)
+static struct smp_ltk_info *get_ltk_info(GKeyFile *key_file, const char *peer)
{
- struct smp_ltk_info *ltk;
- char *ptr;
- int i, ret;
+ struct smp_ltk_info *ltk = NULL;
+ char *key;
+ char *rand = NULL;
+ char *type = NULL;
+ uint8_t bdaddr_type;
- if (strlen(value) < 60) {
- error("Unexpectedly short (%zu) LTK", strlen(value));
- return NULL;
- }
+ key = g_key_file_get_string(key_file, "LongTermKey", "Key", NULL);
+ if (!key || strlen(key) != 34)
+ goto failed;
- ltk = g_new0(struct smp_ltk_info, 1);
+ rand = g_key_file_get_string(key_file, "LongTermKey", "Rand", NULL);
+ if (!rand || strlen(rand) != 18)
+ goto failed;
- str2ba(addr, <k->bdaddr);
+ type = g_key_file_get_string(key_file, "General", "AddressType", NULL);
+ if (!type)
+ goto failed;
- ltk->bdaddr_type = bdaddr_type;
+ if (g_str_equal(type, "public"))
+ bdaddr_type = BDADDR_LE_PUBLIC;
+ else if (g_str_equal(type, "static"))
+ bdaddr_type = BDADDR_LE_RANDOM;
+ else
+ goto failed;
- str2buf(value, ltk->val, sizeof(ltk->val));
+ ltk = g_new0(struct smp_ltk_info, 1);
- ptr = (char *) value + 2 * sizeof(ltk->val) + 1;
+ str2ba(peer, <k->bdaddr);
+ ltk->bdaddr_type = bdaddr_type;
+ str2buf(&key[2], ltk->val, sizeof(ltk->val));
+ str2buf(&rand[2], ltk->rand, sizeof(ltk->rand));
- ret = sscanf(ptr, " %hhd %hhd %hhd %hd %n",
- <k->authenticated, <k->master, <k->enc_size,
- <k->ediv, &i);
- if (ret < 2) {
- g_free(ltk);
- return NULL;
- }
- ptr += i;
+ ltk->authenticated = g_key_file_get_integer(key_file, "LongTermKey",
+ "Authenticated", NULL);
+ ltk->master = g_key_file_get_integer(key_file, "LongTermKey", "Master",
+ NULL);
+ ltk->enc_size = g_key_file_get_integer(key_file, "LongTermKey",
+ "EncSize", NULL);
+ ltk->ediv = g_key_file_get_integer(key_file, "LongTermKey", "EDiv",
+ NULL);
- str2buf(ptr, ltk->rand, sizeof(ltk->rand));
+failed:
+ g_free(key);
+ g_free(rand);
+ g_free(type);
return ltk;
}
-static void create_stored_device_from_ltks(char *key, char *value,
- void *user_data)
-{
- struct adapter_keys *keys = user_data;
- struct btd_adapter *adapter = keys->adapter;
- struct btd_device *device;
- struct smp_ltk_info *info;
- char address[18], srcaddr[18];
- uint8_t bdaddr_type;
-
- if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
- return;
-
- info = get_ltk_info(address, bdaddr_type, value);
- if (info == NULL)
- return;
-
- keys->keys = g_slist_append(keys->keys, info);
-
- if (g_slist_find_custom(adapter->devices, address,
- (GCompareFunc) device_address_cmp))
- return;
-
- ba2str(&adapter->bdaddr, srcaddr);
-
- if (g_strcmp0(srcaddr, address) == 0)
- return;
-
- device = device_create(adapter, address, bdaddr_type);
- if (device) {
- device_set_temporary(device, FALSE);
- adapter->devices = g_slist_append(adapter->devices, device);
- }
-}
-
static GSList *string_to_primary_list(char *str)
{
GSList *l = NULL;
@@ -1935,18 +1915,12 @@ static void create_stored_device_from_primaries(char *key, char *value,
g_slist_free(uuids);
}
-static void smp_key_free(void *data)
-{
- struct smp_ltk_info *info = data;
-
- g_free(info);
-}
-
static void load_devices(struct btd_adapter *adapter)
{
char filename[PATH_MAX + 1];
char srcaddr[18];
struct adapter_keys keys = { adapter, NULL };
+ struct adapter_keys ltks = { adapter, NULL };
int err;
DIR *dir;
struct dirent *entry;
@@ -1961,16 +1935,6 @@ static void load_devices(struct btd_adapter *adapter)
textfile_foreach(filename, create_stored_device_from_primaries,
adapter);
- create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "longtermkeys");
- textfile_foreach(filename, create_stored_device_from_ltks, &keys);
-
- err = mgmt_load_ltks(adapter->dev_id, keys.keys);
- if (err < 0)
- error("Unable to load ltks: %s (%d)", strerror(-err), -err);
-
- g_slist_free_full(keys.keys, smp_key_free);
- keys.keys = NULL;
-
snprintf(filename, PATH_MAX, STORAGEDIR "/%s", srcaddr);
filename[PATH_MAX] = '\0';
@@ -1985,6 +1949,7 @@ static void load_devices(struct btd_adapter *adapter)
char filename[PATH_MAX + 1];
GKeyFile *key_file;
struct link_key_info *key_info;
+ struct smp_ltk_info *ltk_info;
GSList *l;
if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
@@ -2000,6 +1965,10 @@ static void load_devices(struct btd_adapter *adapter)
if (key_info)
keys.keys = g_slist_append(keys.keys, key_info);
+ ltk_info = get_ltk_info(key_file, entry->d_name);
+ if (ltk_info)
+ ltks.keys = g_slist_append(ltks.keys, ltk_info);
+
g_key_file_free(key_file);
l = g_slist_find_custom(adapter->devices, entry->d_name,
@@ -2017,7 +1986,7 @@ static void load_devices(struct btd_adapter *adapter)
adapter->devices = g_slist_append(adapter->devices, device);
device_exist:
- if (key_info) {
+ if (key_info || ltk_info) {
device_set_paired(device, TRUE);
device_set_bonded(device, TRUE);
}
@@ -2032,6 +2001,12 @@ device_exist:
strerror(-err), -err);
g_slist_free_full(keys.keys, g_free);
+
+ err = mgmt_load_ltks(adapter->dev_id, ltks.keys);
+ if (err < 0)
+ error("Unable to load ltks: %s (%d)", strerror(-err), -err);
+
+ g_slist_free_full(ltks.keys, g_free);
}
int btd_adapter_block_address(struct btd_adapter *adapter,
diff --git a/src/device.c b/src/device.c
index bb5689b..a5bdf4c 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1904,12 +1904,6 @@ struct btd_device *device_create(struct btd_adapter *adapter,
load_info(device, srcaddr, address);
- if (device_is_le(device) && has_longtermkeys(src, &device->bdaddr,
- device->bdaddr_type)) {
- device_set_paired(device, TRUE);
- device_set_bonded(device, TRUE);
- }
-
return btd_device_ref(device);
}
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 10/12] adapter: Convert storage longtermkeys file
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index 17f478c..ff9d2e7 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2655,6 +2655,46 @@ static void convert_linkkey_entry(GKeyFile *key_file, void *value)
g_key_file_set_integer(key_file, "LinkKey", "PINLength", val);
}
+static void convert_ltk_entry(GKeyFile *key_file, void *value)
+{
+ char *auth_str, *rand_str, *str;
+ int i, ret;
+ unsigned char auth, master, enc_size;
+ unsigned short ediv;
+
+ auth_str = strchr(value, ' ');
+ if (!auth_str)
+ return;
+
+ *(auth_str++) = 0;
+
+ for (i = 0, rand_str = auth_str; i < 4; i++) {
+ rand_str = strchr(rand_str, ' ');
+ if (!rand_str || rand_str[1] == '\0')
+ return;
+
+ rand_str++;
+ }
+
+ ret = sscanf(auth_str, " %hhd %hhd %hhd %hd", &auth, &master,
+ &enc_size, &ediv);
+ if (ret < 4)
+ return;
+
+ str = g_strconcat("0x", value, NULL);
+ g_key_file_set_string(key_file, "LongTermKey", "Key", str);
+ g_free(str);
+
+ g_key_file_set_integer(key_file, "LongTermKey", "Authenticated", auth);
+ g_key_file_set_integer(key_file, "LongTermKey", "Master", master);
+ g_key_file_set_integer(key_file, "LongTermKey", "EncSize", enc_size);
+ g_key_file_set_integer(key_file, "LongTermKey", "EDiv", ediv);
+
+ str = g_strconcat("0x", rand_str, NULL);
+ g_key_file_set_string(key_file, "LongTermKey", "Rand", str);
+ g_free(str);
+}
+
static void convert_entry(char *key, char *value, void *user_data)
{
struct device_converter *converter = user_data;
@@ -2766,6 +2806,9 @@ static void convert_device_storage(struct btd_adapter *adapter)
/* Convert linkkeys */
convert_file("linkkeys", address, convert_linkkey_entry, TRUE);
+ /* Convert longtermkeys */
+ convert_file("longtermkeys", address, convert_ltk_entry, TRUE);
+
/* Convert classes */
convert_file("classes", address, convert_classes_entry, FALSE);
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 09/12] event: Store link key infos in device info file
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
---
src/event.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 12 deletions(-)
diff --git a/src/event.c b/src/event.c
index 7fc8f02..5e83c09 100644
--- a/src/event.c
+++ b/src/event.c
@@ -354,33 +354,68 @@ static int store_longtermkey(bdaddr_t *local, bdaddr_t *peer,
return err;
}
+static void store_link_key(struct btd_adapter *adapter,
+ struct btd_device *device, uint8_t *key,
+ uint8_t type, uint8_t pin_length)
+{
+ char adapter_addr[18];
+ char device_addr[18];
+ char filename[PATH_MAX + 1];
+ GKeyFile *key_file;
+ char key_str[35];
+ char *str;
+ int i;
+ gsize length = 0;
+
+ ba2str(adapter_get_address(adapter), adapter_addr);
+ ba2str(device_get_address(device), device_addr);
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+ device_addr);
+ filename[PATH_MAX] = '\0';
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+ key_str[0] = '0';
+ key_str[1] = 'x';
+ for (i = 0; i < 16; i++)
+ sprintf(key_str + 2 + (i * 2), "%2.2X", key[i]);
+
+ g_key_file_set_string(key_file, "LinkKey", "Key", key_str);
+
+ g_key_file_set_integer(key_file, "LinkKey", "Type", type);
+ g_key_file_set_integer(key_file, "LinkKey", "PINLength", pin_length);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, str, length, NULL);
+ g_free(str);
+
+ g_key_file_free(key_file);
+}
+
int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,
uint8_t *key, uint8_t key_type,
uint8_t pin_length)
{
struct btd_adapter *adapter;
struct btd_device *device;
- uint8_t peer_type;
- int ret;
if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
return -ENODEV;
DBG("storing link key of type 0x%02x", key_type);
- peer_type = device_get_addr_type(device);
+ store_link_key(adapter, device, key, key_type, pin_length);
- ret = write_link_key(local, peer, peer_type, key, key_type,
- pin_length);
+ device_set_bonded(device, TRUE);
- if (ret == 0) {
- device_set_bonded(device, TRUE);
-
- if (device_is_temporary(device))
- device_set_temporary(device, FALSE);
- }
+ if (device_is_temporary(device))
+ device_set_temporary(device, FALSE);
- return ret;
+ return 0;
}
int btd_event_ltk_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 08/12] adapter: Upload link keys from new storage
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Remove read_link_key() from device_create, this moves to load_devices.
---
src/adapter.c | 110 +++++++++++++++++++++++++--------------------------------
src/device.c | 6 ----
2 files changed, 49 insertions(+), 67 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index bf20580..17f478c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1766,31 +1766,26 @@ static int str2buf(const char *str, uint8_t *buf, size_t blen)
return 0;
}
-static struct link_key_info *get_key_info(const char *addr, const char *value)
+static struct link_key_info *get_key_info(GKeyFile *key_file, const char *peer)
{
- struct link_key_info *info;
- char tmp[3];
- long int l;
+ struct link_key_info *info = NULL;
+ char *str;
- if (strlen(value) < 36) {
- error("Unexpectedly short (%zu) link key line", strlen(value));
- return NULL;
- }
+ str = g_key_file_get_string(key_file, "LinkKey", "Key", NULL);
+ if (!str || strlen(str) != 34)
+ goto failed;
info = g_new0(struct link_key_info, 1);
- str2ba(addr, &info->bdaddr);
-
- str2buf(value, info->key, sizeof(info->key));
+ str2ba(peer, &info->bdaddr);
+ str2buf(&str[2], info->key, sizeof(info->key));
- memcpy(tmp, value + 33, 2);
- info->type = (uint8_t) strtol(tmp, NULL, 10);
+ info->type = g_key_file_get_integer(key_file, "LinkKey", "Type", NULL);
+ info->pin_len = g_key_file_get_integer(key_file, "LinkKey", "PINLength",
+ NULL);
- memcpy(tmp, value + 35, 2);
- l = strtol(tmp, NULL, 10);
- if (l < 0)
- l = 0;
- info->pin_len = l;
+failed:
+ g_free(str);
return info;
}
@@ -1831,34 +1826,6 @@ static struct smp_ltk_info *get_ltk_info(const char *addr, uint8_t bdaddr_type,
return ltk;
}
-static void create_stored_device_from_linkkeys(char *key, char *value,
- void *user_data)
-{
- char address[18];
- uint8_t bdaddr_type;
- struct adapter_keys *keys = user_data;
- struct btd_adapter *adapter = keys->adapter;
- struct btd_device *device;
- struct link_key_info *info;
-
- if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
- bdaddr_type = BDADDR_BREDR;
-
- info = get_key_info(address, value);
- if (info)
- keys->keys = g_slist_append(keys->keys, info);
-
- if (g_slist_find_custom(adapter->devices, address,
- (GCompareFunc) device_address_cmp))
- return;
-
- device = device_create(adapter, address, bdaddr_type);
- if (device) {
- device_set_temporary(device, FALSE);
- adapter->devices = g_slist_append(adapter->devices, device);
- }
-}
-
static void create_stored_device_from_ltks(char *key, char *value,
void *user_data)
{
@@ -1994,18 +1961,6 @@ static void load_devices(struct btd_adapter *adapter)
textfile_foreach(filename, create_stored_device_from_primaries,
adapter);
- create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "linkkeys");
- textfile_foreach(filename, create_stored_device_from_linkkeys, &keys);
-
- err = mgmt_load_link_keys(adapter->dev_id, keys.keys,
- main_opts.debug_keys);
- if (err < 0)
- error("Unable to load link keys: %s (%d)",
- strerror(-err), -err);
-
- g_slist_free_full(keys.keys, g_free);
- keys.keys = NULL;
-
create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "longtermkeys");
textfile_foreach(filename, create_stored_device_from_ltks, &keys);
@@ -2027,13 +1982,32 @@ static void load_devices(struct btd_adapter *adapter)
while ((entry = readdir(dir)) != NULL) {
struct btd_device *device;
+ char filename[PATH_MAX + 1];
+ GKeyFile *key_file;
+ struct link_key_info *key_info;
+ GSList *l;
if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
continue;
- if (g_slist_find_custom(adapter->devices, entry->d_name,
- (GCompareFunc) device_address_cmp))
- continue;
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", srcaddr,
+ entry->d_name);
+
+ key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+ key_info = get_key_info(key_file, entry->d_name);
+ if (key_info)
+ keys.keys = g_slist_append(keys.keys, key_info);
+
+ g_key_file_free(key_file);
+
+ l = g_slist_find_custom(adapter->devices, entry->d_name,
+ (GCompareFunc) device_address_cmp);
+ if (l) {
+ device = l->data;
+ goto device_exist;
+ }
device = device_create(adapter, entry->d_name, BDADDR_BREDR);
if (!device)
@@ -2041,9 +2015,23 @@ static void load_devices(struct btd_adapter *adapter)
device_set_temporary(device, FALSE);
adapter->devices = g_slist_append(adapter->devices, device);
+
+device_exist:
+ if (key_info) {
+ device_set_paired(device, TRUE);
+ device_set_bonded(device, TRUE);
+ }
}
closedir(dir);
+
+ err = mgmt_load_link_keys(adapter->dev_id, keys.keys,
+ main_opts.debug_keys);
+ if (err < 0)
+ error("Unable to load link keys: %s (%d)",
+ strerror(-err), -err);
+
+ g_slist_free_full(keys.keys, g_free);
}
int btd_adapter_block_address(struct btd_adapter *adapter,
diff --git a/src/device.c b/src/device.c
index 1db8a48..bb5689b 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1904,12 +1904,6 @@ struct btd_device *device_create(struct btd_adapter *adapter,
load_info(device, srcaddr, address);
- if (read_link_key(src, &device->bdaddr, device->bdaddr_type, NULL,
- NULL) == 0) {
- device_set_paired(device, TRUE);
- device_set_bonded(device, TRUE);
- }
-
if (device_is_le(device) && has_longtermkeys(src, &device->bdaddr,
device->bdaddr_type)) {
device_set_paired(device, TRUE);
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 07/12] adapter: Convert storage linkkeys file
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/src/adapter.c b/src/adapter.c
index f3b1c5d..bf20580 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2639,6 +2639,34 @@ static void convert_did_entry(GKeyFile *key_file, void *value)
g_key_file_set_integer(key_file, "DeviceID", "Version", val);
}
+static void convert_linkkey_entry(GKeyFile *key_file, void *value)
+{
+ char *type_str, *length_str, *str;
+ gint val;
+
+ type_str = strchr(value, ' ');
+ if (!type_str)
+ return;
+
+ *(type_str++) = 0;
+
+ length_str = strchr(type_str, ' ');
+ if (!length_str)
+ return;
+
+ *(length_str++) = 0;
+
+ str = g_strconcat("0x", value, NULL);
+ g_key_file_set_string(key_file, "LinkKey", "Key", str);
+ g_free(str);
+
+ val = strtol(type_str, NULL, 16);
+ g_key_file_set_integer(key_file, "LinkKey", "Type", val);
+
+ val = strtol(length_str, NULL, 16);
+ g_key_file_set_integer(key_file, "LinkKey", "PINLength", val);
+}
+
static void convert_entry(char *key, char *value, void *user_data)
{
struct device_converter *converter = user_data;
@@ -2747,6 +2775,9 @@ static void convert_device_storage(struct btd_adapter *adapter)
/* Convert blocked */
convert_file("blocked", address, convert_blocked_entry, TRUE);
+ /* Convert linkkeys */
+ convert_file("linkkeys", address, convert_linkkey_entry, TRUE);
+
/* Convert classes */
convert_file("classes", address, convert_classes_entry, FALSE);
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 06/12] adapter: Load devices from new storage architecture
From: Frédéric Danis @ 2012-11-30 14:47 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Parse storage directory and create devices from device sub-directories.
Remove create device from 'blocked' file, this is already converted.
---
src/adapter.c | 50 +++++++++++++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index c5e856d..f3b1c5d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -35,6 +35,7 @@
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <dirent.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
@@ -1893,23 +1894,6 @@ static void create_stored_device_from_ltks(char *key, char *value,
}
}
-static void create_stored_device_from_blocked(char *key, char *value,
- void *user_data)
-{
- struct btd_adapter *adapter = user_data;
- struct btd_device *device;
-
- if (g_slist_find_custom(adapter->devices,
- key, (GCompareFunc) device_address_cmp))
- return;
-
- device = device_create(adapter, key, BDADDR_BREDR);
- if (device) {
- device_set_temporary(device, FALSE);
- adapter->devices = g_slist_append(adapter->devices, device);
- }
-}
-
static GSList *string_to_primary_list(char *str)
{
GSList *l = NULL;
@@ -1997,6 +1981,8 @@ static void load_devices(struct btd_adapter *adapter)
char srcaddr[18];
struct adapter_keys keys = { adapter, NULL };
int err;
+ DIR *dir;
+ struct dirent *entry;
ba2str(&adapter->bdaddr, srcaddr);
@@ -2030,8 +2016,34 @@ static void load_devices(struct btd_adapter *adapter)
g_slist_free_full(keys.keys, smp_key_free);
keys.keys = NULL;
- create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "blocked");
- textfile_foreach(filename, create_stored_device_from_blocked, adapter);
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s", srcaddr);
+ filename[PATH_MAX] = '\0';
+
+ dir = opendir(filename);
+ if (!dir) {
+ error("Unable to open adapter storage directory: %s", filename);
+ return;
+ }
+
+ while ((entry = readdir(dir)) != NULL) {
+ struct btd_device *device;
+
+ if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
+ continue;
+
+ if (g_slist_find_custom(adapter->devices, entry->d_name,
+ (GCompareFunc) device_address_cmp))
+ continue;
+
+ device = device_create(adapter, entry->d_name, BDADDR_BREDR);
+ if (!device)
+ continue;
+
+ device_set_temporary(device, FALSE);
+ adapter->devices = g_slist_append(adapter->devices, device);
+ }
+
+ closedir(dir);
}
int btd_adapter_block_address(struct btd_adapter *adapter,
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 05/12] adapter: Convert device type
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Each time an entry is converted, check device technology and
update device info file
---
src/adapter.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/src/adapter.c b/src/adapter.c
index a976793..c5e856d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2530,6 +2530,44 @@ struct device_converter {
gboolean force;
};
+static void set_device_type(GKeyFile *key_file, char type)
+{
+ char *techno;
+ char *addr_type = NULL;
+ char *str;
+
+ switch (type) {
+ case BDADDR_BREDR:
+ techno = "BR/EDR";
+ break;
+ case BDADDR_LE_PUBLIC:
+ techno = "LE";
+ addr_type = "public";
+ break;
+ case BDADDR_LE_RANDOM:
+ techno = "LE";
+ addr_type = "static";
+ break;
+ default:
+ return;
+ }
+
+ str = g_key_file_get_string(key_file, "General",
+ "SupportedTechnologies", NULL);
+ if (!str)
+ g_key_file_set_string(key_file, "General",
+ "SupportedTechnologies", techno);
+ else if (!strstr(str, techno))
+ g_key_file_set_string(key_file, "General",
+ "SupportedTechnologies", "BR/EDR;LE");
+
+ g_free(str);
+
+ if (addr_type)
+ g_key_file_set_string(key_file, "General", "AddressType",
+ addr_type);
+}
+
static void convert_aliases_entry(GKeyFile *key_file, void *value)
{
g_key_file_set_string(key_file, "General", "Alias", value);
@@ -2592,13 +2630,16 @@ static void convert_did_entry(GKeyFile *key_file, void *value)
static void convert_entry(char *key, char *value, void *user_data)
{
struct device_converter *converter = user_data;
+ char device_type = -1;
char filename[PATH_MAX + 1];
GKeyFile *key_file;
char *data;
gsize length = 0;
- if (key[17] == '#')
+ if (key[17] == '#') {
key[17] = '\0';
+ device_type = key[18] - '0';
+ }
if (bachk(key) != 0)
return;
@@ -2622,6 +2663,10 @@ static void convert_entry(char *key, char *value, void *user_data)
key_file = g_key_file_new();
g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+ if (device_type >= 0)
+ set_device_type(key_file, device_type);
+
converter->cb(key_file, value);
data = g_key_file_to_data(key_file, &length, NULL);
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 04/12] adapter: Add force dir creation to convert_file()
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Some device information, like class or device id, should only be
converted if directory for this device has already been created
during previous conversion (from aliases, trusts, blocked, ...
files).
---
src/adapter.c | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 8e3251b..a976793 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -34,6 +34,7 @@
#include <stdbool.h>
#include <sys/ioctl.h>
#include <sys/file.h>
+#include <sys/stat.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
@@ -2526,6 +2527,7 @@ static void convert_names_entry(char *key, char *value, void *user_data)
struct device_converter {
char *address;
void (*cb)(GKeyFile *key_file, void *value);
+ gboolean force;
};
static void convert_aliases_entry(GKeyFile *key_file, void *value)
@@ -2601,6 +2603,19 @@ static void convert_entry(char *key, char *value, void *user_data)
if (bachk(key) != 0)
return;
+ if (converter->force == FALSE) {
+ struct stat st;
+ int err;
+
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s",
+ converter->address, key);
+ filename[PATH_MAX] = '\0';
+
+ err = stat(filename, &st);
+ if (err || !S_ISDIR(st.st_mode))
+ return;
+ }
+
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
converter->address, key);
filename[PATH_MAX] = '\0';
@@ -2621,7 +2636,8 @@ static void convert_entry(char *key, char *value, void *user_data)
}
static void convert_file(char *file, char *address,
- void (*cb)(GKeyFile *key_file, void *value))
+ void (*cb)(GKeyFile *key_file, void *value),
+ gboolean force)
{
char filename[PATH_MAX + 1];
struct device_converter converter;
@@ -2636,6 +2652,7 @@ static void convert_file(char *file, char *address,
} else {
converter.address = address;
converter.cb = cb;
+ converter.force = force;
textfile_foreach(filename, convert_entry, &converter);
textfile_put(filename, "converted", "yes");
@@ -2665,19 +2682,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
free(str);
/* Convert aliases */
- convert_file("aliases", address, convert_aliases_entry);
+ convert_file("aliases", address, convert_aliases_entry, TRUE);
/* Convert trusts */
- convert_file("trusts", address, convert_trusts_entry);
-
- /* Convert classes */
- convert_file("classes", address, convert_classes_entry);
+ convert_file("trusts", address, convert_trusts_entry, TRUE);
/* Convert blocked */
- convert_file("blocked", address, convert_blocked_entry);
+ convert_file("blocked", address, convert_blocked_entry, TRUE);
+
+ /* Convert classes */
+ convert_file("classes", address, convert_classes_entry, FALSE);
/* Convert device ids */
- convert_file("did", address, convert_did_entry);
+ convert_file("did", address, convert_did_entry, FALSE);
}
static void convert_config(struct btd_adapter *adapter, const char *filename,
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 03/12] adapter: Fix device storage creation
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Create device storage directory and file only if there
is data to write.
---
src/adapter.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index f134dfe..8e3251b 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2604,14 +2604,17 @@ static void convert_entry(char *key, char *value, void *user_data)
snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
converter->address, key);
filename[PATH_MAX] = '\0';
- create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
key_file = g_key_file_new();
g_key_file_load_from_file(key_file, filename, 0, NULL);
converter->cb(key_file, value);
data = g_key_file_to_data(key_file, &length, NULL);
- g_file_set_contents(filename, data, length, NULL);
+ if (length > 0) {
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ g_file_set_contents(filename, data, length, NULL);
+ }
+
g_free(data);
g_key_file_free(key_file);
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 02/12] device: Load device info before updating info file
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1354286826-24016-1-git-send-email-frederic.danis@linux.intel.com>
Data in device info file should not be lost during save
even if they are not in device structure (like link key
and long term key).
---
src/device.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/device.c b/src/device.c
index a99ca34..1db8a48 100644
--- a/src/device.c
+++ b/src/device.c
@@ -217,17 +217,28 @@ static gboolean store_device_info_cb(gpointer user_data)
device->store_id = 0;
+ ba2str(adapter_get_address(device->adapter), adapter_addr);
+ ba2str(&device->bdaddr, device_addr);
+ snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
+ device_addr);
+ filename[PATH_MAX] = '\0';
+
key_file = g_key_file_new();
+ g_key_file_load_from_file(key_file, filename, 0, NULL);
g_key_file_set_string(key_file, "General", "Name", device->name);
if (device->alias != NULL)
g_key_file_set_string(key_file, "General", "Alias",
device->alias);
+ else
+ g_key_file_remove_key(key_file, "General", "Alias", NULL);
if (device->class) {
sprintf(class, "0x%6.6x", device->class);
g_key_file_set_string(key_file, "General", "Class", class);
+ } else {
+ g_key_file_remove_key(key_file, "General", "Class", NULL);
}
g_key_file_set_boolean(key_file, "General", "Trusted",
@@ -245,14 +256,10 @@ static gboolean store_device_info_cb(gpointer user_data)
device->product);
g_key_file_set_integer(key_file, "DeviceID", "Version",
device->version);
+ } else {
+ g_key_file_remove_group(key_file, "DeviceID", NULL);
}
- ba2str(adapter_get_address(device->adapter), adapter_addr);
- ba2str(&device->bdaddr, device_addr);
- snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", adapter_addr,
- device_addr);
- filename[PATH_MAX] = '\0';
-
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
str = g_key_file_to_data(key_file, &length, NULL);
--
1.7.9.5
^ permalink raw reply related
* [RFC V3 01/12] doc: Update settings-storage.txt
From: Frédéric Danis @ 2012-11-30 14:46 UTC (permalink / raw)
To: linux-bluetooth
Add missing Master key to LongTermKey group
---
doc/settings-storage.txt | 2 ++
1 file changed, 2 insertions(+)
diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index 3fdcb03..e7ba89d 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -181,6 +181,8 @@ Long term key) related to a remote device.
Authenticated Boolean True if remote device has been
authenticated
+ Master Boolean True for master key
+
EncSize Integer Encrypted size
EDiv Integer Encrypted diversifier
--
1.7.9.5
^ permalink raw reply related
* [PATCH v3 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Szymon Janc @ 2012-11-30 13:31 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-7-git-send-email-szymon.janc@tieto.com>
This makes adaptername plugin properly cleanup its fds on exit. Fixes
following warnings from valgrind:
16 bytes in 1 blocks are still reachable in loss record 42 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E93ABD: g_slist_prepend (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78350: g_source_add_poll (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5E32: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
18 bytes in 1 blocks are still reachable in loss record 58 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78A69: g_source_set_name (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5E0B: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
32 bytes in 1 blocks are still reachable in loss record 86 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78722: g_source_set_callback (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0DB: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
32 bytes in 1 blocks are still reachable in loss record 87 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E77285: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E775AF: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78115: g_source_attach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0E5: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
120 bytes in 1 blocks are still reachable in loss record 167 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565A9: adaptername_init (adaptername.c:298)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
120 bytes in 1 blocks are still reachable in loss record 168 of 221
at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FAE0: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78044: g_source_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5DF9: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
---
plugins/adaptername.c | 59 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 20 deletions(-)
diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index 2013b7b..179152f 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -50,8 +50,7 @@
#define MACHINE_INFO_DIR "/etc/"
#define MACHINE_INFO_FILE "machine-info"
-static GIOChannel *inotify = NULL;
-static int watch_d = -1;
+static guint watchid = 0;
/* This file is part of systemd's hostnamed functionality:
* http://0pointer.de/public/systemd-man/machine-info.html
@@ -266,20 +265,32 @@ static struct btd_adapter_driver adaptername_driver = {
.probe = adaptername_probe,
};
+struct inotify_data {
+ int inot_fd;
+ int watch_d;
+};
+
+static void destroy_cb(gpointer user_data)
+{
+ struct inotify_data *data = user_data;
+
+ inotify_rm_watch(data->inot_fd, data->watch_d);
+ g_free(data);
+}
+
static int adaptername_init(void)
{
- int err;
- int inot_fd;
guint32 mask;
-
- err = btd_register_adapter_driver(&adaptername_driver);
- if (err < 0)
- return err;
+ GIOChannel *inotify;
+ int inot_fd;
+ int watch_d;
+ struct inotify_data *data;
inot_fd = inotify_init();
if (inot_fd < 0) {
- error("Failed to setup inotify");
- return 0;
+ int err = -errno;
+ error("Failed to setup inotify: %s (%d)", strerror(-err), -err);
+ return err;
}
mask = IN_CLOSE_WRITE;
@@ -290,30 +301,38 @@ static int adaptername_init(void)
watch_d = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
if (watch_d < 0) {
- error("Failed to setup watch for '%s'", MACHINE_INFO_DIR);
+ int err = -errno;
+ error("Failed to setup watch for '%s': %s (%d)",
+ MACHINE_INFO_DIR, strerror(-err), -err);
close(inot_fd);
- return 0;
+ return err;
}
+ data = g_new(struct inotify_data, 1);
+ data->inot_fd = inot_fd;
+ data->watch_d = watch_d;
+
inotify = g_io_channel_unix_new(inot_fd);
g_io_channel_set_close_on_unref(inotify, TRUE);
g_io_channel_set_encoding(inotify, NULL, NULL);
g_io_channel_set_flags(inotify, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch(inotify, G_IO_IN, handle_inotify_cb, NULL);
+
+ watchid = g_io_add_watch_full(inotify, G_PRIORITY_DEFAULT, G_IO_IN,
+ handle_inotify_cb, data, destroy_cb);
+
+ g_io_channel_unref(inotify);
+
+ btd_register_adapter_driver(&adaptername_driver);
return 0;
}
static void adaptername_exit(void)
{
- if (watch_d >= 0 && inotify != NULL) {
- int inot_fd = g_io_channel_unix_get_fd(inotify);
- inotify_rm_watch(inot_fd, watch_d);
- }
- if (inotify != NULL) {
- g_io_channel_shutdown(inotify, FALSE, NULL);
- g_io_channel_unref(inotify);
+ if (watchid > 0) {
+ g_source_remove(watchid);
+ watchid = 0;
}
btd_unregister_adapter_driver(&adaptername_driver);
--
1.7.9.5
^ permalink raw reply related
* Re: [PATCH 1/4] proximity: Convert reporter properties to DBus.Properties
From: Johan Hedberg @ 2012-11-30 13:26 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1352464401-12702-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Fri, Nov 09, 2012, Andrzej Kaczmarek wrote:
> ---
> profiles/proximity/immalert.c | 5 ++--
> profiles/proximity/linkloss.c | 5 ++--
> profiles/proximity/reporter.c | 62 +++++++++++++++----------------------------
> 3 files changed, 25 insertions(+), 47 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply
* Re: [PATCH v2 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Anderson Lizardo @ 2012-11-30 13:22 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
In-Reply-To: <1354280264-19036-7-git-send-email-szymon.janc@tieto.com>
Hi Szymon,
On Fri, Nov 30, 2012 at 8:57 AM, Szymon Janc <szymon.janc@tieto.com> wrote:
> inot_fd = inotify_init();
> if (inot_fd < 0) {
> - error("Failed to setup inotify");
> - return 0;
> + int err = errno;
> + error("Failed to setup inotify: %s (%d)", strerror(-err), -err);
> + return -err;
Now it is broken :) By convention, "err" should be always negative, so use:
int err = -errno;
when printing the error, you need to make it positive, like above:
error("Failed to setup inotify: %s (%d)", strerror(-err), -err);
then when returning, use:
return err;
See other examples on the bluez code if you have doubts.
> @@ -290,30 +301,38 @@ static int adaptername_init(void)
>
> watch_d = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
> if (watch_d < 0) {
> - error("Failed to setup watch for '%s'", MACHINE_INFO_DIR);
> + int err = errno;
> + error("Failed to setup watch for '%s': %s (%d)",
> + MACHINE_INFO_DIR, strerror(-err), -err);
> close(inot_fd);
> - return 0;
> + return -err;
> }
Same problem here, please fix. (you can send just a v3 of this patch,
it should not conflict with others).
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply
* Re: [PATCH 00/15] thermometer plugin updates
From: Johan Hedberg @ 2012-11-30 13:06 UTC (permalink / raw)
To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1352451357-22097-1-git-send-email-andrzej.kaczmarek@tieto.com>
Hi Andrzej,
On Fri, Nov 09, 2012, Andrzej Kaczmarek wrote:
> Here are few patches to update thermometer plugin with features already
> implemented in other plugins:
> - store attributes handles directly in thermometer structure instead of
> nested lists of structures which we need to traverse later (and we
> only need 3 handles stored to support all use cases)
> - register attio handlers for specific handles instead of one ind and
> notif handler globally
> - change properties handling to DBus.Properties
> - and some minor fixes
>
> This is tested with PTS 4.5.3. There's only problem with patch #9 which
> "breaks" testcase TP/THF/CO/BV-09-I - this is because PTS sends invalid
> properties for Measurement Interval characteristic (it does not have
> indicate property so we do not register ind handler for it). I already
> filled issue on PTS.
>
> Comments are welcome.
>
>
> Andrzej Kaczmarek (15):
> thermometer: Store Temperature Measurement CCC handle in struct
> thermometer: Store Intermediate Temperature CCC handle in struct
> thermometer: Store Measurement Interval value handle in struct
> thermometer: Use dedicated handler for Intermediate Temperature
> thermometer: Use dedicated handler for Temperature Measurement
> thermometer: Use dedicated handler for Measurement Interval
> thermometer: Remove descriptor structure
> thermometer: Remove storage of all discovered characteristics
> thermometer: Discover Measurement Interval descriptors only if needed
> thermometer: Always write CCC value when connecting
> thermometer: Make temp_type array static
> thermometer: Add DBus.Properties support
> thermometer: Remove legacy properties code
> doc: Update thermometer API document
> test: Update test-thermometer for DBus.Properties
>
> doc/thermometer-api.txt | 18 -
> profiles/thermometer/thermometer.c | 1008 +++++++++++++++++-------------------
> test/test-thermometer | 13 +-
> 3 files changed, 478 insertions(+), 561 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply
* [PATCH v2 8/8] hog: Fix unregistering profile on exit
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
On exit should call btd_profile_unregister instead of
btd_profile_register. Fixes following:
16 bytes in 1 blocks are still reachable in loss record 54 of 215
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E93FC2: g_slist_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x17F6C2: btd_profile_register (profile.c:533)
by 0x171456: plugin_cleanup (plugin.c:242)
by 0x12164F: main (main.c:563)
16 bytes in 1 blocks are still reachable in loss record 37 of 215
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E93FC2: g_slist_append (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x17F6C2: btd_profile_register (profile.c:533)
by 0x1712EB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
---
profiles/input/hog_manager.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/profiles/input/hog_manager.c b/profiles/input/hog_manager.c
index 21ceb79..595b160 100644
--- a/profiles/input/hog_manager.c
+++ b/profiles/input/hog_manager.c
@@ -144,7 +144,7 @@ static void hog_manager_exit(void)
if (suspend_supported)
suspend_exit();
- btd_profile_register(&hog_profile);
+ btd_profile_unregister(&hog_profile);
}
static int hog_init(void)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 7/8] adaptername: Refactor adaptername_init/exit to fix exit path
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
This makes adaptername plugin properly cleanup its fds on exit. Fixes
following warnings from valgrind:
16 bytes in 1 blocks are still reachable in loss record 42 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E93ABD: g_slist_prepend (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78350: g_source_add_poll (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5E32: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
18 bytes in 1 blocks are still reachable in loss record 58 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78A69: g_source_set_name (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5E0B: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
32 bytes in 1 blocks are still reachable in loss record 86 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78722: g_source_set_callback (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0DB: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
32 bytes in 1 blocks are still reachable in loss record 87 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E77285: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E775AF: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78115: g_source_attach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0E5: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
120 bytes in 1 blocks are still reachable in loss record 167 of 221
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565A9: adaptername_init (adaptername.c:298)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
120 bytes in 1 blocks are still reachable in loss record 168 of 221
at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FAE0: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78044: g_source_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5DF9: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x1565FA: adaptername_init (adaptername.c:302)
by 0x1712AB: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:544)
---
plugins/adaptername.c | 59 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 20 deletions(-)
diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index 2013b7b..018e6f0 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -50,8 +50,7 @@
#define MACHINE_INFO_DIR "/etc/"
#define MACHINE_INFO_FILE "machine-info"
-static GIOChannel *inotify = NULL;
-static int watch_d = -1;
+static guint watchid = 0;
/* This file is part of systemd's hostnamed functionality:
* http://0pointer.de/public/systemd-man/machine-info.html
@@ -266,20 +265,32 @@ static struct btd_adapter_driver adaptername_driver = {
.probe = adaptername_probe,
};
+struct inotify_data {
+ int inot_fd;
+ int watch_d;
+};
+
+static void destroy_cb(gpointer user_data)
+{
+ struct inotify_data *data = user_data;
+
+ inotify_rm_watch(data->inot_fd, data->watch_d);
+ g_free(data);
+}
+
static int adaptername_init(void)
{
- int err;
- int inot_fd;
guint32 mask;
-
- err = btd_register_adapter_driver(&adaptername_driver);
- if (err < 0)
- return err;
+ GIOChannel *inotify;
+ int inot_fd;
+ int watch_d;
+ struct inotify_data *data;
inot_fd = inotify_init();
if (inot_fd < 0) {
- error("Failed to setup inotify");
- return 0;
+ int err = errno;
+ error("Failed to setup inotify: %s (%d)", strerror(-err), -err);
+ return -err;
}
mask = IN_CLOSE_WRITE;
@@ -290,30 +301,38 @@ static int adaptername_init(void)
watch_d = inotify_add_watch(inot_fd, MACHINE_INFO_DIR, mask);
if (watch_d < 0) {
- error("Failed to setup watch for '%s'", MACHINE_INFO_DIR);
+ int err = errno;
+ error("Failed to setup watch for '%s': %s (%d)",
+ MACHINE_INFO_DIR, strerror(-err), -err);
close(inot_fd);
- return 0;
+ return -err;
}
+ data = g_new(struct inotify_data, 1);
+ data->inot_fd = inot_fd;
+ data->watch_d = watch_d;
+
inotify = g_io_channel_unix_new(inot_fd);
g_io_channel_set_close_on_unref(inotify, TRUE);
g_io_channel_set_encoding(inotify, NULL, NULL);
g_io_channel_set_flags(inotify, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch(inotify, G_IO_IN, handle_inotify_cb, NULL);
+
+ watchid = g_io_add_watch_full(inotify, G_PRIORITY_DEFAULT, G_IO_IN,
+ handle_inotify_cb, data, destroy_cb);
+
+ g_io_channel_unref(inotify);
+
+ btd_register_adapter_driver(&adaptername_driver);
return 0;
}
static void adaptername_exit(void)
{
- if (watch_d >= 0 && inotify != NULL) {
- int inot_fd = g_io_channel_unix_get_fd(inotify);
- inotify_rm_watch(inot_fd, watch_d);
- }
- if (inotify != NULL) {
- g_io_channel_shutdown(inotify, FALSE, NULL);
- g_io_channel_unref(inotify);
+ if (watchid > 0) {
+ g_source_remove(watchid);
+ watchid = 0;
}
btd_unregister_adapter_driver(&adaptername_driver);
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 6/8] core: Free parsed options
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
There is no need to keep already parsed options in memory. This also
fix not freeing options at all.
2 bytes in 1 blocks are still reachable in loss record 1 of 153
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x167333: parse_debug (main.c:425)
by 0x4E839D8: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E8403F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E85233: g_option_context_parse (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x121084: main (main.c:462)
16 bytes in 2 blocks are still reachable in loss record 39 of 153
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E5D68B: g_convert_with_iconv (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E5D94B: g_convert (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E5DFBA: g_locale_to_utf8 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E837C7: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E8403F: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E85233: g_option_context_parse (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x121084: main (main.c:462)
---
src/main.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/main.c b/src/main.c
index ccb5fa5..bc53a8e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -344,6 +344,18 @@ static gboolean option_detach = TRUE;
static gboolean option_version = FALSE;
static gboolean option_udev = FALSE;
+static void free_options(void)
+{
+ g_free(option_debug);
+ option_debug = NULL;
+
+ g_free(option_plugin);
+ option_plugin = NULL;
+
+ g_free(option_noplugin);
+ option_noplugin = NULL;
+}
+
static guint last_adapter_timeout = 0;
static gboolean exit_timeout(gpointer data)
@@ -533,6 +545,9 @@ int main(int argc, char *argv[])
* daemon needs to be re-worked. */
plugin_init(config, option_plugin, option_noplugin);
+ /* no need to keep parsed option in memory */
+ free_options();
+
mgmt_err = mgmt_setup();
if (mgmt_err < 0) {
error("mgmt setup failed: %s", strerror(-mgmt_err));
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 5/8] attrib: Fix possible use after free
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
Move io channels unrefs after last use of channels.
---
src/attrib-server.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 8e20903..1a9bd69 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -127,13 +127,13 @@ static void gatt_server_free(struct gatt_server *server)
g_list_free_full(server->database, attrib_free);
if (server->l2cap_io != NULL) {
- g_io_channel_unref(server->l2cap_io);
g_io_channel_shutdown(server->l2cap_io, FALSE, NULL);
+ g_io_channel_unref(server->l2cap_io);
}
if (server->le_io != NULL) {
- g_io_channel_unref(server->le_io);
g_io_channel_shutdown(server->le_io, FALSE, NULL);
+ g_io_channel_unref(server->le_io);
}
g_slist_free_full(server->clients, (GDestroyNotify) channel_free);
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 4/8] hog: Fix memory leak in suspend-dummy
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
g_io_add_watch increase channel ref count but g_io_channel_shutdown
doesn't drop reference nor remove watch. Since close on unref is set
for channel and it is watch we are interested keep watch id and not
channel id and remove watch on exit.
6 bytes in 1 blocks are still reachable in loss record 11 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6CF95: g_io_channel_init (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB66FF: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDC5: fifo_open (suspend.c:109)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
16 bytes in 1 blocks are still reachable in loss record 45 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E93ABD: g_slist_prepend (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78350: g_source_add_poll (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5E32: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDF3: fifo_open (suspend.c:112)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
18 bytes in 1 blocks are still reachable in loss record 63 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78A69: g_source_set_name (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5E0B: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDF3: fifo_open (suspend.c:112)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
32 bytes in 1 blocks are still reachable in loss record 93 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78722: g_source_set_callback (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0DB: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDF3: fifo_open (suspend.c:112)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
32 bytes in 1 blocks are still reachable in loss record 94 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E92CA2: g_slice_alloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E77285: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E775AF: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78115: g_source_attach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0E5: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDF3: fifo_open (suspend.c:112)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
120 bytes in 1 blocks are still reachable in loss record 177 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDC5: fifo_open (suspend.c:109)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
120 bytes in 1 blocks are still reachable in loss record 178 of 235
at 0x4C29DB4: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FAE0: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E78044: g_source_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB5DF9: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6D0C3: g_io_add_watch_full (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x18DDF3: fifo_open (suspend.c:112)
by 0x18DF95: suspend_init (suspend.c:131)
by 0x140B53: hog_init (hog_manager.c:133)
by 0x17127B: plugin_init (plugin.c:217)
by 0x1215D2: main (main.c:532)
---
profiles/input/suspend-dummy.c | 38 +++++++++++++++++---------------------
1 file changed, 17 insertions(+), 21 deletions(-)
diff --git a/profiles/input/suspend-dummy.c b/profiles/input/suspend-dummy.c
index 58f7b9c..b43946d 100644
--- a/profiles/input/suspend-dummy.c
+++ b/profiles/input/suspend-dummy.c
@@ -44,7 +44,7 @@
static suspend_event suspend_cb = NULL;
static resume_event resume_cb = NULL;
-static GIOChannel *fifoio = NULL;
+static guint watch = 0;
static int fifo_open(void);
@@ -54,8 +54,15 @@ static gboolean read_fifo(GIOChannel *io, GIOCondition cond, gpointer user_data)
gsize offset, left, bread;
GIOStatus iostatus;
- if (cond & (G_IO_ERR | G_IO_HUP))
- goto failed;
+ if (cond & (G_IO_ERR | G_IO_HUP)) {
+ /*
+ * Both ends needs to be open simultaneously before proceeding
+ * any input or output operation. When the remote closes the
+ * channel, hup signal is received on this end.
+ */
+ fifo_open();
+ return FALSE;
+ }
offset = 0;
left = sizeof(buffer) - 1;
@@ -77,25 +84,12 @@ static gboolean read_fifo(GIOChannel *io, GIOCondition cond, gpointer user_data)
resume_cb();
return TRUE;
-
-failed:
- /*
- * Both ends needs to be open simultaneously before proceeding
- * any input or output operation. When the remote closes the
- * channel, hup signal is received on this end.
- */
-
- g_io_channel_unref(fifoio);
- fifoio = NULL;
-
- fifo_open();
-
- return FALSE;
}
static int fifo_open(void)
{
GIOCondition condition = G_IO_IN | G_IO_ERR | G_IO_HUP;
+ GIOChannel *fifoio;
int fd;
fd = open(HOG_SUSPEND_FIFO, O_RDONLY | O_NONBLOCK);
@@ -109,7 +103,9 @@ static int fifo_open(void)
fifoio = g_io_channel_unix_new(fd);
g_io_channel_set_close_on_unref(fifoio, TRUE);
- g_io_add_watch(fifoio, condition, read_fifo, NULL);
+ watch = g_io_add_watch(fifoio, condition, read_fifo, NULL);
+
+ g_io_channel_unref(fifoio);
return 0;
}
@@ -137,9 +133,9 @@ int suspend_init(suspend_event suspend, resume_event resume)
void suspend_exit(void)
{
- if (fifoio) {
- g_io_channel_shutdown(fifoio, FALSE, NULL);
- g_io_channel_unref(fifoio);
+ if (watch > 0) {
+ g_source_remove(watch);
+ watch = 0;
}
remove(HOG_SUSPEND_FIFO);
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 3/8] rfkill: Fix memory leak in rfkill_exit
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
g_io_add_watch increase channel ref count but g_io_channel_shutdown
doesn't drop reference nor remove watch. Since close on unref is set
for channel and it is watch we are interested keep watch id and not
channel id and remove watch on exit.
120 bytes in 1 blocks are still reachable in loss record 181 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x167B8D: rfkill_init (rfkill.c:157)
by 0x1215E4: main (main.c:540)
6 bytes in 1 blocks are still reachable in loss record 12 of 235
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E942DD: g_strdup (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4E6CF95: g_io_channel_init (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x4EB66FF: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
by 0x167B8D: rfkill_init (rfkill.c:157)
by 0x1215E4: main (main.c:540)
---
src/rfkill.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/rfkill.c b/src/rfkill.c
index b40c6e7..f82596b 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -139,11 +139,12 @@ static gboolean rfkill_event(GIOChannel *chan,
return TRUE;
}
-static GIOChannel *channel = NULL;
+static guint watch = 0;
void rfkill_init(void)
{
int fd;
+ GIOChannel *channel;
if (!main_opts.remember_powered)
return;
@@ -157,17 +158,18 @@ void rfkill_init(void)
channel = g_io_channel_unix_new(fd);
g_io_channel_set_close_on_unref(channel, TRUE);
- g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
- rfkill_event, NULL);
+ watch = g_io_add_watch(channel,
+ G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+ rfkill_event, NULL);
+
+ g_io_channel_unref(channel);
}
void rfkill_exit(void)
{
- if (!channel)
+ if (watch == 0)
return;
- g_io_channel_shutdown(channel, TRUE, NULL);
- g_io_channel_unref(channel);
-
- channel = NULL;
+ g_source_remove(watch);
+ watch = 0;
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 2/8] doc: Update valgrind.suppressions with some libdbus suppressions
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1354280264-19036-1-git-send-email-szymon.janc@tieto.com>
Suppress some useless libdbus warnings.
---
doc/valgrind.suppressions | 81 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 80 insertions(+), 1 deletion(-)
diff --git a/doc/valgrind.suppressions b/doc/valgrind.suppressions
index 5967a15..07f3238 100644
--- a/doc/valgrind.suppressions
+++ b/doc/valgrind.suppressions
@@ -233,4 +233,83 @@
fun:dbus_connection_send_with_reply_and_block
fun:dbus_bus_register
}
-
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:malloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:g_dbus_setup_bus
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:calloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:g_dbus_setup_bus
+ fun:connect_dbus
+ ...
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:realloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:dbus_connection_send_with_reply_and_block
+ fun:dbus_bus_register
+ ...
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:calloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:dbus_connection_send_with_reply_and_block
+ fun:dbus_bus_register
+ ...
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:malloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:dbus_connection_send_with_reply_and_block
+ fun:dbus_bus_register
+ ...
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:calloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:dbus_connection_send_with_reply_and_block
+ fun:dbus_bus_request_name
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:realloc
+ ...
+ obj:/lib/*/libdbus-*
+ ...
+ fun:dbus_connection_send_with_reply_and_block
+ fun:dbus_bus_request_name
+}
+{
+ <insert_a_suppression_name_here>
+ Memcheck:Leak
+ fun:realloc
+ ...
+ obj:/lib/*/libdbus-*
+}
--
1.7.9.5
^ permalink raw reply related
* [PATCH v2 1/8] doc: Add valgrind.suppressions
From: Szymon Janc @ 2012-11-30 12:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Shamelessly copied from connman.
---
doc/valgrind.suppressions | 236 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 236 insertions(+)
create mode 100644 doc/valgrind.suppressions
diff --git a/doc/valgrind.suppressions b/doc/valgrind.suppressions
new file mode 100644
index 0000000..5967a15
--- /dev/null
+++ b/doc/valgrind.suppressions
@@ -0,0 +1,236 @@
+{
+ <syslog error>
+ Memcheck:Cond
+ obj:/lib/libc-*.so
+ ...
+ fun:localtime_r
+ fun:__vsyslog_chk
+ fun:__syslog_chk
+ fun:__connman_log_init
+ ...
+}
+{
+ <iconv open>
+ Memcheck:Addr4
+ obj:/lib/libc-*.so
+ obj:/lib/libglib-2.0.so*
+ fun:g_iconv_open
+ ...
+ fun:g_convert
+ fun:g_locale_to_utf8
+ fun:g_strerror
+ fun:g_key_file_load_from_file
+ ...
+}
+{
+ <ioctl ADDRT/DELRT>
+ Memcheck:Param
+ ioctl(SIOCADDRT/DELRT)
+ obj:/lib/ld-*.so
+ ...
+}
+{
+ <g_main_loop>
+ Memcheck:Leak
+ fun:memalign
+ ...
+ fun:g_slice_alloc
+ ...
+ fun:g_main_loop_new
+ ...
+}
+{
+ <g_option_context_parse>
+ Memcheck:Leak
+ ...
+ fun:g_slice_alloc
+ ...
+ fun:g_option_context_parse
+ ...
+}
+{
+ <g_key_file_load_from_data>
+ Memcheck:Leak
+ ...
+ fun:g_slice_alloc
+ ...
+ fun:g_key_file_load_from_data
+ ...
+}
+{
+ <g_key_file_new 1>
+ Memcheck:Leak
+ ...
+ fun:g_slice_alloc
+ ...
+ fun:g_key_file_new
+ ...
+}
+{
+ <g_key_file_new 2>
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:g_key_file_new
+ fun:main
+}
+{
+ <connman plugin cleanup>
+ Memcheck:Leak
+ ...
+ fun:__connman_plugin_cleanup
+ ...
+}
+{
+ <cmd line option parsing>
+ Memcheck:Leak
+ fun:malloc
+ fun:g_malloc
+ fun:g_strdup
+ fun:g_set_prgname
+ fun:g_option_context_parse
+ fun:main
+}
+{
+ <dbus system bus setup 1>
+ Memcheck:Leak
+ ...
+ fun:dbus_malloc*
+ ...
+ fun:g_dbus_setup_bus
+ fun:main
+}
+{
+ <dbus system bus setup 2>
+ Memcheck:Leak
+ ...
+ fun:g_malloc*
+ ...
+ fun:dbus_connection_set_watch_functions
+ fun:setup_bus
+ ...
+}
+{
+ <key file get charset>
+ Memcheck:Leak
+ ...
+ fun:g_*alloc*
+ ...
+ fun:g_strerror
+ fun:g_key_file_load_from_file
+ fun:main
+}
+{
+ <dbus disconnect func set>
+ Memcheck:Leak
+ ...
+ fun:filter_data_get
+ fun:g_dbus_add_signal_watch
+ fun:g_dbus_set_disconnect_function
+ fun:main
+}
+{
+ <plugin dlopen>
+ Memcheck:Leak
+ ...
+ fun:dlopen
+ fun:__connman_plugin_init
+ fun:main
+}
+{
+ <dbus system bus setup 3>
+ Memcheck:Leak
+ ...
+ fun:dbus_malloc0
+ ...
+ fun:dbus_parse_address
+ ...
+ fun:g_dbus_setup_bus
+ fun:main
+}
+{
+ <libdbus internals 1>
+ Memcheck:Leak
+ fun:*malloc
+ ...
+ obj:/lib/libdbus-1.so.3.5.3
+}
+{
+ <dbus system bus setup 4>
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:dbus_*alloc*
+ ...
+ fun:g_dbus_setup_bus
+ fun:main
+}
+{
+ <dbus system bus setup 5>
+ Memcheck:Leak
+ fun:calloc
+ fun:g_malloc0
+ ...
+ fun:g_dbus_set_disconnect_function
+ fun:main
+}
+{
+ <dbus bus remove match>
+ Memcheck:Leak
+ fun:malloc
+ fun:g_malloc
+ fun:g_source_set_callback
+ fun:g_timeout_add_full
+ fun:g_timeout_add
+ ...
+ fun:dbus_pending_call_block
+ fun:dbus_connection_send_with_reply_and_block
+ ...
+ fun:dbus_bus_remove_match
+}
+{
+ <g_main_loop_run/new>
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:g_main_loop_*
+ fun:main
+}
+{
+ <g_main_context_dispatch>
+ Memcheck:Leak
+ fun:*alloc
+ ...
+ fun:g_main_context_dispatch
+}
+{
+ <libdbus internals 2>
+ Memcheck:Leak
+ fun:realloc
+ fun:dbus_realloc
+ ...
+ fun:dbus_message_set_reply_serial
+ fun:dbus_message_new_error
+ ...
+}
+{
+ <libdbus internals 3>
+ Memcheck:Leak
+ fun:realloc
+ fun:dbus_realloc
+ ...
+ fun:dbus_message_new_signal
+ ...
+}
+{
+ <dbus_bus_register>
+ Memcheck:Leak
+ fun:malloc
+ fun:realloc
+ fun:dbus_realloc
+ ...
+ fun:dbus_pending_call_block
+ fun:dbus_connection_send_with_reply_and_block
+ fun:dbus_bus_register
+}
+
--
1.7.9.5
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox