blob: c56218aa2d2ae1e8fd1438a84165cbfd23993f74 [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_POSTINSTALL_RUNNER_ACTION_H_
18#define UPDATE_ENGINE_POSTINSTALL_RUNNER_ACTION_H_
adlr@google.com3defe6a2009-12-04 20:57:17 +000019
20#include <string>
Darin Petkov6f03a3b2010-11-10 14:27:14 -080021
adlr@google.com3defe6a2009-12-04 20:57:17 +000022#include "update_engine/action.h"
Andrew de los Reyesf9714432010-05-04 10:21:23 -070023#include "update_engine/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
Darin Petkov6f03a3b2010-11-10 14:27:14 -080054 // Subprocess::Exec callback.
Alex Deymo461b2592015-07-24 20:10:52 -070055 void CompletePostinstall(int return_code,
56 const std::string& output);
Darin Petkov6f03a3b2010-11-10 14:27:14 -080057
Chris Sosad317e402013-06-12 13:47:09 -070058 InstallPlan install_plan_;
Darin Petkov6f03a3b2010-11-10 14:27:14 -080059 std::string temp_rootfs_dir_;
60
Alex Deymo31d95ac2015-09-17 11:56:18 -070061 // The main SystemState singleton.
62 SystemState* system_state_;
63
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070064 // True if Powerwash Marker was created before invoking post-install script.
65 // False otherwise. Used for cleaning up if post-install fails.
Alex Deymo31d95ac2015-09-17 11:56:18 -070066 bool powerwash_marker_created_ = false;
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070067
Alex Vakulenko88b591f2014-08-28 16:48:57 -070068 // Non-null value will cause post-install to override the default marker
69 // file name; used for testing.
Gilad Arnold30dedd82013-07-03 06:19:09 -070070 const char* powerwash_marker_file_;
71
adlr@google.com3defe6a2009-12-04 20:57:17 +000072 DISALLOW_COPY_AND_ASSIGN(PostinstallRunnerAction);
73};
74
75} // namespace chromeos_update_engine
76
Gilad Arnoldcf175a02014-07-10 16:48:47 -070077#endif // UPDATE_ENGINE_POSTINSTALL_RUNNER_ACTION_H_