From 5fb5b34f5c2f5d0a3210708c04779367b1072c32 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 4 Jan 2023 15:25:40 +0100 Subject: Adjust to new lib API --- tests/test-webserver.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/test-webserver.cpp') diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp index 4ac550e..7826a58 100644 --- a/tests/test-webserver.cpp +++ b/tests/test-webserver.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -33,6 +35,7 @@ using namespace std::string_literals; namespace fs = std::filesystem; namespace pt = boost::property_tree; +using namespace Reichwein; class WebserverProcess { @@ -118,6 +121,28 @@ public: m_pid = 0; } + bool isRunning() + { + if (m_pid == 0) + return false; + + fs::path pid_file{fmt::format("/proc/{}/stat", m_pid)}; + if (!fs::exists(pid_file)) + return false; + + std::string s{File::getFile(pid_file)}; + + auto pos0{s.find(' ', 0)}; + pos0 = s.find(' ', pos0 + 1); + pos0++; + + auto pos1{s.find(' ', pos0 + 1)}; + + std::string state{s.substr(pos0, pos1 - pos0)}; + + return state == "R" || state == "S"; + } + private: pid_t m_pid; }; -- cgit v1.2.3