Loading cmds/dumpstate/dumpstate.cpp +62 −52 Original line number Diff line number Diff line Loading @@ -1162,7 +1162,6 @@ static void RunDumpsysNormal() { } static void DumpHals() { using android::sp; using android::hidl::manager::V1_0::IServiceManager; using android::hardware::defaultServiceManager; Loading Loading @@ -1507,15 +1506,10 @@ void Dumpstate::DumpstateBoard() { paths[i]))); } // Given that bugreport is required to diagnose failures, it's better to // drop the result of IDumpstateDevice than to block the rest of bugreport // for an arbitrary amount of time. std::packaged_task<std::unique_ptr<ssize_t[]>()> dumpstate_task([paths]() -> std::unique_ptr<ssize_t[]> { ::android::sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService()); sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService()); if (dumpstate_device == nullptr) { MYLOGE("No IDumpstateDevice implementation\n"); return nullptr; return; } using ScopedNativeHandle = Loading @@ -1527,7 +1521,7 @@ void Dumpstate::DumpstateBoard() { }); if (handle == nullptr) { MYLOGE("Could not create native_handle\n"); return nullptr; return; } for (size_t i = 0; i < paths.size(); i++) { Loading @@ -1538,16 +1532,44 @@ void Dumpstate::DumpstateBoard() { S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))); if (fd < 0) { MYLOGE("Could not open file %s: %s\n", paths[i].c_str(), strerror(errno)); return nullptr; return; } handle.get()->data[i] = fd.release(); } // Given that bugreport is required to diagnose failures, it's better to // set an arbitrary amount of timeout for IDumpstateDevice than to block the // rest of bugreport. In the timeout case, we will kill dumpstate board HAL // and grab whatever dumped std::packaged_task<bool()> dumpstate_task([paths, dumpstate_device, &handle]() -> bool { android::hardware::Return<void> status = dumpstate_device->dumpstateBoard(handle.get()); if (!status.isOk()) { MYLOGE("dumpstateBoard failed: %s\n", status.description().c_str()); return nullptr; return false; } return true; }); auto result = dumpstate_task.get_future(); std::thread(std::move(dumpstate_task)).detach(); constexpr size_t timeout_sec = 30; if (result.wait_for(std::chrono::seconds(timeout_sec)) != std::future_status::ready) { MYLOGE("dumpstateBoard timed out after %zus, killing dumpstate vendor HAL\n", timeout_sec); if (!android::base::SetProperty("ctl.interface_restart", android::base::StringPrintf("%s/default", IDumpstateDevice::descriptor))) { MYLOGE("Couldn't restart dumpstate HAL\n"); } } // Wait some time for init to kill dumpstate vendor HAL constexpr size_t killing_timeout_sec = 10; if (result.wait_for(std::chrono::seconds(killing_timeout_sec)) != std::future_status::ready) { MYLOGE("killing dumpstateBoard timed out after %zus, continue and " "there might be racing in content\n", killing_timeout_sec); } auto file_sizes = std::make_unique<ssize_t[]>(paths.size()); for (size_t i = 0; i < paths.size(); i++) { struct stat s; Loading @@ -1559,18 +1581,6 @@ void Dumpstate::DumpstateBoard() { } file_sizes[i] = s.st_size; } return file_sizes; }); auto result = dumpstate_task.get_future(); std::thread(std::move(dumpstate_task)).detach(); if (result.wait_for(30s) != std::future_status::ready) { MYLOGE("dumpstateBoard timed out after 30s\n"); return; } std::unique_ptr<ssize_t[]> file_sizes = result.get(); if (file_sizes == nullptr) { return; } for (size_t i = 0; i < paths.size(); i++) { if (file_sizes[i] == -1) { Loading Loading
cmds/dumpstate/dumpstate.cpp +62 −52 Original line number Diff line number Diff line Loading @@ -1162,7 +1162,6 @@ static void RunDumpsysNormal() { } static void DumpHals() { using android::sp; using android::hidl::manager::V1_0::IServiceManager; using android::hardware::defaultServiceManager; Loading Loading @@ -1507,15 +1506,10 @@ void Dumpstate::DumpstateBoard() { paths[i]))); } // Given that bugreport is required to diagnose failures, it's better to // drop the result of IDumpstateDevice than to block the rest of bugreport // for an arbitrary amount of time. std::packaged_task<std::unique_ptr<ssize_t[]>()> dumpstate_task([paths]() -> std::unique_ptr<ssize_t[]> { ::android::sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService()); sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService()); if (dumpstate_device == nullptr) { MYLOGE("No IDumpstateDevice implementation\n"); return nullptr; return; } using ScopedNativeHandle = Loading @@ -1527,7 +1521,7 @@ void Dumpstate::DumpstateBoard() { }); if (handle == nullptr) { MYLOGE("Could not create native_handle\n"); return nullptr; return; } for (size_t i = 0; i < paths.size(); i++) { Loading @@ -1538,16 +1532,44 @@ void Dumpstate::DumpstateBoard() { S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))); if (fd < 0) { MYLOGE("Could not open file %s: %s\n", paths[i].c_str(), strerror(errno)); return nullptr; return; } handle.get()->data[i] = fd.release(); } // Given that bugreport is required to diagnose failures, it's better to // set an arbitrary amount of timeout for IDumpstateDevice than to block the // rest of bugreport. In the timeout case, we will kill dumpstate board HAL // and grab whatever dumped std::packaged_task<bool()> dumpstate_task([paths, dumpstate_device, &handle]() -> bool { android::hardware::Return<void> status = dumpstate_device->dumpstateBoard(handle.get()); if (!status.isOk()) { MYLOGE("dumpstateBoard failed: %s\n", status.description().c_str()); return nullptr; return false; } return true; }); auto result = dumpstate_task.get_future(); std::thread(std::move(dumpstate_task)).detach(); constexpr size_t timeout_sec = 30; if (result.wait_for(std::chrono::seconds(timeout_sec)) != std::future_status::ready) { MYLOGE("dumpstateBoard timed out after %zus, killing dumpstate vendor HAL\n", timeout_sec); if (!android::base::SetProperty("ctl.interface_restart", android::base::StringPrintf("%s/default", IDumpstateDevice::descriptor))) { MYLOGE("Couldn't restart dumpstate HAL\n"); } } // Wait some time for init to kill dumpstate vendor HAL constexpr size_t killing_timeout_sec = 10; if (result.wait_for(std::chrono::seconds(killing_timeout_sec)) != std::future_status::ready) { MYLOGE("killing dumpstateBoard timed out after %zus, continue and " "there might be racing in content\n", killing_timeout_sec); } auto file_sizes = std::make_unique<ssize_t[]>(paths.size()); for (size_t i = 0; i < paths.size(); i++) { struct stat s; Loading @@ -1559,18 +1581,6 @@ void Dumpstate::DumpstateBoard() { } file_sizes[i] = s.st_size; } return file_sizes; }); auto result = dumpstate_task.get_future(); std::thread(std::move(dumpstate_task)).detach(); if (result.wait_for(30s) != std::future_status::ready) { MYLOGE("dumpstateBoard timed out after 30s\n"); return; } std::unique_ptr<ssize_t[]> file_sizes = result.get(); if (file_sizes == nullptr) { return; } for (size_t i = 0; i < paths.size(); i++) { if (file_sizes[i] == -1) { Loading