diff options
| author | Roland Reichwein <mail@reichwein.it> | 2023-01-04 15:25:40 +0100 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2023-01-04 15:25:40 +0100 | 
| commit | 5fb5b34f5c2f5d0a3210708c04779367b1072c32 (patch) | |
| tree | 4c79a1cbb4c0f3b35db12b43c9262d7baf2a70be /tests | |
| parent | 14624e39aff9239d5f016af1c0553483c856555b (diff) | |
Adjust to new lib API
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-webserver.cpp | 25 | 
1 files changed, 25 insertions, 0 deletions
| 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 <boost/property_tree/ptree.hpp>  #include <boost/property_tree/xml_parser.hpp> +#include <fmt/core.h> +  #include <chrono>  #include <filesystem>  #include <iostream> @@ -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;  }; | 
