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> | 8 #include <vector> |
9 #include "update_engine/subprocess.h" | 9 #include "update_engine/subprocess.h" |
10 #include "update_engine/utils.h" | 10 #include "update_engine/utils.h" |
11 | 11 |
12 namespace chromeos_update_engine { | 12 namespace chromeos_update_engine { |
13 | 13 |
14 using std::string; | 14 using std::string; |
15 using std::vector; | 15 using std::vector; |
16 | 16 |
17 namespace { | 17 namespace { |
18 const string kPostinstallScript("/postinst"); | 18 const string kPostinstallScript("/postinst"); |
19 } | 19 } |
20 | 20 |
21 void PostinstallRunnerAction::PerformAction() { | 21 void PostinstallRunnerAction::PerformAction() { |
22 CHECK(HasInputObject()); | 22 CHECK(HasInputObject()); |
23 const InstallPlan install_plan = GetInputObject(); | 23 const InstallPlan install_plan = GetInputObject(); |
24 const string install_device = install_plan.install_path; | 24 const string install_device = install_plan.install_path; |
25 ScopedActionCompleter completer(processor_, this); | 25 ScopedActionCompleter completer(processor_, this); |
26 | 26 |
27 utils::BootLoader boot_loader; | |
28 TEST_AND_RETURN(utils::GetBootloader(&boot_loader)); | |
29 | |
30 bool read_only = (boot_loader == utils::BootLoader_CHROME_FIRMWARE); | |
31 | |
32 // Make mountpoint | 27 // Make mountpoint |
33 string temp_dir; | 28 string temp_dir; |
34 TEST_AND_RETURN(utils::MakeTempDirectory("/tmp/au_postint_mount.XXXXXX", | 29 TEST_AND_RETURN(utils::MakeTempDirectory("/tmp/au_postint_mount.XXXXXX", |
35 &temp_dir)); | 30 &temp_dir)); |
36 ScopedDirRemover temp_dir_remover(temp_dir); | 31 ScopedDirRemover temp_dir_remover(temp_dir); |
37 | 32 |
38 { | 33 { |
39 // Scope for the mount | 34 // Scope for the mount |
40 unsigned long mountflags = read_only ? MS_RDONLY : 0; | 35 unsigned long mountflags = MS_RDONLY; |
41 | 36 |
42 int rc = mount(install_device.c_str(), | 37 int rc = mount(install_device.c_str(), |
43 temp_dir.c_str(), | 38 temp_dir.c_str(), |
44 "ext3", | 39 "ext4", |
45 mountflags, | 40 mountflags, |
46 NULL); | 41 NULL); |
47 if (rc < 0) { | 42 if (rc < 0) { |
| 43 LOG(INFO) << "Failed to mount install part as ext4. Trying ext3."; |
| 44 rc = mount(install_device.c_str(), |
| 45 temp_dir.c_str(), |
| 46 "ext3", |
| 47 mountflags, |
| 48 NULL); |
| 49 } |
| 50 if (rc < 0) { |
48 LOG(ERROR) << "Unable to mount destination device " << install_device | 51 LOG(ERROR) << "Unable to mount destination device " << install_device |
49 << " onto " << temp_dir; | 52 << " onto " << temp_dir; |
50 return; | 53 return; |
51 } | 54 } |
52 ScopedFilesystemUnmounter unmounter(temp_dir); | 55 ScopedFilesystemUnmounter unmounter(temp_dir); |
53 | 56 |
54 // run postinstall script | 57 // run postinstall script |
55 vector<string> command; | 58 vector<string> command; |
56 command.push_back(temp_dir + kPostinstallScript); | 59 command.push_back(temp_dir + kPostinstallScript); |
57 command.push_back(install_device); | 60 command.push_back(install_device); |
58 command.push_back(precommit_ ? "" : "--postcommit"); | 61 command.push_back(precommit_ ? "" : "--postcommit"); |
59 rc = 0; | 62 rc = 0; |
60 TEST_AND_RETURN(Subprocess::SynchronousExec(command, &rc)); | 63 TEST_AND_RETURN(Subprocess::SynchronousExec(command, &rc)); |
61 bool success = (rc == 0); | 64 bool success = (rc == 0); |
62 if (!success) { | 65 if (!success) { |
63 LOG(ERROR) << "Postinst command failed with code: " << rc; | 66 LOG(ERROR) << "Postinst command failed with code: " << rc; |
64 return; | 67 return; |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 if (HasOutputPipe()) { | 71 if (HasOutputPipe()) { |
69 SetOutputObject(install_plan); | 72 SetOutputObject(install_plan); |
70 } | 73 } |
71 completer.set_success(true); | 74 completer.set_success(true); |
72 } | 75 } |
73 | 76 |
74 } // namespace chromeos_update_engine | 77 } // namespace chromeos_update_engine |
OLD | NEW |