update_boot_flags_action.cc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "update_engine/update_boot_flags_action.h"
  17. #include <base/bind.h>
  18. #include <base/logging.h>
  19. #include "update_engine/common/boot_control.h"
  20. namespace chromeos_update_engine {
  21. bool UpdateBootFlagsAction::updated_boot_flags_ = false;
  22. bool UpdateBootFlagsAction::is_running_ = false;
  23. void UpdateBootFlagsAction::PerformAction() {
  24. if (is_running_) {
  25. LOG(INFO) << "Update boot flags running, nothing to do.";
  26. processor_->ActionComplete(this, ErrorCode::kSuccess);
  27. return;
  28. }
  29. if (updated_boot_flags_) {
  30. LOG(INFO) << "Already updated boot flags. Skipping.";
  31. processor_->ActionComplete(this, ErrorCode::kSuccess);
  32. return;
  33. }
  34. // This is purely best effort. Failures should be logged by Subprocess. Run
  35. // the script asynchronously to avoid blocking the event loop regardless of
  36. // the script runtime.
  37. is_running_ = true;
  38. LOG(INFO) << "Marking booted slot as good.";
  39. if (!boot_control_->MarkBootSuccessfulAsync(
  40. base::Bind(&UpdateBootFlagsAction::CompleteUpdateBootFlags,
  41. base::Unretained(this)))) {
  42. CompleteUpdateBootFlags(false);
  43. }
  44. }
  45. void UpdateBootFlagsAction::TerminateProcessing() {
  46. is_running_ = false;
  47. }
  48. void UpdateBootFlagsAction::CompleteUpdateBootFlags(bool successful) {
  49. if (!successful) {
  50. // We ignore the failure for now because if the updating boot flags is flaky
  51. // or has a bug in a specific release, then blocking the update can cause
  52. // devices to stay behind even though we could have updated the system and
  53. // fixed the issue regardless of this failure.
  54. //
  55. // TODO(ahassani): Add new error code metric for kUpdateBootFlagsFailed.
  56. LOG(ERROR) << "Updating boot flags failed, but ignoring its failure.";
  57. }
  58. // As the callback to MarkBootSuccessfulAsync, this function can still be
  59. // called even after the current UpdateBootFlagsAction object get destroyed by
  60. // the action processor. In this case, check the value of the static variable
  61. // |is_running_| and skip executing the callback function.
  62. if (!is_running_) {
  63. LOG(INFO) << "UpdateBootFlagsAction is no longer running.";
  64. return;
  65. }
  66. is_running_ = false;
  67. updated_boot_flags_ = true;
  68. processor_->ActionComplete(this, ErrorCode::kSuccess);
  69. }
  70. } // namespace chromeos_update_engine