diff --git a/src/logid/backend/raw/RawDevice.cpp b/src/logid/backend/raw/RawDevice.cpp index be5ece5..917745e 100644 --- a/src/logid/backend/raw/RawDevice.cpp +++ b/src/logid/backend/raw/RawDevice.cpp @@ -208,6 +208,7 @@ std::vector RawDevice::_respondToReport int RawDevice::_sendReport(const std::vector& report) { + std::lock_guard lock(dev_io); if(logid::global_verbosity == LogLevel::RAWREPORT) { printf("[RAWREPORT] %s OUT: ", path.c_str()); for(auto &i : report) @@ -217,11 +218,15 @@ int RawDevice::_sendReport(const std::vector& report) assert(supportedReport(report[0], report.size())); - std::lock_guard lock(dev_io); int ret = ::write(fd, report.data(), report.size()); - if(ret == -1) - throw std::system_error(errno, std::system_category(), - "_sendReport write failed"); + if(ret == -1) { + ///TODO: This seems like a hacky solution + // Try again before failing + ret = ::write(fd, report.data(), report.size()); + if(ret == -1) + throw std::system_error(errno, std::system_category(), + "_sendReport write failed"); + } return ret; }