*/
#include "bacula.h"
#include "jcr.h"
-#include "lib/plugin.h"
#include "fd-plugins.h"
const int dbglvl = 0;
static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
int level, const char *msg);
-void load_fd_plugins(const char *plugin_dir);
-void new_plugins(JCR *jcr);
-void free_plugins(JCR *jcr);
-void plugin_event(JCR *jcr, bEventType event);
-
/* Bacula info */
static bInfo binfo = {
baculaJobMsg,
baculaDebugMsg
};
-
-
-void plugin_event(JCR *jcr, bEventType eventType)
+/*
+ * Create a plugin event
+ */
+void generate_plugin_event(JCR *jcr, bEventType eventType)
{
bEvent event;
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
event.eventType = eventType;
}
plugin_list = New(alist(10, not_owned_by_alist));
-
load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type);
}
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
int num = plugin_list->size();
if (num == 0) {
jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num);
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
- Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
+ Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
foreach_alist(plugin, plugin_list) {
/* Start a new instance of each plugin */
plugin_ctx[i].bContext = (void *)jcr;
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
foreach_alist(plugin, plugin_list) {
/* Free the plugin instance */
plug_func(plugin)->freePlugin(&plugin_ctx[i++]);
}
+/* ==============================================================
+ *
+ * Callbacks from the plugin
+ *
+ * ==============================================================
+ */
static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
{
JCR *jcr = (JCR *)(ctx->bContext);
- Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
+// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
if (!value) {
return 1;
}
- Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
+// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
switch (var) {
case bVarJobId:
*((int *)value) = jcr->JobId;
Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId);
break;
case bVarFDName:
- *((char **)value) = "FD Name";
+ *((char **)value) = my_name;
+ Dmsg1(dbglvl, "Bacula: return my_name=%s\n", my_name);
break;
case bVarLevel:
case bVarType:
#ifdef TEST_PROGRAM
+char my_name = "test-fd";
+
int main(int argc, char *argv[])
{
char plugin_dir[1000];
jcr2->JobId = 222;
new_plugins(jcr2);
- plugin_event(jcr1, bEventJobStart);
- plugin_event(jcr1, bEventJobEnd);
- plugin_event(jcr2, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobStart);
free_plugins(jcr1);
- plugin_event(jcr2, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobEnd);
free_plugins(jcr2);
unload_plugins();
#endif
+
+
/****************************************************************************
* *
* Bacula definitions *
int level, const char *msg);
} bFuncs;
+/* Bacula Subroutines */
+void load_fd_plugins(const char *plugin_dir);
+void new_plugins(JCR *jcr);
+void free_plugins(JCR *jcr);
+void generate_plugin_event(JCR *jcr, bEventType event);
+
+
/****************************************************************************
* *
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2008 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.
create_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
read_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
+ load_fd_plugins(me->plugin_directory);
+
drop(uid, gid);
#ifdef BOMB
bnet_stop_thread_server(server_tid);
generate_daemon_event(NULL, "Exit");
+ unload_plugins();
write_state_file(me->working_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
delete_pid_file(me->pid_directory, "bacula-fd", get_first_port_host_order(me->FDaddrs));
-/*
- * Bacula File Daemon specific configuration and defines
- *
- * Kern Sibbald, Jan MMI
- *
- * Version $Id$
- */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2001-2006 Free Software Foundation Europe e.V.
+ Copyright (C) 2001-2008 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.
(FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
Switzerland, email:ftf@fsfeurope.org.
*/
+/*
+ * Bacula File Daemon specific configuration and defines
+ *
+ * Kern Sibbald, Jan MMI
+ *
+ * Version $Id$
+ */
+
#define FILE_DAEMON 1
#include "filed_conf.h"
+#include "fd-plugins.h"
#include "findlib/find.h"
#include "jcr.h"
#include "acl.h"
if (res->res_client.scripts_directory) {
free(res->res_client.scripts_directory);
}
+ if (res->res_client.plugin_directory) {
+ free(res->res_client.plugin_directory);
+ }
if (res->res_client.FDaddrs) {
free_addresses(res->res_client.FDaddrs);
}
jcr->last_fname = get_pool_memory(PM_FNAME);
jcr->last_fname[0] = 0;
jcr->client_name = get_memory(strlen(my_name) + 1);
+ new_plugins(jcr); /* instantiate plugins for this jcr */
pm_strcpy(jcr->client_name, my_name);
jcr->pki_sign = me->pki_sign;
jcr->pki_encrypt = me->pki_encrypt;
}
generate_daemon_event(jcr, "JobEnd");
+ generate_plugin_event(jcr, bEventJobEnd);
dequeue_messages(jcr); /* send any queued messages */
/* Inform Director that we are done */
- bnet_sig(dir, BNET_TERMINATE);
+ dir->signal(BNET_TERMINATE);
+
+ free_plugins(jcr); /* release instantiated plugins */
/* Clean up fileset */
FF_PKT *ff = jcr->ff;
}
generate_daemon_event(jcr, "JobStart");
+ generate_plugin_event(jcr, bEventJobStart);
#if defined(WIN32_VSS)
/* START VSS ON WIN 32 */
dir->fsend(OKverify);
generate_daemon_event(jcr, "JobStart");
+ generate_plugin_event(jcr, bEventJobStart);
Dmsg1(110, "bfiled>dird: %s", dir->msg);
jcr->replace = replace;
jcr->prefix_links = prefix_links;
- bnet_fsend(dir, OKrestore);
+ dir->fsend(OKrestore);
Dmsg1(110, "bfiled>dird: %s", dir->msg);
jcr->JobType = JT_RESTORE;
*/
start_dir_heartbeat(jcr);
generate_daemon_event(jcr, "JobStart");
+ generate_plugin_event(jcr, bEventJobStart);
do_restore(jcr);
stop_dir_heartbeat(jcr);
/*
* Send Close session command to Storage daemon
*/
- bnet_fsend(sd, read_close, jcr->Ticket);
+ sd->fsend(read_close, jcr->Ticket);
Dmsg1(130, "bfiled>stored: %s", sd->msg);
bget_msg(sd); /* get OK */
/* Inform Storage daemon that we are done */
- bnet_sig(sd, BNET_TERMINATE);
+ sd->signal(BNET_TERMINATE);
bail_out:
*/
#include "bacula.h"
#include "jcr.h"
-#include "lib/plugin.h"
#include "fd-plugins.h"
const int dbglvl = 0;
static bpError baculaDebugMsg(bpContext *ctx, const char *file, int line,
int level, const char *msg);
-void load_fd_plugins(const char *plugin_dir);
-void new_plugins(JCR *jcr);
-void free_plugins(JCR *jcr);
-void plugin_event(JCR *jcr, bEventType event);
-
/* Bacula info */
static bInfo binfo = {
baculaJobMsg,
baculaDebugMsg
};
-
-
-void plugin_event(JCR *jcr, bEventType eventType)
+/*
+ * Create a plugin event
+ */
+void generate_plugin_event(JCR *jcr, bEventType eventType)
{
bEvent event;
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
event.eventType = eventType;
}
plugin_list = New(alist(10, not_owned_by_alist));
-
load_plugins((void *)&binfo, (void *)&bfuncs, plugin_dir, plugin_type);
}
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
int num = plugin_list->size();
if (num == 0) {
jcr->plugin_ctx = (void *)malloc(sizeof(bpContext) * num);
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
- Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
+ Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
foreach_alist(plugin, plugin_list) {
/* Start a new instance of each plugin */
plugin_ctx[i].bContext = (void *)jcr;
Plugin *plugin;
int i = 0;
+ if (!plugin_list) {
+ return;
+ }
+
bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+ Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx, jcr->JobId);
foreach_alist(plugin, plugin_list) {
/* Free the plugin instance */
plug_func(plugin)->freePlugin(&plugin_ctx[i++]);
}
+/* ==============================================================
+ *
+ * Callbacks from the plugin
+ *
+ * ==============================================================
+ */
static bpError baculaGetValue(bpContext *ctx, bVariable var, void *value)
{
JCR *jcr = (JCR *)(ctx->bContext);
- Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
+// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
if (!value) {
return 1;
}
- Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
+// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr);
switch (var) {
case bVarJobId:
*((int *)value) = jcr->JobId;
Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId);
break;
case bVarFDName:
- *((char **)value) = "FD Name";
+ *((char **)value) = my_name;
+ Dmsg1(dbglvl, "Bacula: return my_name=%s\n", my_name);
break;
case bVarLevel:
case bVarType:
#ifdef TEST_PROGRAM
+
int main(int argc, char *argv[])
{
char plugin_dir[1000];
JCR mjcr1, mjcr2;
JCR *jcr1 = &mjcr1;
JCR *jcr2 = &mjcr2;
+
+ strcpy(my_name, "test-fd");
getcwd(plugin_dir, sizeof(plugin_dir)-1);
load_fd_plugins(plugin_dir);
jcr2->JobId = 222;
new_plugins(jcr2);
- plugin_event(jcr1, bEventJobStart);
- plugin_event(jcr1, bEventJobEnd);
- plugin_event(jcr2, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobStart);
+ generate_plugin_event(jcr1, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobStart);
free_plugins(jcr1);
- plugin_event(jcr2, bEventJobEnd);
+ generate_plugin_event(jcr2, bEventJobEnd);
free_plugins(jcr2);
unload_plugins();
#endif
+
+
/****************************************************************************
* *
* Bacula definitions *
int level, const char *msg);
} bFuncs;
+/* Bacula Subroutines */
+void load_fd_plugins(const char *plugin_dir);
+void new_plugins(JCR *jcr);
+void free_plugins(JCR *jcr);
+void generate_plugin_event(JCR *jcr, bEventType event);
+
+
/****************************************************************************
* *