From 004addd2b45e131567fb0e278cdca32cd41fa4ef Mon Sep 17 00:00:00 2001 From: phanes Date: Thu, 16 Feb 2023 03:49:56 -0500 Subject: [PATCH] error handling for log file handle --- src/config/Config.cpp | 10 ++++++++++ src/lcpex/vpty/libclpex_tty.cpp | 10 ++++++++++ src/suite/Suite.cpp | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/config/Config.cpp b/src/config/Config.cpp index 7dd3c1f..dc87759 100644 --- a/src/config/Config.cpp +++ b/src/config/Config.cpp @@ -134,6 +134,12 @@ void Conf::set_object_b(std::string keyname, bool & object_member, std::string f this->slog.log_task( E_DEBUG, "SET_PROPERTY", "'" + keyname + "' " + std::to_string(object_member)); } +void removeTrailingSlash(std::string &str) { + if (!str.empty() && str.back() == '/') { + str.pop_back(); + } +} + /** * @brief Prepend the project root to a relative path * @@ -147,6 +153,7 @@ void Conf::set_object_b(std::string keyname, bool & object_member, std::string f */ std::string Conf::prepend_project_root( std::string relative_path) { + removeTrailingSlash(relative_path); return this->project_root + "/" + relative_path; } @@ -259,6 +266,7 @@ Shell Conf::get_shell_by_name( std::string name ) { } + /** * @class Conf * @brief Loads the configuration for the application @@ -301,6 +309,8 @@ Conf::Conf(std::string filename, int LOG_LEVEL ): JSON_Loader(LOG_LEVEL ), slog( // convert to an absolute path after all the interpolation is done. this->project_root = get_absolute_path( this->project_root ); + + // all other paths are relative to project_root set_object_s_derivedpath( "units_path", this->units_path, filename ); set_object_s_derivedpath( "logs_path", this->logs_path, filename ); diff --git a/src/lcpex/vpty/libclpex_tty.cpp b/src/lcpex/vpty/libclpex_tty.cpp index b340b4f..027e313 100644 --- a/src/lcpex/vpty/libclpex_tty.cpp +++ b/src/lcpex/vpty/libclpex_tty.cpp @@ -118,6 +118,16 @@ int exec_pty( 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 ) { + safe_perror( "Error opening STDOUT log file. Aborting.", &ttyOrig ); + exit( 1 ); + } + if ( stderr_log_fh == NULL ) { + safe_perror( "Error opening STDERR log file. Aborting.", &ttyOrig ); + exit( 1 ); + } + + // create the pipes for the child process to write and read from using its stderr int fd_child_stderr_pipe[2]; diff --git a/src/suite/Suite.cpp b/src/suite/Suite.cpp index 1aa3349..b3de92b 100644 --- a/src/suite/Suite.cpp +++ b/src/suite/Suite.cpp @@ -129,7 +129,7 @@ void Suite::get_units_from_dir( std::vector * files, std::string pa // you want here. Something like: if ( strstr( hFile->d_name, ".units" )) { - std::string full_path = path + hFile->d_name; + std::string full_path = path + "/" + hFile->d_name; files->push_back( full_path ); } }