blob: ab267b825ab5a17c9f401be3b099c197bb395fcf [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
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.com3defe6a2009-12-04 20:57:17 +000016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_
18#define UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_
adlr@google.com3defe6a2009-12-04 20:57:17 +000019
20#include <string>
Darin Petkov6f03a3b2010-11-10 14:27:14 -080021
Alex Deymo39910dc2015-11-09 17:04:30 -080022#include "update_engine/common/action.h"
23#include "update_engine/payload_consumer/install_plan.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000024
25// The Postinstall Runner Action is responsible for running the postinstall
26// script of a successfully downloaded update.
27
28namespace chromeos_update_engine {
29
Alex Deymob15a0b82015-11-25 20:30:40 -030030class BootControlInterface;
31
Chris Sosad317e402013-06-12 13:47:09 -070032class PostinstallRunnerAction : public InstallPlanAction {
adlr@google.com3defe6a2009-12-04 20:57:17 +000033 public:
Alex Deymob15a0b82015-11-25 20:30:40 -030034 explicit PostinstallRunnerAction(BootControlInterface* boot_control)
35 : PostinstallRunnerAction(boot_control, nullptr) {}
adlr@google.com3defe6a2009-12-04 20:57:17 +000036
adlr@google.com3defe6a2009-12-04 20:57:17 +000037 void PerformAction();
38
Darin Petkov6f03a3b2010-11-10 14:27:14 -080039 // Note that there's no support for terminating this action currently.
adlr@google.com3defe6a2009-12-04 20:57:17 +000040 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 Deymo31d95ac2015-09-17 11:56:18 -070047 friend class PostinstallRunnerActionTest;
48
49 // Special constructor used for testing purposes.
Alex Deymob15a0b82015-11-25 20:30:40 -030050 PostinstallRunnerAction(BootControlInterface* boot_control,
Alex Deymo31d95ac2015-09-17 11:56:18 -070051 const char* powerwash_marker_file)
Alex Deymob15a0b82015-11-25 20:30:40 -030052 : boot_control_(boot_control),
Alex Deymo31d95ac2015-09-17 11:56:18 -070053 powerwash_marker_file_(powerwash_marker_file) {}
54
Alex Deymoe5e5fe92015-10-05 09:28:19 -070055 void PerformPartitionPostinstall();
56
Darin Petkov6f03a3b2010-11-10 14:27:14 -080057 // Subprocess::Exec callback.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070058 void CompletePartitionPostinstall(int return_code,
59 const std::string& output);
60
Alex Deymob15a0b82015-11-25 20:30:40 -030061 // 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 Deymoe5e5fe92015-10-05 09:28:19 -070063 void CompletePostinstall(ErrorCode error_code);
Darin Petkov6f03a3b2010-11-10 14:27:14 -080064
Chris Sosad317e402013-06-12 13:47:09 -070065 InstallPlan install_plan_;
Darin Petkov6f03a3b2010-11-10 14:27:14 -080066 std::string temp_rootfs_dir_;
67
Alex Deymoe5e5fe92015-10-05 09:28:19 -070068 // The partition being processed on the list of partitions specified in the
69 // InstallPlan.
70 size_t current_partition_{0};
71
Alex Deymob15a0b82015-11-25 20:30:40 -030072 // The BootControlInerface used to mark the new slot as ready.
73 BootControlInterface* boot_control_;
Alex Deymo31d95ac2015-09-17 11:56:18 -070074
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070075 // True if Powerwash Marker was created before invoking post-install script.
76 // False otherwise. Used for cleaning up if post-install fails.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070077 bool powerwash_marker_created_{false};
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070078
Alex Vakulenko88b591f2014-08-28 16:48:57 -070079 // Non-null value will cause post-install to override the default marker
80 // file name; used for testing.
Gilad Arnold30dedd82013-07-03 06:19:09 -070081 const char* powerwash_marker_file_;
82
adlr@google.com3defe6a2009-12-04 20:57:17 +000083 DISALLOW_COPY_AND_ASSIGN(PostinstallRunnerAction);
84};
85
86} // namespace chromeos_update_engine
87
Alex Deymo39910dc2015-11-09 17:04:30 -080088#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_