Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 04/14] Bluetooth: Check skb_clone return to avoid NULL dereference
From: Gustavo F. Padovan @ 2010-06-05  7:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo, marcel, Gustavo F. Padovan
In-Reply-To: <1275724218-29453-4-git-send-email-gustavo@padovan.org>

From: Gustavo F. Padovan <padovan@profusion.mobi>

skb can be NULL and a Ooops can happen if we do not check for NULL.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Reviewed-by: João Paulo Rechi Vita <jprvita@profusion.mobi>
---
 net/bluetooth/l2cap.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index b08731d..27e69f6 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -1335,6 +1335,8 @@ static int l2cap_streaming_send(struct sock *sk)
 
 	while ((skb = sk->sk_send_head)) {
 		tx_skb = skb_clone(skb, GFP_ATOMIC);
+		if (!tx_skb)
+			break;
 
 		control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
 		control |= pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT;
@@ -1420,6 +1422,8 @@ static int l2cap_ertm_send(struct sock *sk)
 		}
 
 		tx_skb = skb_clone(skb, GFP_ATOMIC);
+		if (!tx_skb)
+			break;
 
 		bt_cb(skb)->retries++;
 
-- 
1.7.1

^ permalink raw reply related

* [PATCH 03/14] Bluetooth: Fix drop of packets with invalid req_seq/tx_seq
From: Gustavo F. Padovan @ 2010-06-05  7:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo, marcel, Gustavo F. Padovan
In-Reply-To: <1275724218-29453-3-git-send-email-gustavo@padovan.org>

From: Gustavo F. Padovan <padovan@profusion.mobi>

We can't use an unsigned var since we are expecting negatives value
there too.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/l2cap.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index e036419..b08731d 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -3789,7 +3789,7 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str
 	u8 tx_seq = __get_txseq(rx_control);
 	u8 req_seq = __get_reqseq(rx_control);
 	u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT;
-	u8 tx_seq_offset, expected_tx_seq_offset;
+	int tx_seq_offset, expected_tx_seq_offset;
 	int num_to_ack = (pi->tx_win/6) + 1;
 	int err = 0;
 
@@ -4074,7 +4074,8 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
 	struct sock *sk;
 	struct l2cap_pinfo *pi;
 	u16 control, len;
-	u8 tx_seq, req_seq, next_tx_seq_offset, req_seq_offset;
+	u8 tx_seq, req_seq;
+	int next_tx_seq_offset, req_seq_offset;
 
 	sk = l2cap_get_chan_by_scid(&conn->chan_list, cid);
 	if (!sk) {
-- 
1.7.1

^ permalink raw reply related

* [PATCH 02/14] Bluetooth: Remove L2CAP Extended Features from Kconfig
From: Gustavo F. Padovan @ 2010-06-05  7:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo, marcel, Gustavo F. Padovan
In-Reply-To: <1275724218-29453-2-git-send-email-gustavo@padovan.org>

From: Gustavo F. Padovan <padovan@profusion.mobi>

This reverts commit 84fb0a6334af0ccad3544f6972c055d90fbb9fbe
One can use other mechanisms to enable L2CAP Extended Features.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/Kconfig |   13 -------------
 net/bluetooth/l2cap.c |    4 ----
 2 files changed, 0 insertions(+), 17 deletions(-)

diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index ee3b304..ed37168 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -43,19 +43,6 @@ config BT_L2CAP
 	  Say Y here to compile L2CAP support into the kernel or say M to
 	  compile it as module (l2cap).
 
-config BT_L2CAP_EXT_FEATURES
-	bool "L2CAP Extended Features support (EXPERIMENTAL)"
-	depends on BT_L2CAP && EXPERIMENTAL
-	help
-	  This option enables the L2CAP Extended Features support. These
-	  new features include the Enhanced Retransmission and Streaming
-	  Modes, the Frame Check Sequence (FCS), and Segmentation and
-	  Reassembly (SAR) for L2CAP packets. They are a required for the
-	  new Alternate MAC/PHY and the Bluetooth Medical Profile.
-
-	  You should say N unless you know what you are doing. Note that
-	  this is in an experimental state yet.
-
 config BT_SCO
 	tristate "SCO links support"
 	depends on BT
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 5c636b3..e036419 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -55,11 +55,7 @@
 
 #define VERSION "2.14"
 
-#ifdef CONFIG_BT_L2CAP_EXT_FEATURES
-static int enable_ertm = 1;
-#else
 static int enable_ertm = 0;
-#endif
 
 static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
 static u8 l2cap_fixed_chan[8] = { 0x02, };
-- 
1.7.1

^ permalink raw reply related

* [PATCH 01/14] Bluetooth: Remove max_tx and tx_window modules paramenter from L2CAP
From: Gustavo F. Padovan @ 2010-06-05  7:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo, marcel, Gustavo F. Padovan
In-Reply-To: <1275724218-29453-1-git-send-email-gustavo@padovan.org>

From: Gustavo F. Padovan <padovan@profusion.mobi>

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/l2cap.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 1b682a5..5c636b3 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -60,8 +60,6 @@ static int enable_ertm = 1;
 #else
 static int enable_ertm = 0;
 #endif
-static int max_transmit = L2CAP_DEFAULT_MAX_TX;
-static int tx_window = L2CAP_DEFAULT_TX_WINDOW;
 
 static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
 static u8 l2cap_fixed_chan[8] = { 0x02, };
@@ -808,9 +806,9 @@ static void l2cap_sock_init(struct sock *sk, struct sock *parent)
 			pi->mode = L2CAP_MODE_ERTM;
 		else
 			pi->mode = L2CAP_MODE_BASIC;
-		pi->max_tx = max_transmit;
+		pi->max_tx = L2CAP_DEFAULT_MAX_TX;
 		pi->fcs  = L2CAP_FCS_CRC16;
-		pi->tx_win = tx_window;
+		pi->tx_win = L2CAP_DEFAULT_TX_WINDOW;
 		pi->sec_level = BT_SECURITY_LOW;
 		pi->role_switch = 0;
 		pi->force_reliable = 0;
@@ -4674,12 +4672,6 @@ module_exit(l2cap_exit);
 module_param(enable_ertm, bool, 0644);
 MODULE_PARM_DESC(enable_ertm, "Enable enhanced retransmission mode");
 
-module_param(max_transmit, uint, 0644);
-MODULE_PARM_DESC(max_transmit, "Max transmit value (default = 3)");
-
-module_param(tx_window, uint, 0644);
-MODULE_PARM_DESC(tx_window, "Transmission window size value (default = 63)");
-
 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
 MODULE_DESCRIPTION("Bluetooth L2CAP ver " VERSION);
 MODULE_VERSION(VERSION);
-- 
1.7.1

^ permalink raw reply related

* Pull request: Fixes for the Enhanced Retransmission Mode
From: Gustavo F. Padovan @ 2010-06-05  7:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo, marcel

Hi Marcel,

The following changes since commit 67a3e12b05e055c0415c556a315a3d3eb637e29e:

  Linux 2.6.35-rc1 (2010-05-30 13:21:02 -0700)

are available in the git repository at:
  git://git.kernel.org/pub/scm/linux/kernel/git/padovan/bluetooth-testing.git for-upstream

Gustavo F. Padovan (13):
      Bluetooth: Remove max_tx and tx_window modules paramenter from L2CAP
      Bluetooth: Remove L2CAP Extended Features from Kconfig
      Bluetooth: Fix drop of packets with invalid req_seq/tx_seq
      Bluetooth: Check skb_clone return to avoid NULL dereference
      Bluetooth: Fix ERTM vars increment
      Bluetooth: Check packet FCS earlier
      Bluetooth: Only check SAR bits if frame is I-frame
      Bluetooth: Stop ack_timer if ERTM enters in Local Busy or SREJ_SENT
      Bluetooth: Fix ERTM channel shutdown
      Bluetooth: Fix crash when sending frames after connection is closed
      Bluetooth: Fix handle of received P-bit
      Bluetooth: Fix l2cap_ertm_send() behavior
      Bluetooth: Fix missing retransmission action with RR(P=1)

João Paulo Rechi Vita (1):
      Bluetooth: Fix SREJ_QUEUE corruption

 net/bluetooth/Kconfig |   13 ----
 net/bluetooth/l2cap.c |  156 +++++++++++++++++++++++++++++++------------------
 2 files changed, 99 insertions(+), 70 deletions(-)

^ permalink raw reply

* [PATCH 5/5] Document the new Debug and DebugString property
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275722736-28895-4-git-send-email-gustavo@padovan.org>

---
 doc/manager-api.txt |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index d2c1caf..07d4fde 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -22,6 +22,15 @@ Methods		dict GetProperties()
 			Possible Errors: org.bluez.Error.DoesNotExist
 					 org.bluez.Error.InvalidArguments
 
+		void SetProperty(string name, variant value)
+
+			Changes the value of the specified property. Only
+			properties that are listed a read-write are changeable.
+			On success this will emit a PropertyChanged signal.
+
+			Possible Errors: org.bluez.Error.DoesNotExist
+					 org.bluez.Error.InvalidArguments
+
 		object DefaultAdapter()
 
 			Returns object path for the default adapter.
@@ -72,3 +81,13 @@ Signals		PropertyChanged(string name, variant value)
 Properties	array{object} Adapters [readonly]
 
 			List of adapter object paths.
+
+		boolean Debug [readwrite]
+
+			Switch dynamic debug on or off.
+
+		string DebugString [readwrite]
+
+			Change the dynamic debug match string. Use it to
+			restrict debug to specific files. The default value is
+			"*" to debug all files.
-- 
1.7.1


^ permalink raw reply related

* [PATCH 4/5] Add DebugString Property to Manager
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275722736-28895-3-git-send-email-gustavo@padovan.org>

---
 src/manager.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 66e1511..220a8fe 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -96,6 +96,31 @@ static DBusMessage *set_debug(DBusConnection *conn, DBusMessage *msg,
 	return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *set_debug_string(DBusConnection *conn, DBusMessage *msg,
+					const char *debug_string, void *data)
+{
+	char *old_string;
+
+	if (!g_utf8_validate(debug_string, -1, NULL)) {
+		error("DebugString change failed: supplied string "
+							"isn't valid UTF-8");
+		return invalid_args(msg);
+	}
+
+	old_string = __btd_get_debug_string();
+
+	if (strcmp((char *)debug_string, old_string) == 0)
+		return dbus_message_new_method_return(msg);
+
+	if (!__btd_set_debug_string((char *)debug_string))
+		return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+							strerror(ENOMEM));
+	emit_property_changed(connection, "/", MANAGER_INTERFACE,
+				"DebugString", DBUS_TYPE_STRING, &debug_string);
+
+	return dbus_message_new_method_return(msg);
+}
+
 static DBusMessage *default_adapter(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -200,6 +225,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	GSList *list;
 	char **array;
 	gboolean debug_value;
+	char *debug_string;
 	int i;
 
 	reply = dbus_message_new_method_return(msg);
@@ -228,6 +254,10 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	debug_value = __btd_debug_enabled();
 	dict_append_entry(&dict, "Debug", DBUS_TYPE_BOOLEAN, &debug_value);
 
+	debug_string = __btd_get_debug_string();
+	dict_append_entry(&dict, "DebugString", DBUS_TYPE_STRING,
+							&debug_string);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
@@ -262,6 +292,14 @@ static DBusMessage *set_property(DBusConnection *conn,
 		dbus_message_iter_get_basic(&sub, &debug);
 
 		return set_debug(conn, msg, debug, data);
+	} else if (g_str_equal("DebugString", property)) {
+		const char *string;
+
+		if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
+			return invalid_args(msg);
+		dbus_message_iter_get_basic(&sub, &string);
+
+		return set_debug_string(conn, msg, string, data);
 	}
 
 	return invalid_args(msg);
-- 
1.7.1


^ permalink raw reply related

* [PATCH 3/5] log: Add function to get/set debug_string
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275722736-28895-2-git-send-email-gustavo@padovan.org>

---
 src/log.c |   56 +++++++++++++++++++++++++++++++++++++++++---------------
 src/log.h |    2 ++
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/src/log.c b/src/log.c
index 4043ee3..f0f2465 100644
--- a/src/log.c
+++ b/src/log.c
@@ -72,6 +72,7 @@ extern struct btd_debug_desc __stop___debug[];
 static gchar **enabled = NULL;
 
 int debug_enabled = FALSE;
+static char *debug_string = NULL;
 
 static gboolean is_enabled(struct btd_debug_desc *desc)
 {
@@ -92,6 +93,44 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
         return 0;
 }
 
+static void debug_on()
+{
+	struct btd_debug_desc *desc;
+	const char *name = NULL, *file = NULL;
+
+	enabled = g_strsplit_set(debug_string, ":, ", 0);
+
+	for (desc = __start___debug; desc < __stop___debug; desc++) {
+		if (file != NULL || name != NULL) {
+			if (g_strcmp0(desc->file, file) == 0) {
+				if (desc->name == NULL)
+					desc->name = name;
+			} else
+				file = NULL;
+		}
+
+		if (is_enabled(desc))
+			desc->flags |= BTD_DEBUG_FLAG_PRINT;
+		else
+			desc->flags &= ~BTD_DEBUG_FLAG_PRINT;
+	}
+}
+
+char *__btd_get_debug_string()
+{
+	return debug_string;
+}
+
+char *__btd_set_debug_string(char *str)
+{
+	g_free(debug_string);
+	debug_string = g_strdup(str);
+
+	debug_on();
+
+	return debug_string;
+}
+
 void __btd_toggle_debug()
 {
 	debug_enabled = !debug_enabled;
@@ -105,8 +144,6 @@ int __btd_debug_enabled()
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
-	struct btd_debug_desc *desc;
-	const char *name = NULL, *file = NULL;
 
 	if (debug != NULL) {
 		debug_enabled = TRUE;
@@ -115,20 +152,9 @@ void __btd_log_init(const char *debug, int detach)
 		debug_enabled = FALSE;
 	}
 
-	enabled = g_strsplit_set(debug, ":, ", 0);
-
-	for (desc = __start___debug; desc < __stop___debug; desc++) {
-		if (file != NULL || name != NULL) {
-			if (g_strcmp0(desc->file, file) == 0) {
-				if (desc->name == NULL)
-					desc->name = name;
-			} else
-				file = NULL;
-		}
+	debug_string = (char *)debug;
 
-		if (is_enabled(desc))
-			desc->flags |= BTD_DEBUG_FLAG_PRINT;
-	}
+	debug_on();
 
 	if (!detach)
 		option |= LOG_PERROR;
diff --git a/src/log.h b/src/log.h
index 681e71d..392c716 100644
--- a/src/log.h
+++ b/src/log.h
@@ -29,6 +29,8 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
+char *__btd_get_debug_string();
+char *__btd_set_debug_string(char *str);
 void __btd_toggle_debug();
 int __btd_debug_enabled();
 
-- 
1.7.1


^ permalink raw reply related

* [PATCH 2/5] Add SetProperty method and Debug read/write property
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275722736-28895-1-git-send-email-gustavo@padovan.org>

---
 src/manager.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index eab7e80..66e1511 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -80,6 +80,22 @@ static inline DBusMessage *no_such_adapter(DBusMessage *msg)
 			"No such adapter");
 }
 
+static DBusMessage *set_debug(DBusConnection *conn, DBusMessage *msg,
+				gboolean debug, void *data)
+{
+	gboolean old_debug = __btd_debug_enabled();
+
+	if (debug == old_debug)
+		return dbus_message_new_method_return(msg);
+
+	__btd_toggle_debug(debug);
+
+	emit_property_changed(connection, "/" , MANAGER_INTERFACE, "Debug",
+				DBUS_TYPE_BOOLEAN, &debug);
+
+	return dbus_message_new_method_return(msg);
+}
+
 static DBusMessage *default_adapter(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -217,8 +233,44 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	return reply;
 }
 
+static DBusMessage *set_property(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessageIter iter;
+	DBusMessageIter sub;
+	const char *property;
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return invalid_args(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return invalid_args(msg);
+
+	dbus_message_iter_get_basic(&iter, &property);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return invalid_args(msg);
+	dbus_message_iter_recurse(&iter, &sub);
+
+	if (g_str_equal("Debug", property)) {
+		gboolean debug;
+
+		if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_BOOLEAN)
+			return invalid_args(msg);
+
+		dbus_message_iter_get_basic(&sub, &debug);
+
+		return set_debug(conn, msg, debug, data);
+	}
+
+	return invalid_args(msg);
+}
+
 static GDBusMethodTable manager_methods[] = {
 	{ "GetProperties",	"",	"a{sv}",get_properties	},
+	{ "SetProperty",	"sv",	"",	set_property,
+						G_DBUS_METHOD_FLAG_ASYNC},
 	{ "DefaultAdapter",	"",	"o",	default_adapter	},
 	{ "FindAdapter",	"s",	"o",	find_adapter	},
 	{ "ListAdapters",	"",	"ao",	list_adapters,
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/5] Add Debug property to Manager interface
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

---
 src/log.c     |    5 +++++
 src/log.h     |    1 +
 src/manager.c |    4 ++++
 3 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/log.c b/src/log.c
index 1bc0a42..4043ee3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -97,6 +97,11 @@ void __btd_toggle_debug()
 	debug_enabled = !debug_enabled;
 }
 
+int __btd_debug_enabled()
+{
+	return debug_enabled;
+}
+
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
diff --git a/src/log.h b/src/log.h
index c9412c4..681e71d 100644
--- a/src/log.h
+++ b/src/log.h
@@ -30,6 +30,7 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
 void __btd_toggle_debug();
+int __btd_debug_enabled();
 
 struct btd_debug_desc {
         const char *name;
diff --git a/src/manager.c b/src/manager.c
index cbbca1e..eab7e80 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -183,6 +183,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	DBusMessageIter dict;
 	GSList *list;
 	char **array;
+	gboolean debug_value;
 	int i;
 
 	reply = dbus_message_new_method_return(msg);
@@ -208,6 +209,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	dict_append_array(&dict, "Adapters", DBUS_TYPE_OBJECT_PATH, &array, i);
 	g_free(array);
 
+	debug_value = __btd_debug_enabled();
+	dict_append_entry(&dict, "Debug", DBUS_TYPE_BOOLEAN, &debug_value);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
-- 
1.7.1


^ permalink raw reply related

* [PATCH] Fix regression with debug via SIGUSR2
From: Gustavo F. Padovan @ 2010-06-05  4:51 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275712886-20127-3-git-send-email-gustavo@padovan.org>

The new dynamic debug feature was not using the SIGUSR2 signal so this was
causing bluetoothd to crash when one tries to toggle debug via SIGUSR2.
This patch brings back such compatibility andadds debug_string and
debug_enabled vars.
---
 src/log.c  |   17 +++++++++++++++--
 src/log.h  |    4 +++-
 src/main.c |    8 ++++++++
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/log.c b/src/log.c
index cb02aad..1bc0a42 100644
--- a/src/log.c
+++ b/src/log.c
@@ -71,6 +71,8 @@ extern struct btd_debug_desc __stop___debug[];
 
 static gchar **enabled = NULL;
 
+int debug_enabled = FALSE;
+
 static gboolean is_enabled(struct btd_debug_desc *desc)
 {
         int i;
@@ -90,14 +92,25 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
         return 0;
 }
 
+void __btd_toggle_debug()
+{
+	debug_enabled = !debug_enabled;
+}
+
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
 	struct btd_debug_desc *desc;
 	const char *name = NULL, *file = NULL;
 
-	if (debug != NULL)
-		enabled = g_strsplit_set(debug, ":, ", 0);
+	if (debug != NULL) {
+		debug_enabled = TRUE;
+	} else {
+		debug = g_strdup("*");
+		debug_enabled = FALSE;
+	}
+
+	enabled = g_strsplit_set(debug, ":, ", 0);
 
 	for (desc = __start___debug; desc < __stop___debug; desc++) {
 		if (file != NULL || name != NULL) {
diff --git a/src/log.h b/src/log.h
index 33168c7..c9412c4 100644
--- a/src/log.h
+++ b/src/log.h
@@ -29,6 +29,7 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
+void __btd_toggle_debug();
 
 struct btd_debug_desc {
         const char *name;
@@ -51,7 +52,8 @@ struct btd_debug_desc {
         __attribute__((used, section("__debug"), aligned(8))) = { \
                 .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
         }; \
-        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
+        if (debug_enabled && \
+			__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
                 debug("%s:%s() " fmt, \
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
diff --git a/src/main.c b/src/main.c
index 3118a34..ba18523 100644
--- a/src/main.c
+++ b/src/main.c
@@ -288,6 +288,11 @@ static void sig_term(int sig)
 	g_main_loop_quit(event_loop);
 }
 
+static void sig_debug(int sig)
+{
+	__btd_toggle_debug();
+}
+
 static gchar *option_debug = NULL;
 static gboolean option_detach = TRUE;
 static gboolean option_udev = FALSE;
@@ -406,6 +411,9 @@ int main(int argc, char *argv[])
 	sigaction(SIGTERM, &sa, NULL);
 	sigaction(SIGINT,  &sa, NULL);
 
+	sa.sa_handler = sig_debug;
+	sigaction(SIGUSR2, &sa, NULL);
+
 	sa.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &sa, NULL);
 
-- 
1.7.1


^ permalink raw reply related

* Re: [PATCH 3/3] Fix regression with debug via SIGUSR2
From: Gustavo F. Padovan @ 2010-06-05  4:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1275712886-20127-3-git-send-email-gustavo@padovan.org>

* Gustavo F. Padovan <gustavo@padovan.org> [2010-06-05 01:41:26 -0300]:

> The new dynamic debug feature was not using the SIGUSR2 signal so this was
> causing bluetoothd to crash when one tries to toggle debug via SIGUSR2.
> This patch brings back such compatibility andadds debug_string and
> debug_enabled vars.
> ---
>  src/log.c  |   17 +++++++++++++++--
>  src/log.h  |    6 +++++-
>  src/main.c |    8 ++++++++
>  3 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/src/log.c b/src/log.c
> index cb02aad..1bc0a42 100644
> --- a/src/log.c
> +++ b/src/log.c
> @@ -71,6 +71,8 @@ extern struct btd_debug_desc __stop___debug[];
>  
>  static gchar **enabled = NULL;
>  
> +int debug_enabled = FALSE;
> +
>  static gboolean is_enabled(struct btd_debug_desc *desc)
>  {
>          int i;
> @@ -90,14 +92,25 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
>          return 0;
>  }
>  
> +void __btd_toggle_debug()
> +{
> +	debug_enabled = !debug_enabled;
> +}
> +
>  void __btd_log_init(const char *debug, int detach)
>  {
>  	int option = LOG_NDELAY | LOG_PID;
>  	struct btd_debug_desc *desc;
>  	const char *name = NULL, *file = NULL;
>  
> -	if (debug != NULL)
> -		enabled = g_strsplit_set(debug, ":, ", 0);
> +	if (debug != NULL) {
> +		debug_enabled = TRUE;
> +	} else {
> +		debug = g_strdup("*");
> +		debug_enabled = FALSE;
> +	}
> +
> +	enabled = g_strsplit_set(debug, ":, ", 0);
>  
>  	for (desc = __start___debug; desc < __stop___debug; desc++) {
>  		if (file != NULL || name != NULL) {
> diff --git a/src/log.h b/src/log.h
> index 33168c7..5f742e8 100644
> --- a/src/log.h
> +++ b/src/log.h
> @@ -23,12 +23,15 @@
>  
>  extern int debug_enabled;
>  
> +extern int debug_enabled;

3/3 It's wrong. I have screw up with git rebase -i :(

> +
>  void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
>  void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
>  void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
>  
>  void __btd_log_init(const char *debug, int detach);
>  void __btd_log_cleanup(void);
> +void __btd_toggle_debug();
>  
>  struct btd_debug_desc {
>          const char *name;
> @@ -51,7 +54,8 @@ struct btd_debug_desc {
>          __attribute__((used, section("__debug"), aligned(8))) = { \
>                  .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
>          }; \
> -        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
> +        if (debug_enabled && \
> +			__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
>                  debug("%s:%s() " fmt, \
>                                          __FILE__, __FUNCTION__ , ## arg); \
>  } while (0)
> diff --git a/src/main.c b/src/main.c
> index 3118a34..ba18523 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -288,6 +288,11 @@ static void sig_term(int sig)
>  	g_main_loop_quit(event_loop);
>  }
>  
> +static void sig_debug(int sig)
> +{
> +	__btd_toggle_debug();
> +}
> +
>  static gchar *option_debug = NULL;
>  static gboolean option_detach = TRUE;
>  static gboolean option_udev = FALSE;
> @@ -406,6 +411,9 @@ int main(int argc, char *argv[])
>  	sigaction(SIGTERM, &sa, NULL);
>  	sigaction(SIGINT,  &sa, NULL);
>  
> +	sa.sa_handler = sig_debug;
> +	sigaction(SIGUSR2, &sa, NULL);
> +
>  	sa.sa_handler = SIG_IGN;
>  	sigaction(SIGPIPE, &sa, NULL);
>  
> -- 
> 1.7.1
> 

-- 
Gustavo F. Padovan
http://padovan.org

^ permalink raw reply

* [PATCH 3/3] Fix regression with debug via SIGUSR2
From: Gustavo F. Padovan @ 2010-06-05  4:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275712886-20127-2-git-send-email-gustavo@padovan.org>

The new dynamic debug feature was not using the SIGUSR2 signal so this was
causing bluetoothd to crash when one tries to toggle debug via SIGUSR2.
This patch brings back such compatibility andadds debug_string and
debug_enabled vars.
---
 src/log.c  |   17 +++++++++++++++--
 src/log.h  |    6 +++++-
 src/main.c |    8 ++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/log.c b/src/log.c
index cb02aad..1bc0a42 100644
--- a/src/log.c
+++ b/src/log.c
@@ -71,6 +71,8 @@ extern struct btd_debug_desc __stop___debug[];
 
 static gchar **enabled = NULL;
 
+int debug_enabled = FALSE;
+
 static gboolean is_enabled(struct btd_debug_desc *desc)
 {
         int i;
@@ -90,14 +92,25 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
         return 0;
 }
 
+void __btd_toggle_debug()
+{
+	debug_enabled = !debug_enabled;
+}
+
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
 	struct btd_debug_desc *desc;
 	const char *name = NULL, *file = NULL;
 
-	if (debug != NULL)
-		enabled = g_strsplit_set(debug, ":, ", 0);
+	if (debug != NULL) {
+		debug_enabled = TRUE;
+	} else {
+		debug = g_strdup("*");
+		debug_enabled = FALSE;
+	}
+
+	enabled = g_strsplit_set(debug, ":, ", 0);
 
 	for (desc = __start___debug; desc < __stop___debug; desc++) {
 		if (file != NULL || name != NULL) {
diff --git a/src/log.h b/src/log.h
index 33168c7..5f742e8 100644
--- a/src/log.h
+++ b/src/log.h
@@ -23,12 +23,15 @@
 
 extern int debug_enabled;
 
+extern int debug_enabled;
+
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
+void __btd_toggle_debug();
 
 struct btd_debug_desc {
         const char *name;
@@ -51,7 +54,8 @@ struct btd_debug_desc {
         __attribute__((used, section("__debug"), aligned(8))) = { \
                 .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
         }; \
-        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
+        if (debug_enabled && \
+			__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
                 debug("%s:%s() " fmt, \
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
diff --git a/src/main.c b/src/main.c
index 3118a34..ba18523 100644
--- a/src/main.c
+++ b/src/main.c
@@ -288,6 +288,11 @@ static void sig_term(int sig)
 	g_main_loop_quit(event_loop);
 }
 
+static void sig_debug(int sig)
+{
+	__btd_toggle_debug();
+}
+
 static gchar *option_debug = NULL;
 static gboolean option_detach = TRUE;
 static gboolean option_udev = FALSE;
@@ -406,6 +411,9 @@ int main(int argc, char *argv[])
 	sigaction(SIGTERM, &sa, NULL);
 	sigaction(SIGINT,  &sa, NULL);
 
+	sa.sa_handler = sig_debug;
+	sigaction(SIGUSR2, &sa, NULL);
+
 	sa.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &sa, NULL);
 
-- 
1.7.1


^ permalink raw reply related

* [PATCH 2/3] Remove ifndef barrier from log.h and btio.h
From: Gustavo F. Padovan @ 2010-06-05  4:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275712886-20127-1-git-send-email-gustavo@padovan.org>

---
 src/btio.h |    3 ---
 src/log.h  |    4 +---
 2 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/src/btio.h b/src/btio.h
index 00d743e..fa6ff69 100644
--- a/src/btio.h
+++ b/src/btio.h
@@ -21,8 +21,6 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
-#ifndef BT_IO_H
-#define BT_IO_H
 
 #include <glib.h>
 
@@ -93,4 +91,3 @@ GIOChannel *bt_io_listen(BtIOType type, BtIOConnect connect,
 				GDestroyNotify destroy, GError **err,
 				BtIOOption opt1, ...);
 
-#endif
diff --git a/src/log.h b/src/log.h
index 9af51e7..33168c7 100644
--- a/src/log.h
+++ b/src/log.h
@@ -21,8 +21,7 @@
  *
  */
 
-#ifndef __LOGGING_H
-#define __LOGGING_H
+extern int debug_enabled;
 
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
@@ -57,4 +56,3 @@ struct btd_debug_desc {
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
 
-#endif /* __LOGGING_H */
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/3] log: Remove vinfo function
From: Gustavo F. Padovan @ 2010-06-05  4:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

It was used only once.
---
 src/log.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/src/log.c b/src/log.c
index 29e2d7d..cb02aad 100644
--- a/src/log.c
+++ b/src/log.c
@@ -33,18 +33,13 @@
 
 #include "log.h"
 
-static inline void vinfo(const char *format, va_list ap)
-{
-	vsyslog(LOG_INFO, format, ap);
-}
-
 void info(const char *format, ...)
 {
 	va_list ap;
 
 	va_start(ap, format);
 
-	vinfo(format, ap);
+	vsyslog(LOG_INFO, format, ap);
 
 	va_end(ap);
 }
-- 
1.7.1


^ permalink raw reply related

* [PATCH 4/4] Remove ifndef barrier from log.h and btio.h
From: Gustavo F. Padovan @ 2010-06-05  2:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275704622-5917-3-git-send-email-gustavo@padovan.org>

---
 src/btio.h |    3 ---
 src/log.h  |    4 ----
 2 files changed, 0 insertions(+), 7 deletions(-)

diff --git a/src/btio.h b/src/btio.h
index 00d743e..fa6ff69 100644
--- a/src/btio.h
+++ b/src/btio.h
@@ -21,8 +21,6 @@
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
-#ifndef BT_IO_H
-#define BT_IO_H
 
 #include <glib.h>
 
@@ -93,4 +91,3 @@ GIOChannel *bt_io_listen(BtIOType type, BtIOConnect connect,
 				GDestroyNotify destroy, GError **err,
 				BtIOOption opt1, ...);
 
-#endif
diff --git a/src/log.h b/src/log.h
index f37929c..94b045c 100644
--- a/src/log.h
+++ b/src/log.h
@@ -21,9 +21,6 @@
  *
  */
 
-#ifndef __LOGGING_H
-#define __LOGGING_H
-
 extern int debug_enabled;
 
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
@@ -61,4 +58,3 @@ struct btd_debug_desc {
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
 
-#endif /* __LOGGING_H */
-- 
1.7.1


^ permalink raw reply related

* [PATCH 3/4] log: Remove vinfo function
From: Gustavo F. Padovan @ 2010-06-05  2:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275704622-5917-2-git-send-email-gustavo@padovan.org>

It was used only once.
---
 src/log.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/src/log.c b/src/log.c
index d667ed0..aefd50f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -33,18 +33,13 @@
 
 #include "log.h"
 
-static inline void vinfo(const char *format, va_list ap)
-{
-	vsyslog(LOG_INFO, format, ap);
-}
-
 void info(const char *format, ...)
 {
 	va_list ap;
 
 	va_start(ap, format);
 
-	vinfo(format, ap);
+	vsyslog(LOG_INFO, format, ap);
 
 	va_end(ap);
 }
-- 
1.7.1


^ permalink raw reply related

* [PATCH 2/4] Add debug_string and debug_enabled vars
From: Gustavo F. Padovan @ 2010-06-05  2:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275704622-5917-1-git-send-email-gustavo@padovan.org>

Both will be very useful when we add Debug property to DBus.
---
 src/log.c |   20 +++++++++++++++++---
 src/log.h |    5 ++++-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/log.c b/src/log.c
index 1c0f0b9..d667ed0 100644
--- a/src/log.c
+++ b/src/log.c
@@ -75,6 +75,9 @@ extern struct btd_debug_desc __start___debug[];
 extern struct btd_debug_desc __stop___debug[];
 
 static gchar **enabled = NULL;
+static const char *debug_string = NULL;
+
+int debug_enabled = FALSE;
 
 static gboolean is_enabled(struct btd_debug_desc *desc)
 {
@@ -103,6 +106,8 @@ static void debug_on(const char *debug)
 	if (debug != NULL)
 		enabled = g_strsplit_set(debug, ":, ", 0);
 
+	debug_enabled = TRUE;
+
 	for (desc = __start___debug; desc < __stop___debug; desc++) {
 		if (file != NULL || name != NULL) {
 			if (g_strcmp0(desc->file, file) == 0) {
@@ -121,6 +126,8 @@ static void debug_off()
 {
 	struct btd_debug_desc *desc;
 
+	debug_enabled = FALSE;
+
 	for (desc = __start___debug; desc < __stop___debug; desc++) {
 		if (is_enabled(desc))
 			desc->flags &= ~BTD_DEBUG_FLAG_PRINT;
@@ -132,16 +139,23 @@ static void debug_off()
 
 void __btd_toggle_debug()
 {
-	if (enabled == NULL)
-		debug_on("*");
-	else
+	if (enabled == NULL) {
+		if (debug_string == NULL)
+			debug_on("*");
+		else
+			debug_on(debug_string);
+	}
+	else {
 		debug_off();
+	}
 }
 
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
 
+	debug_string = debug;
+
 	debug_on(debug);
 
 	if (!detach)
diff --git a/src/log.h b/src/log.h
index a1530da..f37929c 100644
--- a/src/log.h
+++ b/src/log.h
@@ -24,6 +24,8 @@
 #ifndef __LOGGING_H
 #define __LOGGING_H
 
+extern int debug_enabled;
+
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
@@ -53,7 +55,8 @@ struct btd_debug_desc {
         __attribute__((used, section("__debug"), aligned(8))) = { \
                 .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
         }; \
-        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
+        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT \
+			&& debug_enabled) \
                 debug("%s:%s() " fmt, \
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/4] Fix regression with debug via SIGUSR2
From: Gustavo F. Padovan @ 2010-06-05  2:23 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

The new dynamic debug feature was not using the SIGUSR2 signal so this was
causing bluetoothd to crash when one tries to toggle debug via SIGUSR2.
This patch brings back such compatibility.
---
 src/log.c  |   31 +++++++++++++++++++++++++++++--
 src/log.h  |    1 +
 src/main.c |    8 ++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/log.c b/src/log.c
index 29e2d7d..1c0f0b9 100644
--- a/src/log.c
+++ b/src/log.c
@@ -95,9 +95,8 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
         return 0;
 }
 
-void __btd_log_init(const char *debug, int detach)
+static void debug_on(const char *debug)
 {
-	int option = LOG_NDELAY | LOG_PID;
 	struct btd_debug_desc *desc;
 	const char *name = NULL, *file = NULL;
 
@@ -116,6 +115,34 @@ void __btd_log_init(const char *debug, int detach)
 		if (is_enabled(desc))
 			desc->flags |= BTD_DEBUG_FLAG_PRINT;
 	}
+}
+
+static void debug_off()
+{
+	struct btd_debug_desc *desc;
+
+	for (desc = __start___debug; desc < __stop___debug; desc++) {
+		if (is_enabled(desc))
+			desc->flags &= ~BTD_DEBUG_FLAG_PRINT;
+	}
+
+	g_strfreev(enabled);
+	enabled = NULL;
+}
+
+void __btd_toggle_debug()
+{
+	if (enabled == NULL)
+		debug_on("*");
+	else
+		debug_off();
+}
+
+void __btd_log_init(const char *debug, int detach)
+{
+	int option = LOG_NDELAY | LOG_PID;
+
+	debug_on(debug);
 
 	if (!detach)
 		option |= LOG_PERROR;
diff --git a/src/log.h b/src/log.h
index 9af51e7..a1530da 100644
--- a/src/log.h
+++ b/src/log.h
@@ -30,6 +30,7 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
+void __btd_toggle_debug();
 
 struct btd_debug_desc {
         const char *name;
diff --git a/src/main.c b/src/main.c
index 3118a34..ba18523 100644
--- a/src/main.c
+++ b/src/main.c
@@ -288,6 +288,11 @@ static void sig_term(int sig)
 	g_main_loop_quit(event_loop);
 }
 
+static void sig_debug(int sig)
+{
+	__btd_toggle_debug();
+}
+
 static gchar *option_debug = NULL;
 static gboolean option_detach = TRUE;
 static gboolean option_udev = FALSE;
@@ -406,6 +411,9 @@ int main(int argc, char *argv[])
 	sigaction(SIGTERM, &sa, NULL);
 	sigaction(SIGINT,  &sa, NULL);
 
+	sa.sa_handler = sig_debug;
+	sigaction(SIGUSR2, &sa, NULL);
+
 	sa.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &sa, NULL);
 
-- 
1.7.1


^ permalink raw reply related

* Re: [PATCH 1/4] Fix regression with debug via SIGUSR2
From: Johan Hedberg @ 2010-06-04 11:34 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth
In-Reply-To: <1275646613-32639-1-git-send-email-gustavo@padovan.org>

Hi Gustavo,

On Fri, Jun 04, 2010, Gustavo F. Padovan wrote:
> +static void turn_debug_on(const char *debug)

Please call this simply debug_on()

> +static void turn_debug_off()

same here (debug_off)

> +void __btd_toogle_debug()

It's called toggle and not toogle :)

> +	if (enabled == NULL)
> +		turn_debug_on("*");

I suppose this should restore the previous value and not hard-code "*"?

Johan

^ permalink raw reply

* Re: [PATCH 4/4] Adjust define name to the name of the file
From: Luiz Augusto von Dentz @ 2010-06-04 10:59 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth
In-Reply-To: <1275646613-32639-4-git-send-email-gustavo@padovan.org>

Hi Gustavo,

On Fri, Jun 4, 2010 at 1:16 PM, Gustavo F. Padovan <gustavo@padovan.org> wrote:
> ---
>  src/log.h |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/log.h b/src/log.h
> index 235430e..7a5942c 100644
> --- a/src/log.h
> +++ b/src/log.h
> @@ -21,8 +21,8 @@
>  *
>  */
>
> -#ifndef __LOGGING_H
> -#define __LOGGING_H
> +#ifndef __LOG_H
> +#define __LOG_H
>
>  extern int debug_enabled;
>
> @@ -61,4 +61,4 @@ struct btd_debug_desc {
>                                         __FILE__, __FUNCTION__ , ## arg); \
>  } while (0)
>
> -#endif /* __LOGGING_H */
> +#endif /* __LOG_H */

I remember Marcel being against this since it hides real dependency circle.


-- 
Luiz Augusto von Dentz
Computer Engineer

^ permalink raw reply

* [PATCH 4/4] Adjust define name to the name of the file
From: Gustavo F. Padovan @ 2010-06-04 10:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275646613-32639-3-git-send-email-gustavo@padovan.org>

---
 src/log.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/log.h b/src/log.h
index 235430e..7a5942c 100644
--- a/src/log.h
+++ b/src/log.h
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef __LOGGING_H
-#define __LOGGING_H
+#ifndef __LOG_H
+#define __LOG_H
 
 extern int debug_enabled;
 
@@ -61,4 +61,4 @@ struct btd_debug_desc {
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
 
-#endif /* __LOGGING_H */
+#endif /* __LOG_H */
-- 
1.7.1


^ permalink raw reply related

* [PATCH 3/4] log: Remove vinfo function
From: Gustavo F. Padovan @ 2010-06-04 10:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275646613-32639-2-git-send-email-gustavo@padovan.org>

It was used only once.
---
 src/log.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/src/log.c b/src/log.c
index 9248c4d..f113fa6 100644
--- a/src/log.c
+++ b/src/log.c
@@ -33,18 +33,13 @@
 
 #include "log.h"
 
-static inline void vinfo(const char *format, va_list ap)
-{
-	vsyslog(LOG_INFO, format, ap);
-}
-
 void info(const char *format, ...)
 {
 	va_list ap;
 
 	va_start(ap, format);
 
-	vinfo(format, ap);
+	vsyslog(LOG_INFO, format, ap);
 
 	va_end(ap);
 }
-- 
1.7.1


^ permalink raw reply related

* [PATCH 2/4] Add debug_string and debug_enabled vars
From: Gustavo F. Padovan @ 2010-06-04 10:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo
In-Reply-To: <1275646613-32639-1-git-send-email-gustavo@padovan.org>

Both will be very useful when we add Debug property to DBus.
---
 src/log.c |   10 ++++++++++
 src/log.h |    5 ++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/src/log.c b/src/log.c
index 4ef178a..9248c4d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -75,6 +75,9 @@ extern struct btd_debug_desc __start___debug[];
 extern struct btd_debug_desc __stop___debug[];
 
 static gchar **enabled = NULL;
+static const char *debug_string = NULL;
+
+int debug_enabled = FALSE;
 
 static gboolean is_enabled(struct btd_debug_desc *desc)
 {
@@ -100,9 +103,12 @@ static void turn_debug_on(const char *debug)
 	struct btd_debug_desc *desc;
 	const char *name = NULL, *file = NULL;
 
+
 	if (debug != NULL)
 		enabled = g_strsplit_set(debug, ":, ", 0);
 
+	debug_enabled = TRUE;
+
 	for (desc = __start___debug; desc < __stop___debug; desc++) {
 		if (file != NULL || name != NULL) {
 			if (g_strcmp0(desc->file, file) == 0) {
@@ -121,6 +127,8 @@ static void turn_debug_off()
 {
 	struct btd_debug_desc *desc;
 
+	debug_enabled = FALSE;
+
 	for (desc = __start___debug; desc < __stop___debug; desc++) {
 		if (is_enabled(desc))
 			desc->flags &= ~BTD_DEBUG_FLAG_PRINT;
@@ -142,6 +150,8 @@ void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
 
+	debug_string = debug;
+
 	turn_debug_on(debug);
 
 	if (!detach)
diff --git a/src/log.h b/src/log.h
index 8c1b937..235430e 100644
--- a/src/log.h
+++ b/src/log.h
@@ -24,6 +24,8 @@
 #ifndef __LOGGING_H
 #define __LOGGING_H
 
+extern int debug_enabled;
+
 void info(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void error(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
@@ -53,7 +55,8 @@ struct btd_debug_desc {
         __attribute__((used, section("__debug"), aligned(8))) = { \
                 .file = __FILE__, .flags = BTD_DEBUG_FLAG_DEFAULT, \
         }; \
-        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT) \
+        if (__btd_debug_desc.flags & BTD_DEBUG_FLAG_PRINT \
+			&& debug_enabled) \
                 debug("%s:%s() " fmt, \
                                         __FILE__, __FUNCTION__ , ## arg); \
 } while (0)
-- 
1.7.1


^ permalink raw reply related

* [PATCH 1/4] Fix regression with debug via SIGUSR2
From: Gustavo F. Padovan @ 2010-06-04 10:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

The new dynamic debug feature was not using the SIGUSR2 signal so this was
causing bluetoothd to crash when one tries to toogle debug via SIGUSR2.
This patch brings back such compatibility.
---
 src/log.c  |   31 +++++++++++++++++++++++++++++--
 src/log.h  |    1 +
 src/main.c |    8 ++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/log.c b/src/log.c
index 29e2d7d..4ef178a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -95,9 +95,8 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
         return 0;
 }
 
-void __btd_log_init(const char *debug, int detach)
+static void turn_debug_on(const char *debug)
 {
-	int option = LOG_NDELAY | LOG_PID;
 	struct btd_debug_desc *desc;
 	const char *name = NULL, *file = NULL;
 
@@ -116,6 +115,34 @@ void __btd_log_init(const char *debug, int detach)
 		if (is_enabled(desc))
 			desc->flags |= BTD_DEBUG_FLAG_PRINT;
 	}
+}
+
+static void turn_debug_off()
+{
+	struct btd_debug_desc *desc;
+
+	for (desc = __start___debug; desc < __stop___debug; desc++) {
+		if (is_enabled(desc))
+			desc->flags &= ~BTD_DEBUG_FLAG_PRINT;
+	}
+
+	g_strfreev(enabled);
+	enabled = NULL;
+}
+
+void __btd_toogle_debug()
+{
+	if (enabled == NULL)
+		turn_debug_on("*");
+	else
+		turn_debug_off();
+}
+
+void __btd_log_init(const char *debug, int detach)
+{
+	int option = LOG_NDELAY | LOG_PID;
+
+	turn_debug_on(debug);
 
 	if (!detach)
 		option |= LOG_PERROR;
diff --git a/src/log.h b/src/log.h
index 9af51e7..8c1b937 100644
--- a/src/log.h
+++ b/src/log.h
@@ -30,6 +30,7 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
+void __btd_toogle_debug();
 
 struct btd_debug_desc {
         const char *name;
diff --git a/src/main.c b/src/main.c
index 3118a34..d6559b5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -288,6 +288,11 @@ static void sig_term(int sig)
 	g_main_loop_quit(event_loop);
 }
 
+static void sig_debug(int sig)
+{
+	__btd_toogle_debug();
+}
+
 static gchar *option_debug = NULL;
 static gboolean option_detach = TRUE;
 static gboolean option_udev = FALSE;
@@ -406,6 +411,9 @@ int main(int argc, char *argv[])
 	sigaction(SIGTERM, &sa, NULL);
 	sigaction(SIGINT,  &sa, NULL);
 
+	sa.sa_handler = sig_debug;
+	sigaction(SIGUSR2, &sa, NULL);
+
 	sa.sa_handler = SIG_IGN;
 	sigaction(SIGPIPE, &sa, NULL);
 
-- 
1.7.1


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox