From: Eric Bollengier Date: Wed, 12 Nov 2008 16:13:10 +0000 (+0000) Subject: ebl Initialize plugin in director X-Git-Tag: Release-3.0.0~582 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=986b78386cc98c9b0a31ccce243e17dbd357c09e;p=bacula%2Fbacula ebl Initialize plugin in director Fix a couple of segfaults git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8043 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/dir_plugins.c b/bacula/src/dird/dir_plugins.c index b2487543da..4f0dc71503 100644 --- a/bacula/src/dird/dir_plugins.c +++ b/bacula/src/dird/dir_plugins.c @@ -74,7 +74,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) Plugin *plugin; int i = 0; - if (!plugin_list) { + if (!plugin_list || !jcr || !jcr->plugin_ctx_list) { return; } @@ -158,7 +158,7 @@ void free_plugins(JCR *jcr) Plugin *plugin; int i = 0; - if (!plugin_list) { + if (!plugin_list || !jcr->plugin_ctx_list) { return; } @@ -180,9 +180,14 @@ void free_plugins(JCR *jcr) */ static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value) { + bRC ret=bRC_OK; + + if (!ctx) { + return bRC_Error; + } JCR *jcr = (JCR *)(ctx->bContext); // Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var); - if (!value) { + if (!jcr || !value) { return bRC_Error; } // Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr); @@ -191,10 +196,15 @@ static bRC baculaGetValue(bpContext *ctx, brVariable var, void *value) *((int *)value) = jcr->JobId; Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId); break; + case bVarJobName: + *((char **)value) = jcr->Job; + Dmsg1(dbglvl, "Bacula: return bVarJobName=%s\n", jcr->Job); + break; default: + ret = bRC_Error; break; } - return bRC_OK; + return ret; } static bRC baculaSetValue(bpContext *ctx, bwVariable var, void *value) diff --git a/bacula/src/dird/dir_plugins.h b/bacula/src/dird/dir_plugins.h index 25673fb5cb..1bf94e2a77 100644 --- a/bacula/src/dird/dir_plugins.h +++ b/bacula/src/dird/dir_plugins.h @@ -105,7 +105,9 @@ typedef enum { typedef enum { bEventJobStart = 1, bEventJobEnd = 2, - bEventExit = 3 + bEventJobInit = 3, + bEventJobRun = 4, + bEventVolumePurged = 5 } bEventType; typedef struct s_bEvent { diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index c3ab10c3b1..b20c7af0dd 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -173,6 +173,8 @@ bool setup_job(JCR *jcr) jcr->JobId, jcr->Job, jcr->jr.JobType, jcr->jr.JobLevel); generate_daemon_event(jcr, "JobStart"); + new_plugins(jcr); /* instantiate plugins for this jcr */ + generate_plugin_event(jcr, bEventJobStart); if (job_canceled(jcr)) { goto bail_out; @@ -228,6 +230,7 @@ bool setup_job(JCR *jcr) } generate_job_event(jcr, "JobInit"); + generate_plugin_event(jcr, bEventJobInit); Dsm_check(1); return true; @@ -300,6 +303,7 @@ static void *job_thread(void *arg) Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db)); } generate_job_event(jcr, "JobRun"); + generate_plugin_event(jcr, bEventJobRun); switch (jcr->get_JobType()) { case JT_BACKUP: @@ -351,6 +355,7 @@ static void *job_thread(void *arg) } generate_daemon_event(jcr, "JobEnd"); + generate_plugin_event(jcr, bEventJobEnd); Dmsg1(50, "======== End Job stat=%c ==========\n", jcr->JobStatus); sm_check(__FILE__, __LINE__, true); return NULL; @@ -1018,6 +1023,8 @@ void dird_free_jcr(JCR *jcr) jcr->rstore_source = NULL; } + free_plugins(jcr); /* release instantiated plugins */ + /* Delete lists setup to hold storage pointers */ free_rwstorage(jcr); diff --git a/bacula/src/dird/ua_purge.c b/bacula/src/dird/ua_purge.c index 92b0f86efe..59400b5f60 100644 --- a/bacula/src/dird/ua_purge.c +++ b/bacula/src/dird/ua_purge.c @@ -505,6 +505,7 @@ bool mark_media_purged(UAContext *ua, MEDIA_DBR *mr) } pm_strcpy(jcr->VolumeName, mr->VolumeName); generate_job_event(jcr, "VolumePurged"); + generate_plugin_event(jcr, bEventVolumePurged); /* * If the RecyclePool is defined, move the volume there */ diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index a7a9fe88f7..c21e275c1a 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -122,7 +122,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value) Plugin *plugin; int i = 0; - if (!plugin_list || !jcr->plugin_ctx_list) { + if (!plugin_list || !jcr || !jcr->plugin_ctx_list) { return; /* Return if no plugins loaded */ } diff --git a/bacula/src/plugins/fd/example-plugin-fd.c b/bacula/src/plugins/fd/example-plugin-fd.c index 52f1d83ecb..4fc93ae1a6 100644 --- a/bacula/src/plugins/fd/example-plugin-fd.c +++ b/bacula/src/plugins/fd/example-plugin-fd.c @@ -124,7 +124,7 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) switch (event->eventType) { case bEventJobStart: - printf("plugin: JobStart=%s\n", (char *)value); + printf("plugin: JobStart=%s\n", NPRT((char *)value)); break; case bEventJobEnd: printf("plugin: JobEnd\n"); @@ -136,10 +136,10 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) printf("plugin: BackupEnd\n"); break; case bEventLevel: - printf("plugin: JobLevel=%c %d\n", *(int*)value, *(int*)value); + printf("plugin: JobLevel=%c %d\n", (int64_t)value, (int64_t)value); break; case bEventSince: - printf("plugin: since=%d\n", *(int*)value); + printf("plugin: since=%d\n", (int64_t)value); break; case bEventStartRestoreJob: printf("plugin: StartRestoreJob\n"); @@ -150,11 +150,11 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) /* Plugin command e.g. plugin = ::command */ case bEventRestoreCommand: - printf("plugin: backup command=%s\n", (char *)value); + printf("plugin: backup command=%s\n", NPRT((char *)value)); break; case bEventBackupCommand: - printf("plugin: backup command=%s\n", (char *)value); + printf("plugin: backup command=%s\n", NPRT((char *)value)); break; default: