OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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/utils.h" | 5 #include "update_engine/utils.h" |
6 | 6 |
7 #include <sys/mount.h> | 7 #include <sys/mount.h> |
8 #include <sys/resource.h> | 8 #include <sys/resource.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <sys/wait.h> | 11 #include <sys/wait.h> |
12 #include <dirent.h> | 12 #include <dirent.h> |
13 #include <errno.h> | 13 #include <errno.h> |
14 #include <fcntl.h> | 14 #include <fcntl.h> |
15 #include <stdio.h> | 15 #include <stdio.h> |
16 #include <stdlib.h> | 16 #include <stdlib.h> |
17 #include <string.h> | 17 #include <string.h> |
18 #include <unistd.h> | 18 #include <unistd.h> |
19 | 19 |
20 #include <algorithm> | 20 #include <algorithm> |
21 | 21 |
22 #include <base/eintr_wrapper.h> | 22 #include <base/eintr_wrapper.h> |
23 #include <base/file_path.h> | 23 #include <base/file_path.h> |
24 #include <base/file_util.h> | 24 #include <base/file_util.h> |
25 #include <base/rand_util.h> | 25 #include <base/rand_util.h> |
26 #include <base/string_util.h> | 26 #include <base/string_util.h> |
27 #include <base/logging.h> | 27 #include <base/logging.h> |
28 #include <cros_boot_mode/boot_mode.h> | |
29 #include <google/protobuf/stubs/common.h> | 28 #include <google/protobuf/stubs/common.h> |
30 #include <rootdev/rootdev.h> | 29 #include <rootdev/rootdev.h> |
31 | 30 |
32 #include "update_engine/file_writer.h" | 31 #include "update_engine/file_writer.h" |
33 #include "update_engine/omaha_request_params.h" | 32 #include "update_engine/omaha_request_params.h" |
34 #include "update_engine/subprocess.h" | 33 #include "update_engine/subprocess.h" |
35 | 34 |
36 using std::min; | 35 using std::min; |
37 using std::string; | 36 using std::string; |
38 using std::vector; | 37 using std::vector; |
39 | 38 |
40 namespace chromeos_update_engine { | 39 namespace chromeos_update_engine { |
41 | 40 |
42 namespace utils { | 41 namespace utils { |
43 | 42 |
44 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; | 43 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; |
45 static const char kDevImageMarker[] = "/root/.dev_mode"; | 44 static const char kDevImageMarker[] = "/root/.dev_mode"; |
46 | 45 |
47 bool IsOfficialBuild() { | 46 bool IsOfficialBuild() { |
48 return !file_util::PathExists(FilePath(kDevImageMarker)); | 47 return !file_util::PathExists(FilePath(kDevImageMarker)); |
49 } | 48 } |
50 | 49 |
51 bool IsOOBEComplete() { | 50 bool IsOOBEComplete() { |
52 return file_util::PathExists(FilePath(kOOBECompletedMarker)); | 51 return file_util::PathExists(FilePath(kOOBECompletedMarker)); |
53 } | 52 } |
54 | 53 |
55 bool IsNormalBootMode() { | 54 bool IsNormalBootMode() { |
56 cros_boot_mode::BootMode mode; | 55 // TODO(petkov): Convert to a library call once a crossystem library is |
57 mode.Initialize(false, // unsupported_is_developer | 56 // available (crosbug.com/13291). |
58 true); // use_bootloader | 57 int exit_code = 0; |
59 bool normal = mode.mode() == cros_boot_mode::BootMode::kNormal; | 58 vector<string> cmd(1, "/usr/bin/crossystem"); |
60 LOG_IF(INFO, !normal) << "Boot mode not normal: " << mode.mode_text(); | 59 cmd.push_back("devsw_boot?1"); |
61 return normal; | 60 |
| 61 // Assume dev mode if the dev switch is set to 1 and there was no error |
| 62 // executing crossystem. Assume normal mode otherwise. |
| 63 bool success = Subprocess::SynchronousExec(cmd, &exit_code); |
| 64 bool dev_mode = success && exit_code == 0; |
| 65 LOG_IF(INFO, dev_mode) << "Booted in dev mode."; |
| 66 return !dev_mode; |
62 } | 67 } |
63 | 68 |
64 bool WriteFile(const char* path, const char* data, int data_len) { | 69 bool WriteFile(const char* path, const char* data, int data_len) { |
65 DirectFileWriter writer; | 70 DirectFileWriter writer; |
66 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path, | 71 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path, |
67 O_WRONLY | O_CREAT | O_TRUNC, | 72 O_WRONLY | O_CREAT | O_TRUNC, |
68 0600)); | 73 0600)); |
69 ScopedFileWriterCloser closer(&writer); | 74 ScopedFileWriterCloser closer(&writer); |
70 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len)); | 75 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len)); |
71 return true; | 76 return true; |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 reinterpret_cast<google::protobuf::Closure*>(data); | 562 reinterpret_cast<google::protobuf::Closure*>(data); |
558 callback->Run(); | 563 callback->Run(); |
559 return FALSE; | 564 return FALSE; |
560 } | 565 } |
561 | 566 |
562 const char* const kStatefulPartition = "/mnt/stateful_partition"; | 567 const char* const kStatefulPartition = "/mnt/stateful_partition"; |
563 | 568 |
564 } // namespace utils | 569 } // namespace utils |
565 | 570 |
566 } // namespace chromeos_update_engine | 571 } // namespace chromeos_update_engine |
OLD | NEW |