diff --git a/src/Sproc/Sproc.cpp b/src/Sproc/Sproc.cpp index eef2981..18a2e74 100644 --- a/src/Sproc/Sproc.cpp +++ b/src/Sproc/Sproc.cpp @@ -20,7 +20,6 @@ */ #include "Sproc.h" -#include "../loaders/misc/helpers.h" #include "sys/stat.h" #define PARENT default @@ -161,6 +160,7 @@ int set_identity_context( std::string task_name, std::string user_name, std::str } + /// Sproc::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 std::string sourcer = ". " + environment_file + " && " + command; + // 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 + "``."); @@ -314,12 +315,17 @@ int Sproc::execute(std::string shell, std::string environment_file, std::string } else { 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 - int ret = execl( shell.c_str(), shell.c_str(), "-c", sourcer.c_str(), (char *) NULL); + // 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 ); // 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(exit_code_raw); diff --git a/src/Sproc/Sproc.h b/src/Sproc/Sproc.h index 3a073c6..7f0f0aa 100644 --- a/src/Sproc/Sproc.h +++ b/src/Sproc/Sproc.h @@ -35,6 +35,8 @@ #include #include #include "fcntl.h" +#include "../loaders/misc/helpers.h" + // exit codes for Rex enum SPROC_RETURN_CODES { diff --git a/src/loaders/abstract/Task.cpp b/src/loaders/abstract/Task.cpp index bdb6a1e..376c7d2 100644 --- a/src/loaders/abstract/Task.cpp +++ b/src/loaders/abstract/Task.cpp @@ -166,7 +166,7 @@ bool Task::has_definition() /// Task::execute - execute a task's unit definition. /// See the design document for what flow control needs to look like here. /// \param verbose - Verbosity level - not implemented yet. -void Task::execute(Conf * configuration ) +void Task::execute( Conf * configuration ) { // DUFFING - If rex is broken it's probably going to be in this block. // Somebody come clean this up, eh? @@ -201,15 +201,20 @@ void Task::execute(Conf * configuration ) // ....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 + "\"." ); - 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."); } else { this->slog.log( E_FATAL, "[ '" + task_name + "' ] Target executable does not exist." ); throw Task_NotReady(); } - this->slog.log( E_DEBUG, "[ '" + 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 + "' ] Vars file: " + this->definition.get_env_vars_file() ); + 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(); diff --git a/src/loaders/misc/helpers.cpp b/src/loaders/misc/helpers.cpp index 61fc37d..39f8087 100644 --- a/src/loaders/misc/helpers.cpp +++ b/src/loaders/misc/helpers.cpp @@ -19,6 +19,7 @@ */ + #include "helpers.h" bool exists(const std::string& name) diff --git a/src/loaders/misc/helpers.h b/src/loaders/misc/helpers.h index 2750123..a62cfcc 100644 --- a/src/loaders/misc/helpers.h +++ b/src/loaders/misc/helpers.h @@ -31,6 +31,7 @@ #include #include #include +#include bool exists (const std::string& name); @@ -39,6 +40,6 @@ bool is_file( std::string ); bool is_dir( std::string ); std::string get_8601(); - +const char * command2args( std::string input_string ); #endif //REX_HELPERS_JH diff --git a/test/config.json b/test/config.json index 05f6f57..cf657e3 100644 --- a/test/config.json +++ b/test/config.json @@ -1,6 +1,6 @@ { "execution_context_override": true, - "execution_context": "/home/bagira/development/internal/rex/test", + "execution_context": "/home/bagira/development/internal/Rex/test", "units_path": "units/", "logs_path": "logs/", "config_version": "4" diff --git a/test/units/all_test.units b/test/units/all_test.units index 3a7984e..0779aa4 100644 --- a/test/units/all_test.units +++ b/test/units/all_test.units @@ -2,7 +2,7 @@ "units": [ { "name": "independent test 1", - "target": "components/independent_test_1.bash", + "target": "components/independent_test_1.bash --ls -s --arg", "rectifier": "", "active": true, "required": true, @@ -10,12 +10,12 @@ "user": "bagira", "group": "bagira", "rectify": false, - "shell": "/usr/bin/env bash", + "shell": "/usr/bin/bash", "environment": "environments/rex.variables" }, { "name": "independent test 2", - "target": "components/independent_test_2.bash", + "target": "components/independent_test_2.bash --ls", "rectifier": "", "active": true, "required": true,