fixed argument handling in unit definitions

master
Christopher M. Punches 2021-07-26 01:17:41 -04:00
parent 5287a1baa9
commit 23f64c026c
7 changed files with 28 additions and 13 deletions

View File

@ -20,7 +20,6 @@
*/ */
#include "Sproc.h" #include "Sproc.h"
#include "../loaders/misc/helpers.h"
#include "sys/stat.h" #include "sys/stat.h"
#define PARENT default #define PARENT default
@ -161,6 +160,7 @@ int set_identity_context( std::string task_name, std::string user_name, std::str
} }
/// Sproc::execute /// Sproc::execute
/// ///
/// \param input - The commandline input to execute. /// \param input - The commandline input to execute.
@ -231,6 +231,7 @@ int Sproc::execute(std::string shell, std::string environment_file, std::string
// build the command to execute in the shell // build the command to execute in the shell
std::string sourcer = ". " + environment_file + " && " + command; std::string sourcer = ". " + environment_file + " && " + command;
// Show the user a debug print of what is going to be executed in the shell. // Show the user a debug print of what is going to be executed in the shell.
slog.log(E_DEBUG, "[ '" + task_name + "' ] Shell call for loading: ``" + sourcer + "``."); slog.log(E_DEBUG, "[ '" + task_name + "' ] Shell call for loading: ``" + sourcer + "``.");
@ -315,11 +316,16 @@ int Sproc::execute(std::string shell, std::string environment_file, std::string
slog.log( E_INFO, "[ '" + task_name + "' ] Identity context set as user '" + user_name + "' and group '" + group_name + "'." ); slog.log( E_INFO, "[ '" + task_name + "' ] Identity context set as user '" + user_name + "' and group '" + group_name + "'." );
} }
slog.log( E_DEBUG, "[ '" + task_name + "' ] EXECL_CALL_PARAM: " + sourcer.c_str() );
slog.log( E_DEBUG, "[ '" + task_name + "' ] CWD: " + get_current_dir_name() );
// execute our big nasty thing // execute our big nasty thing
// int ret = execlp( shell.c_str(), shell.c_str(), "-c", sourcer.c_str(), (char*)NULL );
int ret = execl(shell.c_str(), shell.c_str(), "-c", sourcer.c_str(), (char*)NULL ); int ret = execl(shell.c_str(), shell.c_str(), "-c", sourcer.c_str(), (char*)NULL );
// print something useful to debug with if execl fails // print something useful to debug with if execl fails
slog.log(E_FATAL, "ret code: " + std::to_string(ret) + "; errno: " + strerror(errno)); slog.log(E_FATAL, "[ '" + task_name + "' ] ret code: " + std::to_string(ret) + "; errno: " + strerror(errno));
// exit child -- if this is executing, you've had a failure // exit child -- if this is executing, you've had a failure
exit(exit_code_raw); exit(exit_code_raw);

View File

@ -35,6 +35,8 @@
#include <grp.h> #include <grp.h>
#include <fstream> #include <fstream>
#include "fcntl.h" #include "fcntl.h"
#include "../loaders/misc/helpers.h"
// exit codes for Rex // exit codes for Rex
enum SPROC_RETURN_CODES { enum SPROC_RETURN_CODES {

View File

@ -201,15 +201,20 @@ void Task::execute(Conf * configuration )
// ....sourcing on the shell for variables and environment population doesn't have a good smell. // ....sourcing on the shell for variables and environment population doesn't have a good smell.
this->slog.log( E_INFO, "[ '" + task_name + "' ] Executing target: \"" + target_command + "\"." ); this->slog.log( E_INFO, "[ '" + task_name + "' ] Executing target: \"" + target_command + "\"." );
if ( exists( target_command ) )
std::string delimiter = " ";
int space_index = target_command.find( delimiter );
std::string bin_path = target_command.substr( 0, space_index );
if ( exists( bin_path ) )
{ {
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Target executable found."); this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Target executable found.");
} else { } else {
this->slog.log( E_FATAL, "[ '" + task_name + "' ] Target executable does not exist." ); this->slog.log( E_FATAL, "[ '" + task_name + "' ] Target executable does not exist." );
throw Task_NotReady(); throw Task_NotReady();
} }
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Vars file: " + this->definition.get_env_vars_file() ); this->slog.log( E_INFO, "[ '" + task_name + "' ] Vars file: " + this->definition.get_env_vars_file() );
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Shell: " + this->definition.get_shell() ); this->slog.log( E_INFO, "[ '" + task_name + "' ] Shell: " + this->definition.get_shell() );
std::string static_env_file = configuration->get_execution_context() + "/" + this->definition.get_env_vars_file(); std::string static_env_file = configuration->get_execution_context() + "/" + this->definition.get_env_vars_file();

View File

@ -19,6 +19,7 @@
*/ */
#include "helpers.h" #include "helpers.h"
bool exists(const std::string& name) bool exists(const std::string& name)

View File

@ -31,6 +31,7 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#include <vector>
bool exists (const std::string& name); bool exists (const std::string& name);
@ -39,6 +40,6 @@ bool is_file( std::string );
bool is_dir( std::string ); bool is_dir( std::string );
std::string get_8601(); std::string get_8601();
const char * command2args( std::string input_string );
#endif //REX_HELPERS_JH #endif //REX_HELPERS_JH

View File

@ -1,6 +1,6 @@
{ {
"execution_context_override": true, "execution_context_override": true,
"execution_context": "/home/bagira/development/internal/rex/test", "execution_context": "/home/bagira/development/internal/Rex/test",
"units_path": "units/", "units_path": "units/",
"logs_path": "logs/", "logs_path": "logs/",
"config_version": "4" "config_version": "4"

View File

@ -2,7 +2,7 @@
"units": [ "units": [
{ {
"name": "independent test 1", "name": "independent test 1",
"target": "components/independent_test_1.bash", "target": "components/independent_test_1.bash --ls -s --arg",
"rectifier": "", "rectifier": "",
"active": true, "active": true,
"required": true, "required": true,
@ -10,12 +10,12 @@
"user": "bagira", "user": "bagira",
"group": "bagira", "group": "bagira",
"rectify": false, "rectify": false,
"shell": "/usr/bin/env bash", "shell": "/usr/bin/bash",
"environment": "environments/rex.variables" "environment": "environments/rex.variables"
}, },
{ {
"name": "independent test 2", "name": "independent test 2",
"target": "components/independent_test_2.bash", "target": "components/independent_test_2.bash --ls",
"rectifier": "", "rectifier": "",
"active": true, "active": true,
"required": true, "required": true,