Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: utils.cc

Issue 6098008: AU: Include a bit flag (bit 31) in error codes to indicate non-normal boot mode. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: review Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
28 #include <rootdev/rootdev.h> 29 #include <rootdev/rootdev.h>
29 30
30 #include "update_engine/file_writer.h" 31 #include "update_engine/file_writer.h"
31 #include "update_engine/omaha_request_params.h" 32 #include "update_engine/omaha_request_params.h"
32 #include "update_engine/subprocess.h" 33 #include "update_engine/subprocess.h"
33 34
34 using std::min; 35 using std::min;
35 using std::string; 36 using std::string;
36 using std::vector; 37 using std::vector;
37 38
38 namespace chromeos_update_engine { 39 namespace chromeos_update_engine {
39 40
40 namespace utils { 41 namespace utils {
41 42
42 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; 43 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed";
43 static const char kDevImageMarker[] = "/root/.dev_mode"; 44 static const char kDevImageMarker[] = "/root/.dev_mode";
44 45
45 bool IsOfficialBuild() { 46 bool IsOfficialBuild() {
46 return !file_util::PathExists(FilePath(kDevImageMarker)); 47 return !file_util::PathExists(FilePath(kDevImageMarker));
47 } 48 }
48 49
49 bool IsOOBEComplete() { 50 bool IsOOBEComplete() {
50 return file_util::PathExists(FilePath(kOOBECompletedMarker)); 51 return file_util::PathExists(FilePath(kOOBECompletedMarker));
51 } 52 }
52 53
54 bool IsNormalBootMode() {
55 cros_boot_mode::BootMode mode;
56 mode.Initialize(false, // unsupported_is_developer
57 true); // use_bootloader
58 bool normal = mode.mode() == cros_boot_mode::BootMode::kNormal;
59 LOG_IF(INFO, !normal) << "Boot mode not normal: " << mode.mode_text();
60 return normal;
61 }
62
53 bool WriteFile(const char* path, const char* data, int data_len) { 63 bool WriteFile(const char* path, const char* data, int data_len) {
54 DirectFileWriter writer; 64 DirectFileWriter writer;
55 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path, 65 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path,
56 O_WRONLY | O_CREAT | O_TRUNC, 66 O_WRONLY | O_CREAT | O_TRUNC,
57 0600)); 67 0600));
58 ScopedFileWriterCloser closer(&writer); 68 ScopedFileWriterCloser closer(&writer);
59 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len)); 69 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len));
60 return true; 70 return true;
61 } 71 }
62 72
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 int min = value - range / 2; 549 int min = value - range / 2;
540 int max = value + range - range / 2; 550 int max = value + range - range / 2;
541 return base::RandInt(min, max); 551 return base::RandInt(min, max);
542 } 552 }
543 553
544 const char* const kStatefulPartition = "/mnt/stateful_partition"; 554 const char* const kStatefulPartition = "/mnt/stateful_partition";
545 555
546 } // namespace utils 556 } // namespace utils
547 557
548 } // namespace chromeos_update_engine 558 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698