aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Bachmann <manuel.bachmann@iot.bzh>2015-12-22 09:25:00 +0100
committerManuel Bachmann <manuel.bachmann@iot.bzh>2015-12-22 09:25:00 +0100
commit1b238baa74d36f144581deee5f3a1834d1d445bb (patch)
tree0f20ce211ebfda983ed5ef14d62b0beeadac34be
parentb11e099d4c4092b9503cd1434299d644118d89d9 (diff)
Fix "no plugins" detection, rename HelloWorld API
afb-daemon now gracefully exits if no plugins are present. HelloWorld's API has been renamed to "hello". Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
-rw-r--r--plugins/samples/HelloWorld.c2
-rw-r--r--src/rest-api.c15
2 files changed, 12 insertions, 5 deletions
diff --git a/plugins/samples/HelloWorld.c b/plugins/samples/HelloWorld.c
index 870225b1..2f6dc4d1 100644
--- a/plugins/samples/HelloWorld.c
+++ b/plugins/samples/HelloWorld.c
@@ -88,7 +88,7 @@ PUBLIC AFB_plugin *pluginRegister () {
AFB_plugin *plugin = malloc (sizeof (AFB_plugin));
plugin->type = AFB_PLUGIN_JSON;
plugin->info = "Application Framework Binder Service";
- plugin->prefix= "dbus";
+ plugin->prefix= "hello";
plugin->apis = pluginApis;
return (plugin);
};
diff --git a/src/rest-api.c b/src/rest-api.c
index 0a31e20e..c1a20f13 100644
--- a/src/rest-api.c
+++ b/src/rest-api.c
@@ -573,9 +573,11 @@ void initPlugins(AFB_session *session) {
afbJsonType = json_object_new_string (AFB_MSG_JTYPE);
int i = 0;
+ plugins = (AFB_plugin **) malloc (sizeof(AFB_plugin));
+
if ((dir = opendir(session->config->plugins)) == NULL) {
- fprintf(stderr, "Could not open plugin directory=%s\n", session->config->plugins);
- return;
+ fprintf(stderr, "Could not open plugin directory [%s], exiting...\n", session->config->plugins);
+ exit (-1);
}
while ((pluginDir = readdir(dir)) != NULL) {
@@ -601,10 +603,15 @@ void initPlugins(AFB_session *session) {
plugins[i] = (**pluginRegisterFct)();
i++;
}
- plugins[i++] = NULL;
+ plugins[i] = NULL;
closedir (dir);
-
+
+ if (plugins[0] == NULL) {
+ fprintf(stderr, "No plugins found, afb-daemon is unlikely to work in this configuration, exiting...\n");
+ exit (-1);
+ }
+
// complete plugins and save them within current sessions
session->plugins = RegisterJsonPlugins(plugins);
}