| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "update_engine/postinstall_runner_action.h" | 5 #include "update_engine/postinstall_runner_action.h" |
| 6 #include <sys/mount.h> | 6 #include <sys/mount.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <vector> |
| 9 #include "update_engine/subprocess.h" |
| 8 #include "update_engine/utils.h" | 10 #include "update_engine/utils.h" |
| 9 | 11 |
| 10 namespace chromeos_update_engine { | 12 namespace chromeos_update_engine { |
| 11 | 13 |
| 12 using std::string; | 14 using std::string; |
| 15 using std::vector; |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| 15 const string kMountPath(string(utils::kStatefulPartition) + "/au_destination"); | |
| 16 const string kPostinstallScript("/postinst"); | 18 const string kPostinstallScript("/postinst"); |
| 17 } | 19 } |
| 18 | 20 |
| 19 void PostinstallRunnerAction::PerformAction() { | 21 void PostinstallRunnerAction::PerformAction() { |
| 20 CHECK(HasInputObject()); | 22 CHECK(HasInputObject()); |
| 21 const string install_device = GetInputObject(); | 23 const InstallPlan install_plan = GetInputObject(); |
| 24 const string install_device = install_plan.install_path; |
| 25 ScopedActionCompleter completer(processor_, this); |
| 26 |
| 27 utils::BootLoader boot_loader; |
| 28 TEST_AND_RETURN(utils::GetBootloader(&boot_loader)); |
| 22 | 29 |
| 23 int rc = mount(install_device.c_str(), kMountPath.c_str(), "ext3", 0, NULL); | 30 bool read_only = (boot_loader == utils::BootLoader_CHROME_FIRMWARE); |
| 24 if (rc < 0) { | 31 |
| 25 LOG(ERROR) << "Unable to mount destination device " << install_device | 32 // Make mountpoint |
| 26 << " onto " << kMountPath; | 33 string temp_dir; |
| 27 processor_->ActionComplete(this, false); | 34 TEST_AND_RETURN(utils::MakeTempDirectory("/tmp/au_postint_mount.XXXXXX", |
| 28 return; | 35 &temp_dir)); |
| 36 ScopedDirRemover temp_dir_remover(temp_dir); |
| 37 |
| 38 { |
| 39 // Scope for the mount |
| 40 unsigned long mountflags = read_only ? MS_RDONLY : 0; |
| 41 |
| 42 int rc = mount(install_device.c_str(), |
| 43 temp_dir.c_str(), |
| 44 "ext3", |
| 45 mountflags, |
| 46 NULL); |
| 47 if (rc < 0) { |
| 48 LOG(ERROR) << "Unable to mount destination device " << install_device |
| 49 << " onto " << temp_dir; |
| 50 return; |
| 51 } |
| 52 ScopedFilesystemUnmounter unmounter(temp_dir); |
| 53 |
| 54 // run postinstall script |
| 55 vector<string> command; |
| 56 command.push_back(temp_dir + kPostinstallScript); |
| 57 command.push_back(install_device); |
| 58 command.push_back(precommit_ ? "" : "--postcommit"); |
| 59 rc = 0; |
| 60 TEST_AND_RETURN(Subprocess::SynchronousExec(command, &rc)); |
| 61 bool success = (rc == 0); |
| 62 if (!success) { |
| 63 LOG(ERROR) << "Postinst command failed with code: " << rc; |
| 64 return; |
| 65 } |
| 29 } | 66 } |
| 30 | 67 |
| 31 // run postinstall script | 68 if (HasOutputPipe()) { |
| 32 rc = system((kMountPath + kPostinstallScript + " " + install_device).c_str()); | 69 SetOutputObject(install_plan); |
| 33 bool success = (rc == 0); | |
| 34 if (!success) { | |
| 35 LOG(ERROR) << "Postinst command failed with code: " << rc; | |
| 36 } | 70 } |
| 37 | 71 completer.set_success(true); |
| 38 rc = umount(kMountPath.c_str()); | |
| 39 if (rc < 0) { | |
| 40 // non-fatal | |
| 41 LOG(ERROR) << "Unable to umount destination device"; | |
| 42 } | |
| 43 if (success && HasOutputPipe()) { | |
| 44 SetOutputObject(install_device); | |
| 45 } | |
| 46 processor_->ActionComplete(this, success); | |
| 47 } | 72 } |
| 48 | 73 |
| 49 } // namespace chromeos_update_engine | 74 } // namespace chromeos_update_engine |
| OLD | NEW |