Skip to contentSkip to conversation

plugin: handle ENOSYS as not-supported

PATCH In review David Herrmann 2 participants 3 messages Oct 2, 2013 – Oct 3, 2013 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 plugin: handle ENOSYS as not-supported

Allow plugins to return -ENOSYS during registration and handle it as "not-supported" error. It makes the error messages slightly more useful in case kernel-support is missing for a particular subsystem.

---
 src/plugin.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
src/plugin.c +9 -2
index 51c98bc..9c3225e 100644
@@ -119,6 +119,7 @@ gboolean plugin_init(const char *enable, const char *disable)
 	const char *file;
 	char **cli_disabled, **cli_enabled;
 	unsigned int i;
+	int err;
 
 	/* Make a call to BtIO API so its symbols got resolved before the
 	 * plugins are loaded. */
@@ -196,8 +197,14 @@ start:
 	for (list = plugins; list; list = list->next) {
 		struct bluetooth_plugin *plugin = list->data;
 
-		if (plugin->desc->init() < 0) {
-			error("Failed to init %s plugin", plugin->desc->name);
+		err = plugin->desc->init();
+		if (err < 0) {
+			if (err == -ENOSYS)
+				warn("System does not support %s plugin",
+							plugin->desc->name);
+			else
+				error("Failed to init %s plugin",
+							plugin->desc->name);
 			continue;
 		}
 
Signature · 1 line
1.8.4
#1 lore raw

PATCH v2 2/2 bnep: improve error-msg if bnep.ko is not loaded

bnep.ko, besides others, can be disabled in custom kernels if network-support is not required. To avoid strange error messages, handle EPROTONOSUPPORT as a special case and emit a warning that kernel support is missing.

---
 profiles/network/common.c  |  7 ++++++-
 profiles/network/manager.c | 16 +++++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)
profiles/network/common.c +6 -1
index e069892..0b291bd 100644
@@ -110,8 +110,13 @@ int bnep_init(void)
 
 	if (ctl < 0) {
 		int err = -errno;
-		error("Failed to open control socket: %s (%d)",
+
+		if (err == -EPROTONOSUPPORT)
+			warn("kernel lacks bnep-protocol support");
+		else
+			error("Failed to open control socket: %s (%d)",
 						strerror(-err), -err);
+
 		return err;
 	}
 
profiles/network/manager.c +13 -3
index 03b1b3d..6617687 100644
@@ -25,6 +25,7 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
 #include <stdbool.h>
 
 #include <bluetooth/bluetooth.h>
@@ -169,11 +170,20 @@ static struct btd_profile nap_profile = {
 
 static int network_init(void)
 {
+	int err;
+
 	read_config(CONFIGDIR "/network.conf");
 
-	if (bnep_init()) {
-		error("Can't init bnep module");
-		return -1;
+	err = bnep_init();
+	if (err) {
+		if (err == -EPROTONOSUPPORT) {
+			info("bnep module not available, disabling plugin");
+			err = -ENOSYS;
+		} else {
+			error("Can't init bnep module");
+		}
+
+		return err;
 	}
 
 	/*
Signature · 1 line
1.8.4
#2 lore raw
In reply to David Herrmann

Hi David,

Quoted 6 lines · David Herrmann

Allow plugins to return -ENOSYS during registration and handle it as "not-supported" error. It makes the error messages slightly more useful in case kernel-support is missing for a particular subsystem.

---
 src/plugin.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Both patches have been applied after a couple of minor tweaks: remove one of the three logs in the bnep failure case (we don't need that many) and restrict scope of the err variable in plugin.c.

Johan