Moved Process helper functions to service class

This commit is contained in:
Nav
2022-12-26 21:35:24 +00:00
parent d353b55f9b
commit 4c25c85c36
7 changed files with 60 additions and 24 deletions

View File

@@ -6,7 +6,7 @@
#include "Responses/Error.hpp"
#include "src/Helpers/Process.hpp"
#include "src/Services/ProcessService.hpp"
#include "src/Logger/Logger.hpp"
#include "src/TargetController/Exceptions/DeviceFailure.hpp"
@@ -439,6 +439,40 @@ namespace Bloom::TargetController
TargetControllerComponent::responsesByCommandIdCv.notify_all();
}
<<<<<<< HEAD
=======
void TargetControllerComponent::checkUdevRules() {
auto bloomRulesPath = std::string("/etc/udev/rules.d/99-bloom.rules");
auto latestBloomRulesPath = Paths::resourcesDirPath() + "/UDevRules/99-bloom.rules";
if (!std::filesystem::exists(bloomRulesPath)) {
Logger::warning("Bloom udev rules missing - attempting installation");
// We can only install them if we're running as root
if (!Services::ProcessService::isRunningAsRoot()) {
Logger::error("Bloom udev rules missing - cannot install udev rules without root privileges.\n"
"Running Bloom once with root privileges will allow it to automatically install the udev rules. "
"Alternatively, instructions on manually installing the udev rules can be found "
"here: " + Paths::homeDomainName() + "/docs/getting-started\nBloom may fail to connect to some "
"debug tools until this is resolved.");
return;
}
if (!std::filesystem::exists(latestBloomRulesPath)) {
// This shouldn't happen, but it can if someone has been messing with the installation files
Logger::error(
"Unable to install Bloom udev rules - \"" + latestBloomRulesPath + "\" does not exist."
);
return;
}
std::filesystem::copy(latestBloomRulesPath, bloomRulesPath);
Logger::warning("Bloom udev rules installed - a reconnect of the debug tool may be required "
"before the new udev rules come into effect.");
}
}
>>>>>>> b5402709 (Moved Process helper functions to service class)
void TargetControllerComponent::shutdown() {
if (this->getThreadState() == ThreadState::STOPPED) {
return;