| 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 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_POSTINSTALL_RUNNER_ACTION_H_ | 
 | 18 | #define UPDATE_ENGINE_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 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 22 | #include "update_engine/action.h" | 
| Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 23 | #include "update_engine/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 |  | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 30 | class PostinstallRunnerAction : public InstallPlanAction { | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 31 |  public: | 
| Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 32 |   PostinstallRunnerAction() | 
 | 33 |       : powerwash_marker_created_(false), | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 34 |         powerwash_marker_file_(nullptr) {} | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 35 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 |   void PerformAction(); | 
 | 37 |  | 
| Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 38 |   // Note that there's no support for terminating this action currently. | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 39 |   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: | 
| Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 46 |   // Subprocess::Exec callback. | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 47 |   void CompletePostinstall(int return_code, | 
 | 48 |                            const std::string& output); | 
| Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 49 |  | 
| Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 50 |   InstallPlan install_plan_; | 
| Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 51 |   std::string temp_rootfs_dir_; | 
 | 52 |  | 
| Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 53 |   // True if Powerwash Marker was created before invoking post-install script. | 
 | 54 |   // False otherwise. Used for cleaning up if post-install fails. | 
 | 55 |   bool powerwash_marker_created_; | 
 | 56 |  | 
| Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 57 |   // Non-null value will cause post-install to override the default marker | 
 | 58 |   // file name; used for testing. | 
| Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 59 |   const char* powerwash_marker_file_; | 
 | 60 |  | 
 | 61 |   // Special ctor + friend declaration for testing purposes. | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 62 |   explicit PostinstallRunnerAction(const char* powerwash_marker_file) | 
| Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 63 |       : powerwash_marker_created_(false), | 
 | 64 |         powerwash_marker_file_(powerwash_marker_file) {} | 
 | 65 |  | 
 | 66 |   friend class PostinstallRunnerActionTest; | 
 | 67 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 68 |   DISALLOW_COPY_AND_ASSIGN(PostinstallRunnerAction); | 
 | 69 | }; | 
 | 70 |  | 
 | 71 | }  // namespace chromeos_update_engine | 
 | 72 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 73 | #endif  // UPDATE_ENGINE_POSTINSTALL_RUNNER_ACTION_H_ |