From: Eric Bollengier Date: Fri, 17 Dec 2010 14:26:19 +0000 (+0100) Subject: Track unbalanced start/end plugin stream X-Git-Tag: Release-7.0.0~1267 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=20787d8026640d85591e521b5e373ead1c3af0ce;p=bacula%2Fbacula Track unbalanced start/end plugin stream --- diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index defe88bf89..b54adc9810 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -176,11 +176,18 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) case bEventEndVerifyJob: call_if_canceled = true; break; + case bEventStartRestoreJob: + if (jcr->plugin) { + jcr->plugin->restoreFileStarted = false; + jcr->plugin->createFileCalled = false; + } + break; case bEventEndRestoreJob: call_if_canceled = true; if (jcr->plugin && jcr->plugin->restoreFileStarted) { plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx); jcr->plugin->restoreFileStarted = false; + jcr->plugin->createFileCalled = false; } break; default: @@ -527,6 +534,7 @@ bool plugin_name_stream(JCR *jcr, char *name) if (jcr->plugin && jcr->plugin->restoreFileStarted) { plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx); jcr->plugin->restoreFileStarted = false; + jcr->plugin->createFileCalled = false; } jcr->plugin_ctx = NULL; jcr->plugin = NULL; @@ -564,11 +572,12 @@ bool plugin_name_stream(JCR *jcr, char *name) &event, cmd) != bRC_OK) { goto bail_out; } - /* ***FIXME**** check error code */ - if (plugin->restoreFileStarted) { - plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx); + if (plugin->restoreFileStarted) + { + Jmsg0(jcr, M_FATAL, 0, "Unbalanced call to startRestoreFile\n"); + goto bail_out; } - plug_func(plugin)->startRestoreFile((bpContext *)jcr->plugin_ctx, cmd); + plug_func(plugin)->startRestoreFile(jcr->plugin_ctx, cmd); plugin->restoreFileStarted = true; goto bail_out; } @@ -622,6 +631,11 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) if (rp.attrEx) { Dmsg1(dbglvl, "attrEx=\"%s\"\n", rp.attrEx); } + if (!plugin->restoreFileStarted || plugin->createFileCalled) + { + Jmsg0(jcr, M_FATAL, 0, "Unbalanced call to createFile\n"); + return CF_ERROR; + } rc = plug_func(plugin)->createFile(plugin_ctx, &rp); if (rc != bRC_OK) { Qmsg2(jcr, M_ERROR, 0, _("Plugin createFile call failed. Stat=%d file=%s\n"), diff --git a/bacula/src/lib/plugins.h b/bacula/src/lib/plugins.h index c3d015357b..2d45f916bf 100644 --- a/bacula/src/lib/plugins.h +++ b/bacula/src/lib/plugins.h @@ -78,6 +78,7 @@ public: void *pHandle; bool disabled; bool restoreFileStarted; + bool createFileCalled; }; /* Functions */