Amin Hassani | 0882a51 | 2018-04-05 16:25:44 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2018 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #include "update_engine/update_boot_flags_action.h" |
| 18 | |
| 19 | #include <base/bind.h> |
| 20 | #include <base/logging.h> |
| 21 | |
| 22 | #include "update_engine/common/boot_control.h" |
| 23 | |
| 24 | namespace chromeos_update_engine { |
| 25 | |
| 26 | bool UpdateBootFlagsAction::updated_boot_flags_ = false; |
| 27 | bool UpdateBootFlagsAction::is_running_ = false; |
| 28 | |
| 29 | void UpdateBootFlagsAction::PerformAction() { |
| 30 | if (is_running_) { |
| 31 | LOG(INFO) << "Update boot flags running, nothing to do."; |
| 32 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
| 33 | return; |
| 34 | } |
| 35 | if (updated_boot_flags_) { |
| 36 | LOG(INFO) << "Already updated boot flags. Skipping."; |
| 37 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | // This is purely best effort. Failures should be logged by Subprocess. Run |
| 42 | // the script asynchronously to avoid blocking the event loop regardless of |
| 43 | // the script runtime. |
| 44 | is_running_ = true; |
| 45 | LOG(INFO) << "Marking booted slot as good."; |
| 46 | if (!boot_control_->MarkBootSuccessfulAsync( |
| 47 | base::Bind(&UpdateBootFlagsAction::CompleteUpdateBootFlags, |
| 48 | base::Unretained(this)))) { |
| 49 | CompleteUpdateBootFlags(false); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | void UpdateBootFlagsAction::CompleteUpdateBootFlags(bool successful) { |
| 54 | is_running_ = false; |
| 55 | if (!successful) { |
| 56 | // We ignore the failure for now because if the updating boot flags is flaky |
| 57 | // or has a bug in a specific release, then blocking the update can cause |
| 58 | // devices to stay behind even though we could have updated the system and |
| 59 | // fixed the issue regardless of this failure. |
| 60 | // |
| 61 | // TODO(ahassani): Add new error code metric for kUpdateBootFlagsFailed. |
| 62 | LOG(ERROR) << "Updating boot flags failed, but ignoring its failure."; |
| 63 | } |
| 64 | updated_boot_flags_ = true; |
| 65 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
| 66 | } |
| 67 | |
| 68 | } // namespace chromeos_update_engine |