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 "../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);

View File

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

View File

@ -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();

View File

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

View File

@ -31,6 +31,7 @@
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
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

View File

@ -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"

View File

@ -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,