From 1b238baa74d36f144581deee5f3a1834d1d445bb Mon Sep 17 00:00:00 2001 From: Manuel Bachmann Date: Tue, 22 Dec 2015 09:25:00 +0100 Subject: [PATCH] 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 --- plugins/samples/HelloWorld.c | 2 +- src/rest-api.c | 15 +++++++++++---- 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); } -- 2.16.6