blob: de19c0cdd0258443d2544d8403b9aef9a24b87d8 [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"
Alex Deymo31d95ac2015-09-17 11:56:18 -070024#include "update_engine/system_state.h"
adlr@google.com3defe6a2009-12-04 20:57:17 +000025
26// The Postinstall Runner Action is responsible for running the postinstall
27// script of a successfully downloaded update.
28
29namespace chromeos_update_engine {
30
Chris Sosad317e402013-06-12 13:47:09 -070031class PostinstallRunnerAction : public InstallPlanAction {
adlr@google.com3defe6a2009-12-04 20:57:17 +000032 public:
Alex Deymo31d95ac2015-09-17 11:56:18 -070033 explicit PostinstallRunnerAction(SystemState* system_state)
34 : PostinstallRunnerAction(system_state, nullptr) {}
adlr@google.com3defe6a2009-12-04 20:57:17 +000035
adlr@google.com3defe6a2009-12-04 20:57:17 +000036 void PerformAction();
37
Darin Petkov6f03a3b2010-11-10 14:27:14 -080038 // Note that there's no support for terminating this action currently.
adlr@google.com3defe6a2009-12-04 20:57:17 +000039 void TerminateProcessing() { CHECK(false); }
40
41 // Debugging/logging
42 static std::string StaticType() { return "PostinstallRunnerAction"; }
43 std::string Type() const { return StaticType(); }
44
45 private:
Alex Deymo31d95ac2015-09-17 11:56:18 -070046 friend class PostinstallRunnerActionTest;
47
48 // Special constructor used for testing purposes.
49 PostinstallRunnerAction(SystemState* system_state,
50 const char* powerwash_marker_file)
51 : system_state_(system_state),
52 powerwash_marker_file_(powerwash_marker_file) {}
53
Alex Deymoe5e5fe92015-10-05 09:28:19 -070054 void PerformPartitionPostinstall();
55
Darin Petkov6f03a3b2010-11-10 14:27:14 -080056 // Subprocess::Exec callback.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070057 void CompletePartitionPostinstall(int return_code,
58 const std::string& output);
59
60 //
61 void CompletePostinstall(ErrorCode error_code);
Darin Petkov6f03a3b2010-11-10 14:27:14 -080062
Chris Sosad317e402013-06-12 13:47:09 -070063 InstallPlan install_plan_;
Darin Petkov6f03a3b2010-11-10 14:27:14 -080064 std::string temp_rootfs_dir_;
65
Alex Deymoe5e5fe92015-10-05 09:28:19 -070066 // The partition being processed on the list of partitions specified in the
67 // InstallPlan.
68 size_t current_partition_{0};
69
Alex Deymo31d95ac2015-09-17 11:56:18 -070070 // The main SystemState singleton.
71 SystemState* system_state_;
72
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070073 // True if Powerwash Marker was created before invoking post-install script.
74 // False otherwise. Used for cleaning up if post-install fails.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070075 bool powerwash_marker_created_{false};
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070076
Alex Vakulenko88b591f2014-08-28 16:48:57 -070077 // Non-null value will cause post-install to override the default marker
78 // file name; used for testing.
Gilad Arnold30dedd82013-07-03 06:19:09 -070079 const char* powerwash_marker_file_;
80
adlr@google.com3defe6a2009-12-04 20:57:17 +000081 DISALLOW_COPY_AND_ASSIGN(PostinstallRunnerAction);
82};
83
84} // namespace chromeos_update_engine
85
Alex Deymo39910dc2015-11-09 17:04:30 -080086#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_