enh(ProcessRunner): does not detect launch errors #4482 (#4483)

* enh(ProcessRunner): does not detect launch errors #4482

* enh(File): add absolutePath and existsAnywhere() #4482

* fix windows build and tsan fail

* fix tsan

* fix windows file tests

* comment out some CI env path -related issues

* fix tsan and windows build

* try to fix ci

* ignore ProcessRunner test fail on windows cmake

* enh(File): canExecute throws FileNotFoundException if the file to be executed can't be found in the path.

* Few C++ modernisation changes.

* enh(File): Windows specifics of File::canExecute. Returns false if the file to be executed can't be found using absolutePath.

---------

Co-authored-by: Matej Kenda <matejken@gmail.com>
This commit is contained in:
Aleksandar Fabijanic
2024-07-29 13:16:18 -05:00
committed by GitHub
parent f24547cdcf
commit 3656f069e1
20 changed files with 361 additions and 37 deletions

View File

@@ -121,6 +121,8 @@ public:
int runCount() const;
/// Returns the number of times the process has been executed.
const std::string& error() const;
/// Returns the error message.
private:
static const Poco::ProcessHandle::PID INVALID_PID = -1;
@@ -141,10 +143,23 @@ private:
/// Process initialization completion is indicated by new pid in
/// the pid file. If pid file is not specified, there is no waiting.
void checkTimeout(const Poco::Stopwatch& sw, const std::string& msg);
void checkError();
/// If timeout is exceeded, throws TimeoutException with `msg`
/// message.
void checkTimeout(const std::string& msg);
/// If timeout is exceeded, throws TimeoutException with `msg`
/// message.
void checkStatus(const std::string& msg, bool tOut = true);
/// If there were andy errors during process start/stop,
/// throws RuntimeException with the error message;
/// otherwise, if tOut is true and timeout is exceeded, throws
/// TimeoutException with `msg` message.
void setError(const std::string& msg);
/// Sets the error message.
Poco::Thread _t;
std::string _cmd;
Args _args;
@@ -156,6 +171,9 @@ private:
std::atomic<bool> _started;
std::atomic<int> _rc;
std::atomic<int> _runCount;
Stopwatch _sw;
std::string _error;
mutable Poco::FastMutex _mutex;
};
@@ -193,6 +211,20 @@ inline int ProcessRunner::runCount() const
}
inline void ProcessRunner::setError(const std::string& msg)
{
_error = Poco::format("ProcessRunner(%s): %s", cmdLine(), msg);
}
inline const std::string& ProcessRunner::error() const
{
Poco::FastMutex::ScopedLock l(_mutex);
return _error;
}
} // namespace Poco