From 0d3277b8cf6d9a668c8cf9a69c40c152b71de66d Mon Sep 17 00:00:00 2001 From: "reillyg@chromium.org" Date: Sat, 21 Jun 2014 02:20:42 +0000 Subject: [PATCH] Log errors in Linux HID from read, write and ioctl calls. 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 --- device/hid/hid_connection_linux.cc | 16 +++++++++++----- device/hid/hid_service_linux.cc | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/device/hid/hid_connection_linux.cc b/device/hid/hid_connection_linux.cc index 425d88fa35cd83..331e3f30856ade 100644 --- a/device/hid/hid_connection_linux.cc +++ b/device/hid/hid_connection_linux.cc @@ -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(); @@ -103,6 +103,7 @@ void HidConnectionLinux::OnFileCanReadWithoutBlocking(int fd) { if (errno == EAGAIN) { return; } + VPLOG(1) << "Read failed"; Disconnect(); return; } @@ -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 { @@ -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( @@ -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() { diff --git a/device/hid/hid_service_linux.cc b/device/hid/hid_service_linux.cc index 5257dcd874a5a4..70335016e68f24 100644 --- a/device/hid/hid_service_linux.cc +++ b/device/hid/hid_service_linux.cc @@ -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; } @@ -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; }