X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fplugins%2Ffd%2Fbpipe-fd.c;h=d6091fce93863fbe248b59391cd03c1bff967f74;hb=7c3df9d20a1d06c21b33c6f03a583aeac0585cf6;hp=a22811186b25563488c312ffd229a640248581cf;hpb=ec049b4b604b0e3576b3437ab2414bb941f7c78e;p=bacula%2Fbacula diff --git a/bacula/src/plugins/fd/bpipe-fd.c b/bacula/src/plugins/fd/bpipe-fd.c index a22811186b..d6091fce93 100644 --- a/bacula/src/plugins/fd/bpipe-fd.c +++ b/bacula/src/plugins/fd/bpipe-fd.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2007-2008 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. @@ -45,7 +45,9 @@ extern "C" { #endif -#define PLUGIN_LICENSE "GPLv2" +static const int dbglvl = 150; + +#define PLUGIN_LICENSE "Bacula GPLv2" #define PLUGIN_AUTHOR "Kern Sibbald" #define PLUGIN_DATE "January 2008" #define PLUGIN_VERSION "1" @@ -171,6 +173,9 @@ static bRC newPlugin(bpContext *ctx) static bRC freePlugin(bpContext *ctx) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } if (p_ctx->cmd) { free(p_ctx->cmd); /* free any allocated command string */ } @@ -201,6 +206,10 @@ static bRC setPluginValue(bpContext *ctx, pVariable var, void *value) static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } + // char *name; /* @@ -209,8 +218,12 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) * what is really going on. */ switch (event->eventType) { + case bEventPluginCommand: + bfuncs->DebugMessage(ctx, fi, li, dbglvl, + "bpipe-fd: PluginCommand=%s\n", (char *)value); + break; case bEventJobStart: - bfuncs->DebugMessage(ctx, fi, li, 50, "bpipe-fd: JobStart=%s\n", (char *)value); + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "bpipe-fd: JobStart=%s\n", (char *)value); break; case bEventJobEnd: // printf("bpipe-fd: JobEnd\n"); @@ -238,11 +251,11 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) /* Plugin command e.g. plugin = ::read command:write command */ case bEventRestoreCommand: - printf("bpipe-fd: EventRestoreCommand cmd=%s\n", (char *)value); +// printf("bpipe-fd: EventRestoreCommand cmd=%s\n", (char *)value); /* Fall-through wanted */ case bEventBackupCommand: char *p; - bfuncs->DebugMessage(ctx, fi, li, 50, "bpipe-fd: pluginEvent cmd=%s\n", (char *)value); + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "bpipe-fd: pluginEvent cmd=%s\n", (char *)value); p_ctx->cmd = strdup((char *)value); p = strchr(p_ctx->cmd, ':'); if (!p) { @@ -265,12 +278,13 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) } *p++ = 0; /* terminate reader string */ p_ctx->writer = p; - printf("bpipe-fd: plugin=%s fname=%s reader=%s writer=%s\n", - p_ctx->cmd, p_ctx->fname, p_ctx->reader, p_ctx->writer); +// printf("bpipe-fd: plugin=%s fname=%s reader=%s writer=%s\n", +// p_ctx->cmd, p_ctx->fname, p_ctx->reader, p_ctx->writer); break; default: - printf("bpipe-fd: unknown event=%d\n", event->eventType); +// printf("bpipe-fd: unknown event=%d\n", event->eventType); + break; } return bRC_OK; } @@ -281,6 +295,9 @@ static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value) static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } time_t now = time(NULL); sp->fname = p_ctx->fname; sp->type = FT_REG; @@ -315,17 +332,20 @@ static bRC endBackupFile(bpContext *ctx) static bRC pluginIO(bpContext *ctx, struct io_pkt *io) { struct plugin_ctx *p_ctx = (struct plugin_ctx *)ctx->pContext; + if (!p_ctx) { + return bRC_Error; + } io->status = 0; io->io_errno = 0; switch(io->func) { case IO_OPEN: - bfuncs->DebugMessage(ctx, fi, li, 50, "bpipe-fd: IO_OPEN\n"); + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "bpipe-fd: IO_OPEN\n"); if (io->flags & (O_CREAT | O_WRONLY)) { char *writer_codes = apply_rp_codes(p_ctx); p_ctx->fd = popen(writer_codes, "w"); - bfuncs->DebugMessage(ctx, fi, li, 50, "bpipe-fd: IO_OPEN fd=%d writer=%s\n", + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "bpipe-fd: IO_OPEN fd=%d writer=%s\n", p_ctx->fd, writer_codes); if (!p_ctx->fd) { io->io_errno = errno; @@ -341,7 +361,7 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) } } else { p_ctx->fd = popen(p_ctx->reader, "r"); - bfuncs->DebugMessage(ctx, fi, li, 50, "bpipe-fd: IO_OPEN fd=%p reader=%s\n", + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "bpipe-fd: IO_OPEN fd=%p reader=%s\n", p_ctx->fd, p_ctx->reader); if (!p_ctx->fd) { io->io_errno = errno; @@ -359,11 +379,11 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) return bRC_Error; } io->status = fread(io->buf, 1, io->count, p_ctx->fd); -// bfuncs->DebugMessage(ctx, fi, li, 50, "bpipe-fd: IO_READ buf=%p len=%d\n", io->buf, io->status); +// bfuncs->DebugMessage(ctx, fi, li, dbglvl, "bpipe-fd: IO_READ buf=%p len=%d\n", io->buf, io->status); if (io->status == 0 && ferror(p_ctx->fd)) { bfuncs->JobMessage(ctx, fi, li, M_FATAL, 0, "Pipe read error: ERR=%s\n", strerror(errno)); - bfuncs->DebugMessage(ctx, fi, li, 50, + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "Pipe read error: ERR=%s\n", strerror(errno)); return bRC_Error; } @@ -380,7 +400,7 @@ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) if (io->status == 0 && ferror(p_ctx->fd)) { bfuncs->JobMessage(ctx, fi, li, M_FATAL, 0, "Pipe write error\n"); - bfuncs->DebugMessage(ctx, fi, li, 50, + bfuncs->DebugMessage(ctx, fi, li, dbglvl, "Pipe read error: ERR=%s\n", strerror(errno)); return bRC_Error; }