Skip to content

Commit

Permalink
Log errors in Linux HID from read, write and ioctl calls.
Browse files Browse the repository at this point in the history
Log human readable descriptions of the errors generated by system calls
executed on Linux against HID devices.

BUG=

Review URL: https://codereview.chromium.org/348733002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278899 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
reillyg@chromium.org committed Jun 21, 2014
1 parent 4372da5 commit 0d3277b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions device/hid/hid_connection_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ HidConnectionLinux::HidConnectionLinux(HidDeviceInfo device_info,

if (fcntl(device_file.GetPlatformFile(), F_SETFL,
fcntl(device_file.GetPlatformFile(), F_GETFL) | O_NONBLOCK)) {
PLOG(ERROR) << "Failed to set non-blocking flag to device file.";
PLOG(ERROR) << "Failed to set non-blocking flag to device file";
return;
}
device_file_ = device_file.Pass();
Expand Down Expand Up @@ -103,6 +103,7 @@ void HidConnectionLinux::OnFileCanReadWithoutBlocking(int fd) {
if (errno == EAGAIN) {
return;
}
VPLOG(1) << "Read failed";
Disconnect();
return;
}
Expand Down Expand Up @@ -147,6 +148,7 @@ void HidConnectionLinux::Write(uint8_t report_id,
int bytes_written = HANDLE_EINTR(
write(device_file_.GetPlatformFile(), buffer->data(), buffer->size()));
if (bytes_written < 0) {
VPLOG(1) << "Write failed";
Disconnect();
callback.Run(false, 0);
} else {
Expand All @@ -170,10 +172,12 @@ void HidConnectionLinux::GetFeatureReport(
int result = ioctl(device_file_.GetPlatformFile(),
HIDIOCGFEATURE(buffer->size()),
buffer->data());
if (result < 0)
if (result < 0) {
VPLOG(1) << "Failed to get feature report";
callback.Run(false, 0);
else
} else {
callback.Run(true, result);
}
}

void HidConnectionLinux::SendFeatureReport(
Expand All @@ -186,10 +190,12 @@ void HidConnectionLinux::SendFeatureReport(
int result = ioctl(device_file_.GetPlatformFile(),
HIDIOCSFEATURE(buffer->size()),
buffer->data());
if (result < 0)
if (result < 0) {
VPLOG(1) << "Failed to send feature report";
callback.Run(false, 0);
else
} else {
callback.Run(true, result);
}
}

void HidConnectionLinux::ProcessReadQueue() {
Expand Down
4 changes: 2 additions & 2 deletions device/hid/hid_service_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void HidServiceLinux::OnDeviceAdded(udev_device* device) {
int desc_size = 0;
int res = ioctl(device_file.GetPlatformFile(), HIDIOCGRDESCSIZE, &desc_size);
if (res < 0) {
LOG(ERROR) << "HIDIOCGRDESCSIZE failed.";
PLOG(ERROR) << "Failed to get report descriptor size";
device_file.Close();
return;
}
Expand All @@ -140,7 +140,7 @@ void HidServiceLinux::OnDeviceAdded(udev_device* device) {

res = ioctl(device_file.GetPlatformFile(), HIDIOCGRDESC, &rpt_desc);
if (res < 0) {
LOG(ERROR) << "HIDIOCGRDESC failed.";
PLOG(ERROR) << "Failed to get report descriptor";
device_file.Close();
return;
}
Expand Down

0 comments on commit 0d3277b

Please sign in to comment.