Drop udev in favor of static paths.
Change-Id: I4f24b00e7bff340da2f6a0a1e511a004b1b1085c
(cherry picked from commit 95c09fec3d0afa261cdf69dec2a4de9f1237163c)
diff --git a/host/vadb/usbip/BUILD b/host/vadb/usbip/BUILD
index dcbd6fc..d1594b1 100644
--- a/host/vadb/usbip/BUILD
+++ b/host/vadb/usbip/BUILD
@@ -25,9 +25,6 @@
"@gflags_repo//:gflags",
"@glog_repo//:glog",
],
- linkopts = [
- "-ludev",
- ],
visibility = [ "//visibility:public" ]
)
diff --git a/host/vadb/usbip/vhci_instrument.cpp b/host/vadb/usbip/vhci_instrument.cpp
index 8fb2600..8f484f2 100644
--- a/host/vadb/usbip/vhci_instrument.cpp
+++ b/host/vadb/usbip/vhci_instrument.cpp
@@ -51,10 +51,10 @@
constexpr uint32_t kDefaultDeviceSpeed = 3;
// Subsystem and device type where VHCI driver is located.
-// These values can usually be found after loading vhci-hcd module here:
-// /sys/devices/platform/vhci_hcd/modalias
-constexpr char kVHCISubsystem[] = "platform";
-constexpr char kVHCIDevType[] = "vhci_hcd";
+const char* const kVHCIPlatformPaths[] = {
+ "/sys/devices/platform/vhci_hcd",
+ "/sys/devices/platform/vhci_hcd.1",
+};
// Control messages.
// Attach tells thread to attach remote device.
@@ -78,10 +78,7 @@
} // anonymous namespace
VHCIInstrument::VHCIInstrument(const std::string& name)
- : udev_(nullptr, [](udev* u) { udev_unref(u); }),
- vhci_device_(nullptr,
- [](udev_device* device) { udev_device_unref(device); }),
- name_(name) {}
+ : name_(name) {}
VHCIInstrument::~VHCIInstrument() {
control_write_end_->Write(&kControlExit, sizeof(kControlExit));
@@ -91,20 +88,21 @@
bool VHCIInstrument::Init() {
avd::SharedFD::Pipe(&control_read_end_, &control_write_end_);
- udev_.reset(udev_new());
- CHECK(udev_) << "Could not create libudev context.";
+ struct stat buf;
+ for (const auto* path : kVHCIPlatformPaths) {
+ if (stat(path, &buf) == 0) {
+ syspath_ = path;
+ break;
+ }
+ }
- vhci_device_.reset(udev_device_new_from_subsystem_sysname(
- udev_.get(), kVHCISubsystem, kVHCIDevType));
- if (!vhci_device_) {
+ if (syspath_.empty()) {
LOG(ERROR) << "VHCI not available. Is the driver loaded?";
LOG(ERROR) << "Try: sudo modprobe vhci_hcd";
LOG(ERROR) << "The driver is part of linux-image-extra-`uname -r` package";
return false;
}
- syspath_ = udev_device_get_syspath(vhci_device_.get());
-
if (!FindFreePort()) {
LOG(ERROR) << "It appears all your VHCI ports are currently occupied.";
LOG(ERROR) << "New VHCI device cannot be registered unless one of the "
diff --git a/host/vadb/usbip/vhci_instrument.h b/host/vadb/usbip/vhci_instrument.h
index 7f54cde..9fa5ece 100644
--- a/host/vadb/usbip/vhci_instrument.h
+++ b/host/vadb/usbip/vhci_instrument.h
@@ -19,8 +19,6 @@
#include <string>
#include <thread>
-#include <libudev.h>
-
#include "common/libs/fs/shared_fd.h"
namespace vadb {
@@ -59,8 +57,6 @@
bool FindFreePort();
private:
- std::unique_ptr<udev, void(*)(udev*)> udev_;
- std::unique_ptr<udev_device, void(*)(udev_device*)> vhci_device_;
std::string name_;
std::unique_ptr<std::thread> attach_thread_;
std::string syspath_;