From: Radosław Korzeniewski Date: Tue, 19 Oct 2021 15:43:05 +0000 (+0200) Subject: pluginlib: Update execprog class. X-Git-Tag: Beta-15.0.0~798 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1821600bef9057dfcbb8b323ddc206de032c7bd9;p=thirdparty%2Fbacula.git pluginlib: Update execprog class. --- diff --git a/bacula/src/plugins/fd/pluginlib/execprog.cpp b/bacula/src/plugins/fd/pluginlib/execprog.cpp index af68ce78f..8d4c8fb52 100644 --- a/bacula/src/plugins/fd/pluginlib/execprog.cpp +++ b/bacula/src/plugins/fd/pluginlib/execprog.cpp @@ -44,13 +44,15 @@ */ void EXECPROG::terminate(bpContext *ctx, bool raise_error) { - if (is_closed()){ + if (is_closed()) + { return; } // after close_bpipe it is no longer available tstatus = close_bpipe(bpipe); - if (tstatus && raise_error){ + if (tstatus && raise_error) + { /* error during close */ berrno be; DMSG(ctx, DERROR, "Error closing command. Err=%s\n", be.bstrerror(tstatus)); @@ -66,22 +68,6 @@ void EXECPROG::terminate(bpContext *ctx, bool raise_error) bpipe = NULL; }; -/* - * Run command and prepared parameters. - */ -bool EXECPROG::execute_command(bpContext *ctx, const POOL_MEM &cmd, const POOL_MEM &args) -{ - return execute_command(ctx, cmd.c_str(), args.c_str()); -} - -/* - * Run command and prepared parameters. - */ -bool EXECPROG::execute_command(bpContext *ctx, const POOL_MEM &cmd) -{ - return execute_command(ctx, cmd.c_str()); -} - /* * Run command and prepared parameters. * @@ -92,11 +78,12 @@ bool EXECPROG::execute_command(bpContext *ctx, const POOL_MEM &cmd) * True - when command execute successfully * False - when execution return error */ -bool EXECPROG::execute_command(bpContext *ctx, const POOLMEM *cmd, const POOLMEM *args) +bool EXECPROG::execute_command(bpContext *ctx, const char *cmd, const char *args) { POOL_MEM exe_cmd(PM_FNAME); - if (cmd == NULL){ + if (cmd == NULL) + { /* cannot execute command NULL */ DMSG0(ctx, DERROR, "Logic error: Cannot execute NULL command!\n"); JMSG0(ctx, M_FATAL, "Logic error: Cannot execute NULL command!\n"); @@ -107,7 +94,8 @@ bool EXECPROG::execute_command(bpContext *ctx, const POOLMEM *cmd, const POOLMEM Mmsg(exe_cmd, "%s %s", cmd, args); DMSG(ctx, DINFO, "Executing: %s\n", exe_cmd.c_str()); bpipe = open_bpipe(exe_cmd.c_str(), 0, "rw"); - if (bpipe == NULL){ + if (bpipe == NULL) + { berrno be; DMSG(ctx, DERROR, "Unable to run command. Err=%s\n", be.bstrerror()); JMSG(ctx, M_FATAL, "Unable to run command. Err=%s\n", be.bstrerror()); diff --git a/bacula/src/plugins/fd/pluginlib/execprog.h b/bacula/src/plugins/fd/pluginlib/execprog.h index 1ecc83195..e7700bb3c 100644 --- a/bacula/src/plugins/fd/pluginlib/execprog.h +++ b/bacula/src/plugins/fd/pluginlib/execprog.h @@ -170,9 +170,14 @@ public: inline int get_terminate_status() { return tstatus; }; /* all you need is to simply execute the command first */ - bool execute_command(bpContext *ctx, const POOLMEM *cmd, const POOLMEM *args = ""); - bool execute_command(bpContext *ctx, const POOL_MEM &cmd, const POOL_MEM &args); - bool execute_command(bpContext *ctx, const POOL_MEM &cmd); + bool execute_command(bpContext *ctx, const char *cmd, const char *args = ""); + + /* + * Run command and prepared parameters. + */ + inline bool execute_command(bpContext *ctx, const char *cmd, const POOL_MEM &args) { return execute_command(ctx, cmd, args.c_str()); } + inline bool execute_command(bpContext *ctx, const POOL_MEM &cmd, const POOL_MEM &args) { return execute_command(ctx, cmd.c_str(), args.c_str()); } + inline bool execute_command(bpContext *ctx, const POOL_MEM &cmd) { return execute_command(ctx, cmd.c_str()); } /* then just simply read or write data to it */ int32_t read_data(bpContext *ctx, POOLMEM *buf, int32_t len);