blob: a626ce6bba15e5b7f0b2d8c477ad658ccf5d8e2b [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
Alex Deymod15c5462016-03-09 18:11:12 -080037 // InstallPlanAction overrides.
Alex Deymocbc22742016-03-04 17:53:02 -080038 void PerformAction() override;
Alex Deymod15c5462016-03-09 18:11:12 -080039 void SuspendAction() override;
40 void ResumeAction() override;
41 void TerminateProcessing() override;
adlr@google.com3defe6a2009-12-04 20:57:17 +000042
43 // Debugging/logging
44 static std::string StaticType() { return "PostinstallRunnerAction"; }
Alex Deymocbc22742016-03-04 17:53:02 -080045 std::string Type() const override { return StaticType(); }
adlr@google.com3defe6a2009-12-04 20:57:17 +000046
47 private:
Alex Deymo31d95ac2015-09-17 11:56:18 -070048 friend class PostinstallRunnerActionTest;
49
50 // Special constructor used for testing purposes.
Alex Deymob15a0b82015-11-25 20:30:40 -030051 PostinstallRunnerAction(BootControlInterface* boot_control,
Alex Deymo31d95ac2015-09-17 11:56:18 -070052 const char* powerwash_marker_file)
Alex Deymob15a0b82015-11-25 20:30:40 -030053 : boot_control_(boot_control),
Alex Deymo31d95ac2015-09-17 11:56:18 -070054 powerwash_marker_file_(powerwash_marker_file) {}
55
Alex Deymoe5e5fe92015-10-05 09:28:19 -070056 void PerformPartitionPostinstall();
57
Alex Deymod15c5462016-03-09 18:11:12 -080058 // Unmount and remove the mountpoint directory if needed.
59 void CleanupMount();
60
Darin Petkov6f03a3b2010-11-10 14:27:14 -080061 // Subprocess::Exec callback.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070062 void CompletePartitionPostinstall(int return_code,
63 const std::string& output);
64
Alex Deymob15a0b82015-11-25 20:30:40 -030065 // Complete the Action with the passed |error_code| and mark the new slot as
66 // ready. Called when the post-install script was run for all the partitions.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070067 void CompletePostinstall(ErrorCode error_code);
Darin Petkov6f03a3b2010-11-10 14:27:14 -080068
Chris Sosad317e402013-06-12 13:47:09 -070069 InstallPlan install_plan_;
Alex Deymo390efed2016-02-18 11:00:40 -080070
71 // The path where the filesystem will be mounted during post-install.
72 std::string fs_mount_dir_;
Darin Petkov6f03a3b2010-11-10 14:27:14 -080073
Alex Deymoe5e5fe92015-10-05 09:28:19 -070074 // The partition being processed on the list of partitions specified in the
75 // InstallPlan.
76 size_t current_partition_{0};
77
Alex Deymob15a0b82015-11-25 20:30:40 -030078 // The BootControlInerface used to mark the new slot as ready.
79 BootControlInterface* boot_control_;
Alex Deymo31d95ac2015-09-17 11:56:18 -070080
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070081 // True if Powerwash Marker was created before invoking post-install script.
82 // False otherwise. Used for cleaning up if post-install fails.
Alex Deymoe5e5fe92015-10-05 09:28:19 -070083 bool powerwash_marker_created_{false};
Jay Srinivasan1c0fe792013-03-28 16:45:25 -070084
Alex Vakulenko88b591f2014-08-28 16:48:57 -070085 // Non-null value will cause post-install to override the default marker
86 // file name; used for testing.
Gilad Arnold30dedd82013-07-03 06:19:09 -070087 const char* powerwash_marker_file_;
88
Alex Deymod15c5462016-03-09 18:11:12 -080089 // Postinstall command currently running, or 0 if no program running.
90 pid_t current_command_{0};
91
adlr@google.com3defe6a2009-12-04 20:57:17 +000092 DISALLOW_COPY_AND_ASSIGN(PostinstallRunnerAction);
93};
94
95} // namespace chromeos_update_engine
96
Alex Deymo39910dc2015-11-09 17:04:30 -080097#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_POSTINSTALL_RUNNER_ACTION_H_