g13d: Handle errors in writes

The original code was just throwing away error conditions for write calls to an
fd. Obviously this is bad, but really, we should probably be using an ostream
instead of a raw file handle here. For now, deal with the warning by checking
the result for errors, at least, and later we'll refactor to use ostream
properly.
This commit is contained in:
June Tate-Gans 2021-04-25 14:29:40 -05:00
parent 516423ae16
commit ae055495cc

View File

@ -32,11 +32,22 @@ void G13_Device::send_event(int type, int code, int val) {
_event.type = type; _event.type = type;
_event.code = code; _event.code = code;
_event.value = val; _event.value = val;
write(_uinput_fid, &_event, sizeof(_event));
// TODO(jtgans): Make this actually verify it writes all bytes
auto result = write(_uinput_fid, &_event, sizeof(_event));
if (result < 0) {
G13_LOG(error, "Unable to send event: " << strerror(errno));
exit(1);
}
} }
void G13_Device::write_output_pipe(const std::string &out) { void G13_Device::write_output_pipe(const std::string &out) {
write(_output_pipe_fid, out.c_str(), out.size()); // TODO(jtgans): Make this actually verify it writes all bytes
auto result = write(_output_pipe_fid, out.c_str(), out.size());
if (result < 0) {
G13_LOG(error, "Unable to write to output pipe: " << strerror(errno));
exit(1);
}
} }
void G13_Device::set_mode_leds(int leds) { void G13_Device::set_mode_leds(int leds) {