Binned udev rule check in TargetController
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
#include "TargetControllerComponent.hpp"
|
||||
|
||||
#include <thread>
|
||||
#include <filesystem>
|
||||
#include <typeindex>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Responses/Error.hpp"
|
||||
|
||||
#include "src/Helpers/Paths.hpp"
|
||||
#include "src/Helpers/Process.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
@@ -169,9 +167,6 @@ namespace Bloom::TargetController
|
||||
this->eventListener->setInterruptEventNotifier(&TargetControllerComponent::notifier);
|
||||
EventManager::registerListener(this->eventListener);
|
||||
|
||||
// Install Bloom's udev rules if not already installed
|
||||
TargetControllerComponent::checkUdevRules();
|
||||
|
||||
// Register command handlers
|
||||
this->registerCommandHandler<GetState>(
|
||||
std::bind(&TargetControllerComponent::handleGetState, this, std::placeholders::_1)
|
||||
@@ -444,37 +439,6 @@ namespace Bloom::TargetController
|
||||
TargetControllerComponent::responsesByCommandIdCv.notify_all();
|
||||
}
|
||||
|
||||
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 (!Process::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.");
|
||||
}
|
||||
}
|
||||
|
||||
void TargetControllerComponent::shutdown() {
|
||||
if (this->getThreadState() == ThreadState::STOPPED) {
|
||||
return;
|
||||
|
||||
@@ -234,13 +234,6 @@ namespace Bloom::TargetController
|
||||
*/
|
||||
void registerCommandResponse(Commands::CommandIdType commandId, std::unique_ptr<Responses::Response> response);
|
||||
|
||||
/**
|
||||
* Installs Bloom's udev rules on user's machine. Rules are copied from build/Distribution/Resources/UdevRules
|
||||
* to /etc/udev/rules.d/. This method will report an error if Bloom isn't running as root (as root privileges
|
||||
* are required for writing to files in /etc/udev).
|
||||
*/
|
||||
static void checkUdevRules();
|
||||
|
||||
/**
|
||||
* Exit point - must be called before the TargetController thread is terminated.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user