Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2010 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 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_ |
| 18 | #define UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_ |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | |
| 20 | #include <string> |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 21 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 22 | #include "update_engine/common/action.h" |
| 23 | #include "update_engine/payload_consumer/install_plan.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 24 | |
| 25 | // The Postinstall Runner Action is responsible for running the postinstall |
| 26 | // script of a successfully downloaded update. |
| 27 | |
| 28 | namespace chromeos_update_engine { |
| 29 | |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 30 | class BootControlInterface; |
| 31 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 32 | class PostinstallRunnerAction : public InstallPlanAction { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 33 | public: |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 34 | explicit PostinstallRunnerAction(BootControlInterface* boot_control) |
| 35 | : PostinstallRunnerAction(boot_control, nullptr) {} |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | void PerformAction(); |
| 38 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 39 | // Note that there's no support for terminating this action currently. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 40 | void TerminateProcessing() { CHECK(false); } |
| 41 | |
| 42 | // Debugging/logging |
| 43 | static std::string StaticType() { return "PostinstallRunnerAction"; } |
| 44 | std::string Type() const { return StaticType(); } |
| 45 | |
| 46 | private: |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 47 | friend class PostinstallRunnerActionTest; |
| 48 | |
| 49 | // Special constructor used for testing purposes. |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 50 | PostinstallRunnerAction(BootControlInterface* boot_control, |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 51 | const char* powerwash_marker_file) |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 52 | : boot_control_(boot_control), |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 53 | powerwash_marker_file_(powerwash_marker_file) {} |
| 54 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 55 | void PerformPartitionPostinstall(); |
| 56 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 57 | // Subprocess::Exec callback. |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 58 | void CompletePartitionPostinstall(int return_code, |
| 59 | const std::string& output); |
| 60 | |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 61 | // Complete the Action with the passed |error_code| and mark the new slot as |
| 62 | // ready. Called when the post-install script was run for all the partitions. |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 63 | void CompletePostinstall(ErrorCode error_code); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 64 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 65 | InstallPlan install_plan_; |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 66 | |
| 67 | // The path where the filesystem will be mounted during post-install. |
| 68 | std::string fs_mount_dir_; |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 69 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 70 | // The partition being processed on the list of partitions specified in the |
| 71 | // InstallPlan. |
| 72 | size_t current_partition_{0}; |
| 73 | |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 74 | // The BootControlInerface used to mark the new slot as ready. |
| 75 | BootControlInterface* boot_control_; |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 76 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 77 | // True if Powerwash Marker was created before invoking post-install script. |
| 78 | // False otherwise. Used for cleaning up if post-install fails. |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 79 | bool powerwash_marker_created_{false}; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 80 | |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 81 | // Non-null value will cause post-install to override the default marker |
| 82 | // file name; used for testing. |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 83 | const char* powerwash_marker_file_; |
| 84 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 85 | DISALLOW_COPY_AND_ASSIGN(PostinstallRunnerAction); |
| 86 | }; |
| 87 | |
| 88 | } // namespace chromeos_update_engine |
| 89 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 90 | #endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_ |