parent
004addd2b4
commit
d0fbd30f31
|
@ -1,5 +1,8 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/bash
|
||||||
echo "This is an independent test. It does not depend on other tests."
|
#
|
||||||
echo "Environment file check: TEST_VAR from environment file is set to: $TEST_VAR"
|
echo test from script
|
||||||
|
/usr/bin/dialog --title "This should be one argument" --inputbox "Enter your name:" 0 0
|
||||||
|
|
||||||
exit $?
|
|
||||||
|
|
||||||
|
env
|
||||||
|
|
|
@ -8,4 +8,5 @@ set -a
|
||||||
|
|
||||||
echo "variables file says hello and set a variable named TEST_VAR"
|
echo "variables file says hello and set a variable named TEST_VAR"
|
||||||
TEST_VAR="999"
|
TEST_VAR="999"
|
||||||
|
TERM=xterm
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
lcpex: setgid failed: Operation not permitted
|
|
||||||
lcpex: Aborting: Setting GID failed: bagira/bagira
|
|
|
@ -1 +0,0 @@
|
||||||
/usr/bin/bash: line 1: /home/phanes/development/internal/rex-rewrite/sample/environments/rex.variables: Permission denied
|
|
|
@ -1 +0,0 @@
|
||||||
/usr/bin/bash: line 1: /home/phanes/development/internal/rex-rewrite/sample/environments/rex.variables: Permission denied
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"project_root": "/home/phanes/development/internal/rex-rewrite/sample",
|
"project_root": "/tmp/sample",
|
||||||
"units_path": "units/",
|
"units_path": "units/",
|
||||||
"logs_path": "logs/",
|
"logs_path": "logs/",
|
||||||
"shells_path": "shells/shells.definitions",
|
"shells_path": "shells/shells.definitions",
|
||||||
|
|
Binary file not shown.
|
@ -36,15 +36,15 @@ std::string prefix_generator(
|
||||||
// it's not a shell command, so we can just execute it directly
|
// it's not a shell command, so we can just execute it directly
|
||||||
prefix = command;
|
prefix = command;
|
||||||
}
|
}
|
||||||
std::cout << "prefix: " << prefix << std::endl;
|
std::cout << "LAUNCHER: " << prefix << std::endl;
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lcpex(
|
int lcpex(
|
||||||
std::string command,
|
std::string command,
|
||||||
std::string stdout_log_file,
|
FILE * stdout_log_fh,
|
||||||
std::string stderr_log_file,
|
FILE * stderr_log_fh,
|
||||||
bool context_override,
|
bool context_override,
|
||||||
std::string context_user,
|
std::string context_user,
|
||||||
std::string context_group,
|
std::string context_group,
|
||||||
|
@ -72,11 +72,11 @@ int lcpex(
|
||||||
// if we are forcing a pty, then we will use the vpty library
|
// if we are forcing a pty, then we will use the vpty library
|
||||||
if( force_pty )
|
if( force_pty )
|
||||||
{
|
{
|
||||||
return exec_pty( command, stdout_log_file, stderr_log_file, context_override, context_user, context_group, supply_environment );
|
return exec_pty( command, stdout_log_fh, stderr_log_fh, context_override, context_user, context_group, supply_environment );
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, we will use the execute function
|
// otherwise, we will use the execute function
|
||||||
return execute( command, stdout_log_file, stderr_log_file, context_override, context_user, context_group, supply_environment );
|
return execute( command, stdout_log_fh, stderr_log_fh, context_override, context_user, context_group, supply_environment );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,8 +161,8 @@ void run_child_process(bool context_override, const char* context_user, const ch
|
||||||
|
|
||||||
int execute(
|
int execute(
|
||||||
std::string command,
|
std::string command,
|
||||||
std::string stdout_log_file,
|
FILE * stdout_log_fh,
|
||||||
std::string stderr_log_file,
|
FILE * stderr_log_fh,
|
||||||
bool context_override,
|
bool context_override,
|
||||||
std::string context_user,
|
std::string context_user,
|
||||||
std::string context_group,
|
std::string context_group,
|
||||||
|
@ -183,10 +183,6 @@ int execute(
|
||||||
clearenv();
|
clearenv();
|
||||||
}
|
}
|
||||||
|
|
||||||
// open file handles to the two log files we need to create for each execution
|
|
||||||
FILE * stdout_log_fh = fopen( stdout_log_file.c_str(), "a+" );
|
|
||||||
FILE * stderr_log_fh = fopen( stderr_log_file.c_str(), "a+" );
|
|
||||||
|
|
||||||
// create the pipes for the child process to write and read from using its stdin/stdout/stderr
|
// create the pipes for the child process to write and read from using its stdin/stdout/stderr
|
||||||
int fd_child_stdout_pipe[2];
|
int fd_child_stdout_pipe[2];
|
||||||
int fd_child_stderr_pipe[2];
|
int fd_child_stderr_pipe[2];
|
||||||
|
@ -325,9 +321,7 @@ int execute(
|
||||||
// wait for child to exit, capture status
|
// wait for child to exit, capture status
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
|
||||||
// close the log file handles
|
|
||||||
fclose(stdout_log_fh);
|
|
||||||
fclose(stderr_log_fh);
|
|
||||||
if WIFEXITED(status) {
|
if WIFEXITED(status) {
|
||||||
return WEXITSTATUS(status);
|
return WEXITSTATUS(status);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
*/
|
*/
|
||||||
int execute(
|
int execute(
|
||||||
std::string command,
|
std::string command,
|
||||||
std::string stdout_log_file,
|
FILE * stdout_log_fh,
|
||||||
std::string stderr_log_file,
|
FILE * stderr_log_fh,
|
||||||
bool context_override,
|
bool context_override,
|
||||||
std::string context_user,
|
std::string context_user,
|
||||||
std::string context_group,
|
std::string context_group,
|
||||||
|
@ -76,8 +76,8 @@ int execute(
|
||||||
*/
|
*/
|
||||||
int lcpex(
|
int lcpex(
|
||||||
std::string command,
|
std::string command,
|
||||||
std::string stdout_log_file,
|
FILE * stdout_log_fh,
|
||||||
std::string stderr_log_file,
|
FILE * stderr_log_fh,
|
||||||
bool context_override,
|
bool context_override,
|
||||||
std::string context_user,
|
std::string context_user,
|
||||||
std::string context_group,
|
std::string context_group,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "string_expansion.h"
|
#include "string_expansion.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// convert a string to a char** representing our artificial argv to be consumed by execvp
|
// convert a string to a char** representing our artificial argv to be consumed by execvp
|
||||||
char ** expand_env(const std::string& var, int flags )
|
char ** expand_env(const std::string& var, int flags )
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,8 +94,8 @@ void run_child_process( int fd_child_stderr_pipe[2], char * processed_command[],
|
||||||
// - TEE child stdout/stderr to parent stdout/stderr
|
// - TEE child stdout/stderr to parent stdout/stderr
|
||||||
int exec_pty(
|
int exec_pty(
|
||||||
std::string command,
|
std::string command,
|
||||||
std::string stdout_log_file,
|
FILE * stdout_log_fh,
|
||||||
std::string stderr_log_file,
|
FILE * stderr_log_fh,
|
||||||
bool context_override,
|
bool context_override,
|
||||||
std::string context_user,
|
std::string context_user,
|
||||||
std::string context_group,
|
std::string context_group,
|
||||||
|
@ -114,14 +114,11 @@ int exec_pty(
|
||||||
// turn our command string into something execvp can consume
|
// turn our command string into something execvp can consume
|
||||||
char ** processed_command = expand_env( command );
|
char ** processed_command = expand_env( command );
|
||||||
|
|
||||||
// open file handles to the two log files we need to create for each execution
|
|
||||||
FILE * stdout_log_fh = fopen( stdout_log_file.c_str(), "a+" );
|
|
||||||
FILE * stderr_log_fh = fopen( stderr_log_file.c_str(), "a+" );
|
|
||||||
|
|
||||||
if ( stdout_log_fh == NULL ) {
|
if ( stdout_log_fh == NULL ) {
|
||||||
safe_perror( "Error opening STDOUT log file. Aborting.", &ttyOrig );
|
safe_perror( "Error opening STDOUT log file. Aborting.", &ttyOrig );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( stderr_log_fh == NULL ) {
|
if ( stderr_log_fh == NULL ) {
|
||||||
safe_perror( "Error opening STDERR log file. Aborting.", &ttyOrig );
|
safe_perror( "Error opening STDERR log file. Aborting.", &ttyOrig );
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
|
@ -277,9 +274,6 @@ int exec_pty(
|
||||||
// wait for child to exit, capture status
|
// wait for child to exit, capture status
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
|
||||||
// close the log file handles
|
|
||||||
fclose(stdout_log_fh);
|
|
||||||
fclose(stderr_log_fh);
|
|
||||||
ttyResetExit( &ttyOrig);
|
ttyResetExit( &ttyOrig);
|
||||||
if WIFEXITED(status) {
|
if WIFEXITED(status) {
|
||||||
return WEXITSTATUS(status);
|
return WEXITSTATUS(status);
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
*/
|
*/
|
||||||
int exec_pty(
|
int exec_pty(
|
||||||
std::string command,
|
std::string command,
|
||||||
std::string stdout_log_file,
|
FILE * stdout_log_fh,
|
||||||
std::string stderr_log_file,
|
FILE * stderr_log_fh,
|
||||||
bool context_override,
|
bool context_override,
|
||||||
std::string context_user,
|
std::string context_user,
|
||||||
std::string context_group,
|
std::string context_group,
|
||||||
|
|
|
@ -307,7 +307,7 @@ bool createDirectory(const std::string& path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Task::prepare_logs( std::string task_name, std::string logs_root, std::string timestamp )
|
bool Task::prepare_logs( std::string task_name, std::string logs_root )
|
||||||
{
|
{
|
||||||
std::string full_path = logs_root + "/" + task_name;
|
std::string full_path = logs_root + "/" + task_name;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -407,20 +407,25 @@ void Task::execute( Conf * configuration )
|
||||||
logs_root = configuration->get_project_root() + "/" + logs_root;
|
logs_root = configuration->get_project_root() + "/" + logs_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string timestamp = get_8601();
|
|
||||||
// set these first so the pre-execution logs get there.
|
// set these first so the pre-execution logs get there.
|
||||||
/*
|
/*
|
||||||
* create the logs dir here
|
* create the logs dir here
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (! this->prepare_logs( task_name, logs_root, timestamp ) )
|
if (! this->prepare_logs( task_name, logs_root ) )
|
||||||
{
|
{
|
||||||
throw TaskException("Could not prepare logs for task execution at '" + logs_root + "'.");
|
throw TaskException("Could not prepare logs for task execution at '" + logs_root + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string timestamp = get_8601();
|
||||||
std::string stdout_log_file = logs_root + "/" + task_name + "/" + timestamp + ".stdout.log";
|
std::string stdout_log_file = logs_root + "/" + task_name + "/" + timestamp + ".stdout.log";
|
||||||
std::string stderr_log_file = logs_root + "/" + task_name + "/" + timestamp + ".stderr.log";
|
std::string stderr_log_file = logs_root + "/" + task_name + "/" + timestamp + ".stderr.log";
|
||||||
|
|
||||||
|
// open file handles to the two log files we need to create for each execution
|
||||||
|
FILE * stdout_log_fh = fopen( stdout_log_file.c_str(), "a+" );
|
||||||
|
FILE * stderr_log_fh = fopen( stderr_log_file.c_str(), "a+" );
|
||||||
|
|
||||||
// check if working directory is to be set
|
// check if working directory is to be set
|
||||||
if ( override_working_dir )
|
if ( override_working_dir )
|
||||||
{
|
{
|
||||||
|
@ -443,8 +448,8 @@ void Task::execute( Conf * configuration )
|
||||||
|
|
||||||
int return_code = lcpex(
|
int return_code = lcpex(
|
||||||
command,
|
command,
|
||||||
stdout_log_file,
|
stdout_log_fh,
|
||||||
stderr_log_file,
|
stderr_log_fh,
|
||||||
set_user_context,
|
set_user_context,
|
||||||
user,
|
user,
|
||||||
group,
|
group,
|
||||||
|
@ -457,7 +462,6 @@ void Task::execute( Conf * configuration )
|
||||||
environment_file
|
environment_file
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// **********************************************
|
// **********************************************
|
||||||
// d[0] Error Code Check
|
// d[0] Error Code Check
|
||||||
// **********************************************
|
// **********************************************
|
||||||
|
@ -513,8 +517,8 @@ void Task::execute( Conf * configuration )
|
||||||
this->slog.log_task( E_INFO, task_name, "Executing rectification: " + rectifier + "." );
|
this->slog.log_task( E_INFO, task_name, "Executing rectification: " + rectifier + "." );
|
||||||
int rectifier_error = lcpex(
|
int rectifier_error = lcpex(
|
||||||
rectifier,
|
rectifier,
|
||||||
stdout_log_file,
|
stdout_log_fh,
|
||||||
stderr_log_file,
|
stderr_log_fh,
|
||||||
set_user_context,
|
set_user_context,
|
||||||
user,
|
user,
|
||||||
group,
|
group,
|
||||||
|
@ -565,8 +569,8 @@ void Task::execute( Conf * configuration )
|
||||||
|
|
||||||
int retry_code = lcpex(
|
int retry_code = lcpex(
|
||||||
command,
|
command,
|
||||||
stdout_log_file,
|
stdout_log_fh,
|
||||||
stderr_log_file,
|
stderr_log_fh,
|
||||||
set_user_context,
|
set_user_context,
|
||||||
user,
|
user,
|
||||||
group,
|
group,
|
||||||
|
@ -618,4 +622,7 @@ void Task::execute( Conf * configuration )
|
||||||
// end d[1] Rectify Check
|
// end d[1] Rectify Check
|
||||||
// **********************************************
|
// **********************************************
|
||||||
}
|
}
|
||||||
|
// close the log file handles
|
||||||
|
fclose(stdout_log_fh);
|
||||||
|
fclose(stderr_log_fh);
|
||||||
}
|
}
|
|
@ -47,7 +47,7 @@ class Task
|
||||||
// the readiness of this task to execute
|
// the readiness of this task to execute
|
||||||
bool defined;
|
bool defined;
|
||||||
|
|
||||||
bool prepare_logs( std::string task_name, std::string logs_root, std::string timestamp );
|
bool prepare_logs( std::string task_name, std::string logs_root );
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue