rest-api: catch error from pluginRegisterFct()
authorYannick Gicquel <yannick.gicquel@iot.bzh>
Thu, 28 Jan 2016 15:31:50 +0000 (16:31 +0100)
committerYannick Gicquel <yannick.gicquel@iot.bzh>
Thu, 28 Jan 2016 15:31:50 +0000 (16:31 +0100)
in case NULL is returned, log an error and do not register
the plugin.

Signed-off-by: Yannick Gicquel <yannick.gicquel@iot.bzh>
src/rest-api.c

index e1c3756..eae1d63 100644 (file)
@@ -637,8 +637,10 @@ STATIC void scanDirectory(char *dirpath, int dirfd, AFB_plugin **plugins, int *c
 
             if (verbose) fprintf(stderr, "[%s] is a valid AFB plugin, loading pos[%d]\n", pluginDir.d_name, *count);
             plugins[*count] = pluginRegisterFct();
-            *count = *count +1;
-
+            if (!plugins[*count]) {
+                if (verbose) fprintf(stderr, "ERROR: plugin [%s] register function failed. continuing...\n", pluginDir.d_name);
+            } else
+                *count = *count +1;
         }
     }
     closedir (dir);