From 15d417ae900561216cc8cdc25f0a2c46183ea33c Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 24 Jul 2010 14:53:52 +0200 Subject: [PATCH] Call plugin bEventEndxxxJob even if Job canceled --- bacula/src/filed/fd_plugins.c | 34 +++++++++++++++++++++++++++++----- bacula/src/lib/plugins.h | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index b045462ac4..d07341cd81 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -151,15 +151,19 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) bEvent event; Plugin *plugin; int i = 0; - char *name=NULL; - int len; + char *name = NULL; + int len = 0; + bool call_if_canceled = false; bRC rc; - if (!plugin_list || !jcr || !jcr->plugin_ctx_list || jcr->is_job_canceled()) { + if (!plugin_list || !jcr || !jcr->plugin_ctx_list) { return; /* Return if no plugins loaded */ } - /* Some events are sent to only a particular plugin */ + /* + * Some events are sent to only a particular plugin or must be + * called even if the job is canceled + */ switch(eventType) { case bEventPluginCommand: name = (char *)value; @@ -167,10 +171,25 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) return; } break; + case bEventEndBackupJob: + case bEventEndVerifyJob: + call_if_canceled = true; + 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; + } + break; default: break; } + if (!call_if_canceled && jcr->is_job_canceled()) { + return; + } + bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list; event.eventType = eventType; @@ -485,8 +504,9 @@ bool plugin_name_stream(JCR *jcr, char *name) * End of plugin data, notify plugin, then clear flags */ Dmsg2(dbglvl, "End plugin data plugin=%p ctx=%p\n", jcr->plugin, jcr->plugin_ctx); - if (jcr->plugin) { + if (jcr->plugin && jcr->plugin->restoreFileStarted) { plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx); + jcr->plugin->restoreFileStarted = false; } jcr->plugin_ctx = NULL; jcr->plugin = NULL; @@ -525,7 +545,11 @@ bool plugin_name_stream(JCR *jcr, char *name) goto bail_out; } /* ***FIXME**** check error code */ + if (plugin->restoreFileStarted) { + plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx); + } plug_func(plugin)->startRestoreFile((bpContext *)jcr->plugin_ctx, cmd); + plugin->restoreFileStarted = true; goto bail_out; } Jmsg1(jcr, M_WARNING, 0, _("Plugin=%s not found.\n"), cmd); diff --git a/bacula/src/lib/plugins.h b/bacula/src/lib/plugins.h index 89eb1e086d..5ab1603ba0 100644 --- a/bacula/src/lib/plugins.h +++ b/bacula/src/lib/plugins.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2009 Free Software Foundation Europe e.V. + Copyright (C) 2007-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -76,6 +76,7 @@ public: void *pfuncs; void *pHandle; bool disabled; + bool restoreFileStarted; }; /* Functions */ -- 2.39.5