diff options
author | Tom Cherry <tomcherry@google.com> | 2017-08-17 09:38:01 -0700 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2017-08-18 10:39:48 -0700 |
commit | 9c8d6dd7de6e436542d40ae1cd635ce13b89162f (patch) | |
tree | 92480644743d31364a759dfe4965cf9c8cedb2a9 | |
parent | 334929b525370a8a008b276e81e7ba573af7808f (diff) | |
download | system_core-9c8d6dd7de6e436542d40ae1cd635ce13b89162f.tar.gz system_core-9c8d6dd7de6e436542d40ae1cd635ce13b89162f.tar.bz2 system_core-9c8d6dd7de6e436542d40ae1cd635ce13b89162f.zip |
ueventd: fix subsystem list logic issues
1) Check subsystems list before doing usb subsystem logic. This allows
developers to handle usb* subsystems in ueventd.rc files.
2) Fix a bug where each subsystem_ instance is not reinitialized, but
rather only the name_ member was set.
Test: boot bullhead
Test: check that multiple uevent_devname subsystems work when
specified in ueventd.rc
Change-Id: Ifcac04763afcaf72a3b14ef5f3a6cb89981b51a1
-rw-r--r-- | init/devices.cpp | 30 | ||||
-rw-r--r-- | init/devices.h | 1 | ||||
-rw-r--r-- | init/ueventd_parser.cpp | 2 |
3 files changed, 16 insertions, 17 deletions
diff --git a/init/devices.cpp b/init/devices.cpp index d59f53c74..af6b50acb 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -386,26 +386,24 @@ void DeviceHandler::HandleDeviceEvent(const Uevent& uevent) { if (StartsWith(uevent.path, "/devices")) { links = GetBlockDeviceSymlinks(uevent); } - } else if (StartsWith(uevent.subsystem, "usb")) { - if (uevent.subsystem == "usb") { - if (!uevent.device_name.empty()) { - devpath = "/dev/" + uevent.device_name; - } else { - // This imitates the file system that would be created - // if we were using devfs instead. - // Minors are broken up into groups of 128, starting at "001" - int bus_id = uevent.minor / 128 + 1; - int device_id = uevent.minor % 128 + 1; - devpath = StringPrintf("/dev/bus/usb/%03d/%03d", bus_id, device_id); - } - } else { - // ignore other USB events - return; - } } else if (const auto subsystem = std::find(subsystems_.cbegin(), subsystems_.cend(), uevent.subsystem); subsystem != subsystems_.cend()) { devpath = subsystem->ParseDevPath(uevent); + } else if (uevent.subsystem == "usb") { + if (!uevent.device_name.empty()) { + devpath = "/dev/" + uevent.device_name; + } else { + // This imitates the file system that would be created + // if we were using devfs instead. + // Minors are broken up into groups of 128, starting at "001" + int bus_id = uevent.minor / 128 + 1; + int device_id = uevent.minor % 128 + 1; + devpath = StringPrintf("/dev/bus/usb/%03d/%03d", bus_id, device_id); + } + } else if (StartsWith(uevent.subsystem, "usb")) { + // ignore other USB events + return; } else { devpath = "/dev/" + Basename(uevent.path); } diff --git a/init/devices.h b/init/devices.h index dd44337dc..1f8f1e8a9 100644 --- a/init/devices.h +++ b/init/devices.h @@ -72,6 +72,7 @@ class Subsystem { friend class SubsystemParser; Subsystem() {} + Subsystem(std::string name) : name_(std::move(name)) {} // Returns the full path for a uevent of a device that is a member of this subsystem, // according to the rules parsed from ueventd.rc diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp index e831b8b63..cd7adb433 100644 --- a/init/ueventd_parser.cpp +++ b/init/ueventd_parser.cpp @@ -82,7 +82,7 @@ Result<Success> SubsystemParser::ParseSection(std::vector<std::string>&& args, return Error() << "ignoring duplicate subsystem entry"; } - subsystem_.name_ = args[1]; + subsystem_ = Subsystem(std::move(args[1])); return Success(); } |