Diff between 6b5b53f5d8a884fdd80a5c276507ec7cd3c1401b and 8cd91d18de8ada1cc1284a6e9dcad6f78b018b97

Changed Files

File Additions Deletions Status
src/log.c +15 -4 modified
src/log.h +3 -0 modified
src/plugin.c +2 -0 modified
src/plugin.h +8 -1 modified

Full Patch

diff --git a/src/log.c b/src/log.c
index 2c492e9..4a50117 100644
--- a/src/log.c
+++ b/src/log.c
@@ -86,6 +86,20 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
 	return 0;
 }
 
+void __btd_enable_debug(struct btd_debug_desc *start,
+					struct btd_debug_desc *stop)
+{
+	struct btd_debug_desc *desc;
+
+	if (start == NULL || stop == NULL)
+		return;
+
+	for (desc = start; desc < stop; desc++) {
+		if (is_enabled(desc))
+			desc->flags |= BTD_DEBUG_FLAG_PRINT;
+	}
+}
+
 void __btd_toggle_debug(void)
 {
 	struct btd_debug_desc *desc;
@@ -97,14 +111,11 @@ void __btd_toggle_debug(void)
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
-	struct btd_debug_desc *desc;
 
 	if (debug != NULL)
 		enabled = g_strsplit_set(debug, ":, ", 0);
 
-	for (desc = __start___debug; desc < __stop___debug; desc++)
-		if (is_enabled(desc))
-			desc->flags |= BTD_DEBUG_FLAG_PRINT;
+	__btd_enable_debug(__start___debug, __stop___debug);
 
 	if (!detach)
 		option |= LOG_PERROR;
diff --git a/src/log.h b/src/log.h
index 78bbdd8..b43b2b7 100644
--- a/src/log.h
+++ b/src/log.h
@@ -37,6 +37,9 @@ struct btd_debug_desc {
 	unsigned int flags;
 } __attribute__((aligned(8)));
 
+void __btd_enable_debug(struct btd_debug_desc *start,
+					struct btd_debug_desc *stop);
+
 /**
  * DBG:
  * @fmt: format string
diff --git a/src/plugin.c b/src/plugin.c
index 3506553..2a86e68 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -77,6 +77,8 @@ static gboolean add_plugin(void *handle, struct bluetooth_plugin_desc *desc)
 	plugin->active = FALSE;
 	plugin->desc = desc;
 
+	__btd_enable_debug(desc->debug_start, desc->debug_stop);
+
 	plugins = g_slist_insert_sorted(plugins, plugin, compare_priority);
 
 	return TRUE;
diff --git a/src/plugin.h b/src/plugin.h
index 30bd415..4fbdd1d 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -30,6 +30,8 @@ struct bluetooth_plugin_desc {
 	int priority;
 	int (*init) (void);
 	void (*exit) (void);
+	void *debug_start;
+	void *debug_stop;
 };
 
 #ifdef BLUETOOTH_PLUGIN_BUILTIN
@@ -39,9 +41,14 @@ struct bluetooth_plugin_desc {
 		};
 #else
 #define BLUETOOTH_PLUGIN_DEFINE(name, version, priority, init, exit) \
+		extern struct btd_debug_desc __start___debug[] \
+				__attribute__ ((visibility("hidden"))); \
+		extern struct btd_debug_desc __stop___debug[] \
+				__attribute__ ((visibility("hidden"))); \
 		extern struct bluetooth_plugin_desc bluetooth_plugin_desc \
 				__attribute__ ((visibility("default"))); \
 		struct bluetooth_plugin_desc bluetooth_plugin_desc = { \
-			#name, version, priority, init, exit \
+			#name, version, priority, init, exit, \
+			__start___debug, __stop___debug \
 		};
 #endif