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

Side by Side Diff: client/settings.cc

Issue 997613002: Fix Settings::OpenForReadingAndWriting using O_CREAT with no mode. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | client/settings_test.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 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 12 matching lines...) Expand all
23 #include "base/compiler_specific.h" 23 #include "base/compiler_specific.h"
24 #include "base/logging.h" 24 #include "base/logging.h"
25 #include "base/posix/eintr_wrapper.h" 25 #include "base/posix/eintr_wrapper.h"
26 #include "util/numeric/in_range_cast.h" 26 #include "util/numeric/in_range_cast.h"
27 27
28 namespace crashpad { 28 namespace crashpad {
29 29
30 struct ALIGNAS(4) Settings::Data { 30 struct ALIGNAS(4) Settings::Data {
31 static const uint16_t kSettingsVersion = 1; 31 static const uint16_t kSettingsVersion = 1;
32 32
33 enum Options : uint32_t {
34 kUploadsEnabled = 1 << 0,
35 };
36
33 Data() : version(kSettingsVersion), 37 Data() : version(kSettingsVersion),
34 options(0), 38 options(0),
35 last_upload_attempt_time(0), 39 last_upload_attempt_time(0),
36 client_id() {} 40 client_id() {}
37 41
38 enum Options : uint32_t {
39 kUploadsEnabled = 1 << 0,
40 };
41
42 uint32_t version; 42 uint32_t version;
43 uint32_t options; 43 uint32_t options;
44 uint64_t last_upload_attempt_time; // time_t 44 uint64_t last_upload_attempt_time; // time_t
45 UUID client_id; 45 UUID client_id;
46 }; 46 };
47 47
48 Settings::Settings(const base::FilePath& file_path) 48 Settings::Settings(const base::FilePath& file_path)
49 : file_path_(file_path), 49 : file_path_(file_path),
50 initialized_() { 50 initialized_() {
51 } 51 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 146
147 ScopedFileHandle Settings::OpenForReading() { 147 ScopedFileHandle Settings::OpenForReading() {
148 ScopedFileHandle handle(HANDLE_EINTR(open(file_path(), O_RDONLY | O_SHLOCK))); 148 ScopedFileHandle handle(HANDLE_EINTR(open(file_path(), O_RDONLY | O_SHLOCK)));
149 PLOG_IF(ERROR, !handle.is_valid()) << "open for reading"; 149 PLOG_IF(ERROR, !handle.is_valid()) << "open for reading";
150 return handle.Pass(); 150 return handle.Pass();
151 } 151 }
152 152
153 ScopedFileHandle Settings::OpenForReadingAndWriting() { 153 ScopedFileHandle Settings::OpenForReadingAndWriting() {
154 ScopedFileHandle handle(HANDLE_EINTR( 154 ScopedFileHandle handle(HANDLE_EINTR(
155 open(file_path(), O_RDWR | O_EXLOCK | O_CREAT))); 155 open(file_path(), O_RDWR | O_EXLOCK | O_CREAT, 0644)));
156 PLOG_IF(ERROR, !handle.is_valid()) << "open for writing"; 156 PLOG_IF(ERROR, !handle.is_valid()) << "open for writing";
157 return handle.Pass(); 157 return handle.Pass();
158 } 158 }
159 159
160 bool Settings::OpenAndReadSettings(Data* out_data) { 160 bool Settings::OpenAndReadSettings(Data* out_data) {
161 ScopedFileHandle handle = OpenForReading(); 161 ScopedFileHandle handle = OpenForReading();
162 if (!handle.is_valid()) 162 if (!handle.is_valid())
163 return false; 163 return false;
164 164
165 if (ReadSettings(handle.get(), out_data)) 165 if (ReadSettings(handle.get(), out_data))
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 uuid_t uuid; 241 uuid_t uuid;
242 uuid_generate(uuid); 242 uuid_generate(uuid);
243 243
244 Data settings; 244 Data settings;
245 settings.client_id.InitializeFromBytes(uuid); 245 settings.client_id.InitializeFromBytes(uuid);
246 246
247 return WriteSettings(handle, settings); 247 return WriteSettings(handle, settings);
248 } 248 }
249 249
250 } // namespace crashpad 250 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | client/settings_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698