Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-core: Commit

system/core


Commit MetaInfo

Revisionba111389990113905e7a9a786a1ba0a96458e123 (tree)
Time2017-12-27 13:10:38
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

ueventd: load modules in the main process only

Loading modules in multiple processes is dangerous. It may cause
the system to hang.

Only handle uevents with modalias in the main process so that
all modules are loaded sequentially.

Change Summary

Incremental Difference

--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -379,7 +379,6 @@ void DeviceHandler::HandleDevice(const std::string& action, const std::string& d
379379
380380 void DeviceHandler::HandleDeviceEvent(const Uevent& uevent) {
381381 if (uevent.action == "add" || uevent.action == "change" || uevent.action == "online") {
382- LoadModule(uevent);
383382 FixupSysPermissions(uevent.path, uevent.subsystem);
384383 }
385384
@@ -426,28 +425,33 @@ void DeviceHandler::HandleDeviceEvent(const Uevent& uevent) {
426425 HandleDevice(uevent.action, devpath, block, uevent.major, uevent.minor, links);
427426 }
428427
429-void DeviceHandler::HandleModuleEvent(const Uevent& uevent, std::vector<std::string>& mod_queue)
428+void DeviceHandler::HandleModuleEvent(const Uevent& uevent, std::vector<std::string>* mod_queue)
430429 {
431430 if (!uevent.modalias.empty() && uevent.action == "add") {
432431 if (mod_aliases_.empty()) {
433432 ReadModulesDescFiles();
434433 }
435- for (auto& entry : deferred_mod_aliases_) {
436- if (!fnmatch(entry.first.c_str(), uevent.modalias.c_str(), 0)) {
437- mod_queue.emplace_back(entry.second);
434+ bool deferred = false;
435+ if (mod_queue) {
436+ for (auto& entry : deferred_mod_aliases_) {
437+ if (!fnmatch(entry.first.c_str(), uevent.modalias.c_str(), 0)) {
438+ mod_queue->emplace_back(entry.second);
439+ deferred = true;
440+ }
438441 }
439442 }
443+ if (!deferred) {
444+ LoadModule(uevent);
445+ }
440446 }
441447 }
442448
443449 bool DeviceHandler::LoadModule(const Uevent& uevent) const
444450 {
445451 bool ret = false;
446- if (!uevent.modalias.empty()) {
447- for (auto& entry : mod_aliases_) {
448- if (!fnmatch(entry.first.c_str(), uevent.modalias.c_str(), 0)) {
449- ret |= LoadModule(entry.second);
450- }
452+ for (auto& entry : mod_aliases_) {
453+ if (!fnmatch(entry.first.c_str(), uevent.modalias.c_str(), 0)) {
454+ ret |= LoadModule(entry.second);
451455 }
452456 }
453457 return ret;
--- a/init/devices.h
+++ b/init/devices.h
@@ -108,7 +108,7 @@ class DeviceHandler {
108108 ~DeviceHandler(){};
109109
110110 void HandleDeviceEvent(const Uevent& uevent);
111- void HandleModuleEvent(const Uevent& uevent, std::vector<std::string>& mod_queue);
111+ void HandleModuleEvent(const Uevent& uevent, std::vector<std::string>* mod_queue = nullptr);
112112 bool LoadModule(const Uevent& uevent) const;
113113 bool LoadModule(const std::string& mod) const;
114114 void ReadModulesDescFiles();
--- a/init/ueventd.cpp
+++ b/init/ueventd.cpp
@@ -141,7 +141,7 @@ void ColdBoot::UeventHandlerMain(unsigned int process_num, unsigned int total_pr
141141 void ColdBoot::RegenerateUevents() {
142142 uevent_listener_.RegenerateUevents([this](const Uevent& uevent) {
143143 HandleFirmwareEvent(uevent);
144- device_handler_.HandleModuleEvent(uevent, mod_queue_);
144+ device_handler_.HandleModuleEvent(uevent, &mod_queue_);
145145 uevent_queue_.emplace_back(std::move(uevent));
146146 return ListenerAction::kContinue;
147147 });
@@ -285,6 +285,7 @@ int ueventd_main(int argc, char** argv) {
285285
286286 uevent_listener.Poll([&device_handler](const Uevent& uevent) {
287287 HandleFirmwareEvent(uevent);
288+ device_handler.HandleModuleEvent(uevent);
288289 device_handler.HandleDeviceEvent(uevent);
289290 return ListenerAction::kContinue;
290291 });
Show on old repository browser