diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 1dd0c35..e1d8407 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
if (g_option_context_parse(context, &argc, &argv, &gerr) == FALSE) {
g_printerr("%s\n", gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
if (opt_interactive) {
}
chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
- opt_psm, opt_mtu, connect_cb);
+ opt_psm, opt_mtu, connect_cb, &gerr);
if (chan == NULL) {
+ g_printerr("%s\n", gerr->message);
+ g_clear_error(&gerr);
got_error = TRUE;
goto done;
}
diff --git a/attrib/gatttool.h b/attrib/gatttool.h
index 260480d..184a7f8 100644
--- a/attrib/gatttool.h
+++ b/attrib/gatttool.h
int psm);
GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
const gchar *dst_type, const gchar *sec_level,
- int psm, int mtu, BtIOConnect connect_cb);
+ int psm, int mtu, BtIOConnect connect_cb,
+ GError **gerr);
size_t gatt_attr_data_from_string(const char *str, uint8_t **data);
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 9f72453..ce35218 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
static void cmd_connect(int argcp, char **argvp)
{
+ GError *gerr = NULL;
+
if (conn_state != STATE_DISCONNECTED)
return;
set_state(STATE_CONNECTING);
iochannel = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
- opt_psm, opt_mtu, connect_cb);
- if (iochannel == NULL)
+ opt_psm, opt_mtu, connect_cb, &gerr);
+ if (iochannel == NULL) {
+ printf("%s\n", gerr->message);
set_state(STATE_DISCONNECTED);
- else
+ g_error_free(gerr);
+ } else
g_io_add_watch(iochannel, G_IO_HUP, channel_watcher, NULL);
}
diff --git a/attrib/utils.c b/attrib/utils.c
index c8c8651..e263bcb 100644
--- a/attrib/utils.c
+++ b/attrib/utils.c
GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
const gchar *dst_type, const gchar *sec_level,
- int psm, int mtu, BtIOConnect connect_cb)
+ int psm, int mtu, BtIOConnect connect_cb,
+ GError **gerr)
{
GIOChannel *chan;
bdaddr_t sba, dba;
uint8_t dest_type;
- GError *err = NULL;
+ GError *tmp_err = NULL;
BtIOSecLevel sec;
str2ba(dst, &dba);
sec = BT_IO_SEC_LOW;
if (psm == 0)
- chan = bt_io_connect(connect_cb, NULL, NULL, &err,
+ chan = bt_io_connect(connect_cb, NULL, NULL, &tmp_err,
BT_IO_OPT_SOURCE_BDADDR, &sba,
BT_IO_OPT_DEST_BDADDR, &dba,
BT_IO_OPT_DEST_TYPE, dest_type,
BT_IO_OPT_SEC_LEVEL, sec,
BT_IO_OPT_INVALID);
else
- chan = bt_io_connect(connect_cb, NULL, NULL, &err,
+ chan = bt_io_connect(connect_cb, NULL, NULL, &tmp_err,
BT_IO_OPT_SOURCE_BDADDR, &sba,
BT_IO_OPT_DEST_BDADDR, &dba,
BT_IO_OPT_PSM, psm,
BT_IO_OPT_SEC_LEVEL, sec,
BT_IO_OPT_INVALID);
- if (err) {
- g_printerr("%s\n", err->message);
- g_error_free(err);
+ if (tmp_err) {
+ g_propagate_error(gerr, tmp_err);
return NULL;
}