Fix crashes when logid starts as root

If logid scans every device, it will either SIGSEGV or not work at all.
This commit should fix bug #100.
This commit is contained in:
pixl
2020-07-13 01:14:15 -04:00
parent 8f073d66c3
commit dde2993223
5 changed files with 119 additions and 41 deletions

View File

@@ -19,6 +19,8 @@
#include "DeviceMonitor.h"
#include "../../util/task.h"
#include "../../util/log.h"
#include "RawDevice.h"
#include "../hidpp/Device.h"
#include <thread>
#include <system_error>
@@ -99,10 +101,16 @@ void DeviceMonitor::run()
if (action == "add")
task::spawn([this, name=devnode]() {
this->addDevice(name);
auto supported_reports = backend::hidpp::getSupportedReports(
RawDevice::getReportDescriptor(name));
if(supported_reports)
this->addDevice(name);
else
logPrintf(DEBUG, "Unsupported device %s ignored",
name.c_str());
}, [name=devnode](std::exception& e){
logPrintf(WARN, "Error adding device %s: %s",
name.c_str(), e.what());
name.c_str(), e.what());
});
else if (action == "remove")
task::spawn([this, name=devnode]() {
@@ -158,10 +166,16 @@ void DeviceMonitor::enumerate()
udev_device_unref(device);
task::spawn([this, name=devnode]() {
this->addDevice(name);
auto supported_reports = backend::hidpp::getSupportedReports(
RawDevice::getReportDescriptor(name));
if(supported_reports)
this->addDevice(name);
else
logPrintf(DEBUG, "Unsupported device %s ignored",
name.c_str());
}, [name=devnode](std::exception& e){
logPrintf(WARN, "Error adding device %s: %s",
name.c_str(), e.what());
name.c_str(), e.what());
});
}