Skip to content

Commit

Permalink
Descriptive log for HID device open failure on Linux.
Browse files Browse the repository at this point in the history
Log a human readable message describing the reason why Chromium failed
to open a HID device node on Linux instead of the base::File error code.

BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278684 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
reillyg@chromium.org committed Jun 20, 2014
1 parent 5785622 commit 645947e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
17 changes: 9 additions & 8 deletions device/hid/hid_connection_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ HidConnectionLinux::HidConnectionLinux(HidDeviceInfo device_info,
base::File::Error file_error = device_file.error_details();

if (file_error == base::File::FILE_ERROR_ACCESS_DENIED) {
VLOG(1) << "Access denied opening device read-write, trying read-only.";

flags = base::File::FLAG_OPEN | base::File::FLAG_READ;

base::File device_file(base::FilePath(dev_node), flags);
if (!device_file.IsValid()) {
LOG(ERROR) << device_file.error_details();
return;
}
} else {
LOG(ERROR) << file_error;
return;
device_file = base::File(base::FilePath(dev_node), flags);
}
}
if (!device_file.IsValid()) {
LOG(ERROR) << "Failed to open '" << dev_node << "': "
<< base::File::ErrorToString(device_file.error_details());
return;
}

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.";
Expand Down
5 changes: 3 additions & 2 deletions device/hid/hid_service_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ void HidServiceLinux::OnDeviceAdded(udev_device* device) {

std::string dev_node;
if (!FindHidrawDevNode(device, &dev_node)) {
LOG(ERROR) << "Cannot open HID device as hidraw device.";
LOG(ERROR) << "Cannot find device node for HID device.";
return;
}

int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;

base::File device_file(base::FilePath(dev_node), flags);
if (!device_file.IsValid()) {
LOG(ERROR) << device_file.error_details();
LOG(ERROR) << "Cannot open '" << dev_node << "': "
<< base::File::ErrorToString(device_file.error_details());
return;
}

Expand Down

0 comments on commit 645947e

Please sign in to comment.