Fix race condition is commitCheckpoint

If cp_commitCheckpoint is called twice at the same time, the second call
to setBowState will fail.

Add lock to remove possibility, and protect all uses of isCheckpointing

Bug: 138952436
Test: Boots after flashing in checkpoint mode
Change-Id: I131298adc506c3c176774d15e642b13d5f991087
This commit is contained in:
Paul Lawrence 2019-08-22 09:51:18 -07:00
parent 5bcfb5bf45
commit 1d57f686a3

View file

@ -144,9 +144,15 @@ Status cp_startCheckpoint(int retry) {
namespace {
volatile bool isCheckpointing = false;
// Protects isCheckpointing and code that makes decisions based on status of
// isCheckpointing
std::mutex isCheckpointingLock;
}
Status cp_commitChanges() {
std::lock_guard<std::mutex> lock(isCheckpointingLock);
if (!isCheckpointing) {
return Status::ok();
}
@ -261,6 +267,7 @@ bool cp_needsCheckpoint() {
std::string content;
sp<IBootControl> module = IBootControl::getService();
std::lock_guard<std::mutex> lock(isCheckpointingLock);
if (isCheckpointing) return isCheckpointing;
if (module && module->isSlotMarkedSuccessful(module->getCurrentSlot()) == BoolResult::FALSE) {
@ -330,6 +337,7 @@ static void cp_healthDaemon(std::string mnt_pnt, std::string blk_device, bool is
} // namespace
Status cp_prepareCheckpoint() {
std::lock_guard<std::mutex> lock(isCheckpointingLock);
if (!isCheckpointing) {
return Status::ok();
}