bpContext *plugin_ctx;
bsdEvent event;
Plugin *plugin;
- int i = 0;
+ int i;
bRC rc = bRC_OK;
- if (!bplugin_list || !jcr || !jcr->plugin_ctx_list) {
+ if (!bplugin_list) {
+ Dmsg0(dbglvl, "No bplugin_list: generate_plugin_event ignored.\n");
+ return bRC_OK;
+ }
+ if (!jcr) {
+ Dmsg0(dbglvl, "No jcr: generate_plugin_event ignored.\n");
+ return bRC_OK;
+ }
+ if (!jcr->plugin_ctx_list) {
+ Dmsg0(dbglvl, "No plugin_ctx_list: generate_plugin_event ignored.\n");
return bRC_OK; /* Return if no plugins loaded */
}
if (jcr->is_job_canceled()) {
+ Dmsg0(dbglvl, "Cancel return from generate_plugin_event\n");
return bRC_Cancel;
}
Dmsg2(dbglvl, "sd-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
- foreach_alist(plugin, bplugin_list) {
- plugin_ctx = &plugin_ctx_list[i++];
+ foreach_alist_index(i, plugin, bplugin_list) {
+ plugin_ctx = &plugin_ctx_list[i];
if (is_plugin_disabled(plugin_ctx)) {
continue;
}
void load_sd_plugins(const char *plugin_dir)
{
Plugin *plugin;
+ int i;
Dmsg0(dbglvl, "Load sd plugins\n");
if (!plugin_dir) {
* Verify that the plugin is acceptable, and print information
* about it.
*/
- foreach_alist(plugin, bplugin_list) {
+ foreach_alist_index(i, plugin, bplugin_list) {
Jmsg(NULL, M_INFO, 0, _("Loaded plugin: %s\n"), plugin->file);
Dmsg1(dbglvl, "Loaded plugin: %s\n", plugin->file);
}
void new_plugins(JCR *jcr)
{
Plugin *plugin;
- int i = 0;
+ int i;
Dmsg0(dbglvl, "=== enter new_plugins ===\n");
if (!bplugin_list) {
if (jcr->is_job_canceled()) {
return;
}
+ /*
+ * If plugins already loaded, just return
+ */
+ if (jcr->plugin_ctx_list) {
+ return;
+ }
int num = bplugin_list->size();
bpContext *plugin_ctx_list = jcr->plugin_ctx_list;
Dmsg2(dbglvl, "Instantiate sd-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
- foreach_alist(plugin, bplugin_list) {
+ foreach_alist_index(i, plugin, bplugin_list) {
/* Start a new instance of each plugin */
bacula_ctx *b_ctx = (bacula_ctx *)malloc(sizeof(bacula_ctx));
memset(b_ctx, 0, sizeof(bacula_ctx));
b_ctx->jcr = jcr;
plugin_ctx_list[i].bContext = (void *)b_ctx;
plugin_ctx_list[i].pContext = NULL;
- if (sdplug_func(plugin)->newPlugin(&plugin_ctx_list[i++]) != bRC_OK) {
+ if (sdplug_func(plugin)->newPlugin(&plugin_ctx_list[i]) != bRC_OK) {
b_ctx->disabled = true;
}
}
void free_plugins(JCR *jcr)
{
Plugin *plugin;
- int i = 0;
+ int i;
if (!bplugin_list || !jcr->plugin_ctx_list) {
return;
bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list;
Dmsg2(dbglvl, "Free instance sd-plugin_ctx_list=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
- foreach_alist(plugin, bplugin_list) {
+ foreach_alist_index(i, plugin, bplugin_list) {
/* Free the plugin instance */
sdplug_func(plugin)->freePlugin(&plugin_ctx_list[i]);
- free(plugin_ctx_list[i++].bContext); /* free Bacula private context */
+ free(plugin_ctx_list[i].bContext); /* free Bacula private context */
}
free(plugin_ctx_list);
jcr->plugin_ctx_list = NULL;