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

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: 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 <dirent.h> 11 #include <dirent.h>
12 #include <errno.h> 12 #include <errno.h>
13 #include <fcntl.h> 13 #include <fcntl.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <stdlib.h> 15 #include <stdlib.h>
16 #include <string.h> 16 #include <string.h>
17 #include <unistd.h> 17 #include <unistd.h>
18 18
19 #include <algorithm> 19 #include <algorithm>
20 20
21 #include <base/eintr_wrapper.h> 21 #include <base/eintr_wrapper.h>
22 #include <base/file_path.h> 22 #include <base/file_path.h>
23 #include <base/file_util.h> 23 #include <base/file_util.h>
24 #include <base/rand_util.h> 24 #include <base/rand_util.h>
25 #include <base/string_util.h> 25 #include <base/string_util.h>
26 #include <base/logging.h> 26 #include <base/logging.h>
27 #include <cros_boot_mode/boot_mode.h>
27 #include <rootdev/rootdev.h> 28 #include <rootdev/rootdev.h>
28 29
29 #include "update_engine/file_writer.h" 30 #include "update_engine/file_writer.h"
30 #include "update_engine/omaha_request_params.h" 31 #include "update_engine/omaha_request_params.h"
31 #include "update_engine/subprocess.h" 32 #include "update_engine/subprocess.h"
32 33
33 using std::min; 34 using std::min;
34 using std::string; 35 using std::string;
35 using std::vector; 36 using std::vector;
36 37
37 namespace chromeos_update_engine { 38 namespace chromeos_update_engine {
38 39
39 namespace utils { 40 namespace utils {
40 41
41 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed"; 42 static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed";
42 static const char kDevImageMarker[] = "/root/.dev_mode"; 43 static const char kDevImageMarker[] = "/root/.dev_mode";
43 44
44 bool IsOfficialBuild() { 45 bool IsOfficialBuild() {
45 return !file_util::PathExists(FilePath(kDevImageMarker)); 46 return !file_util::PathExists(FilePath(kDevImageMarker));
46 } 47 }
47 48
48 bool IsOOBEComplete() { 49 bool IsOOBEComplete() {
49 return file_util::PathExists(FilePath(kOOBECompletedMarker)); 50 return file_util::PathExists(FilePath(kOOBECompletedMarker));
50 } 51 }
51 52
53 bool IsNormalBootMode() {
54 cros_boot_mode::BootMode mode;
55 mode.Initialize(false, true);
adlr 2011/01/07 22:44:08 perhaps a comment about what false, true means?
petkov 2011/01/07 22:50:45 Done.
56 bool normal = mode.mode() == cros_boot_mode::BootMode::kNormal;
57 LOG_IF(INFO, !normal) << "Boot mode not normal: " << mode.mode_text();
58 return normal;
59 }
60
52 bool WriteFile(const char* path, const char* data, int data_len) { 61 bool WriteFile(const char* path, const char* data, int data_len) {
53 DirectFileWriter writer; 62 DirectFileWriter writer;
54 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path, 63 TEST_AND_RETURN_FALSE_ERRNO(0 == writer.Open(path,
55 O_WRONLY | O_CREAT | O_TRUNC, 64 O_WRONLY | O_CREAT | O_TRUNC,
56 0600)); 65 0600));
57 ScopedFileWriterCloser closer(&writer); 66 ScopedFileWriterCloser closer(&writer);
58 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len)); 67 TEST_AND_RETURN_FALSE_ERRNO(data_len == writer.Write(data, data_len));
59 return true; 68 return true;
60 } 69 }
61 70
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 int min = value - range / 2; 526 int min = value - range / 2;
518 int max = value + range - range / 2; 527 int max = value + range - range / 2;
519 return base::RandInt(min, max); 528 return base::RandInt(min, max);
520 } 529 }
521 530
522 const char* const kStatefulPartition = "/mnt/stateful_partition"; 531 const char* const kStatefulPartition = "/mnt/stateful_partition";
523 532
524 } // namespace utils 533 } // namespace utils
525 534
526 } // namespace chromeos_update_engine 535 } // 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