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

Side by Side Diff: tools/crashpad_database_util.cc

Issue 1395653002: crashpad_database_util: Don’t create a database unless explicitly asked (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: For checkin Created 5 years, 2 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 | « tools/crashpad_database_util.ad ('k') | no next file » | 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 28 matching lines...) Expand all
39 #include "util/misc/uuid.h" 39 #include "util/misc/uuid.h"
40 40
41 namespace crashpad { 41 namespace crashpad {
42 namespace { 42 namespace {
43 43
44 void Usage(const base::FilePath& me) { 44 void Usage(const base::FilePath& me) {
45 fprintf(stderr, 45 fprintf(stderr,
46 "Usage: %" PRFilePath " [OPTION]... PID\n" 46 "Usage: %" PRFilePath " [OPTION]... PID\n"
47 "Operate on Crashpad crash report databases.\n" 47 "Operate on Crashpad crash report databases.\n"
48 "\n" 48 "\n"
49 " --create allow database at PATH to be created\n"
49 " -d, --database=PATH operate on the crash report database at PATH\ n" 50 " -d, --database=PATH operate on the crash report database at PATH\ n"
50 " --show-client-id show the client ID\n" 51 " --show-client-id show the client ID\n"
51 " --show-uploads-enabled show whether uploads are enabled\n" 52 " --show-uploads-enabled show whether uploads are enabled\n"
52 " --show-last-upload-attempt-time\n" 53 " --show-last-upload-attempt-time\n"
53 " show the last-upload-attempt time\n" 54 " show the last-upload-attempt time\n"
54 " --show-pending-reports show reports eligible for upload\n" 55 " --show-pending-reports show reports eligible for upload\n"
55 " --show-completed-reports show reports not eligible for upload\n" 56 " --show-completed-reports show reports not eligible for upload\n"
56 " --show-all-report-info with --show-*-reports, show more information\ n" 57 " --show-all-report-info with --show-*-reports, show more information\ n"
57 " --show-report=UUID show report stored under UUID\n" 58 " --show-report=UUID show report stored under UUID\n"
58 " --set-uploads-enabled=BOOL enable or disable uploads\n" 59 " --set-uploads-enabled=BOOL enable or disable uploads\n"
59 " --set-last-upload-attempt-time=TIME\n" 60 " --set-last-upload-attempt-time=TIME\n"
60 " set the last-upload-attempt time to TIME\n" 61 " set the last-upload-attempt time to TIME\n"
61 " --new-report=PATH submit a new report at PATH, or - for stdin\n " 62 " --new-report=PATH submit a new report at PATH, or - for stdin\n "
62 " --utc show and set UTC times instead of local\n" 63 " --utc show and set UTC times instead of local\n"
63 " --help display this help and exit\n" 64 " --help display this help and exit\n"
64 " --version output version information and exit\n", 65 " --version output version information and exit\n",
65 me.value().c_str()); 66 me.value().c_str());
66 ToolSupport::UsageTail(me); 67 ToolSupport::UsageTail(me);
67 } 68 }
68 69
69 struct Options { 70 struct Options {
70 std::vector<UUID> show_reports; 71 std::vector<UUID> show_reports;
71 std::vector<base::FilePath> new_report_paths; 72 std::vector<base::FilePath> new_report_paths;
72 const char* database; 73 const char* database;
73 const char* set_last_upload_attempt_time_string; 74 const char* set_last_upload_attempt_time_string;
74 time_t set_last_upload_attempt_time; 75 time_t set_last_upload_attempt_time;
76 bool create;
75 bool show_client_id; 77 bool show_client_id;
76 bool show_uploads_enabled; 78 bool show_uploads_enabled;
77 bool show_last_upload_attempt_time; 79 bool show_last_upload_attempt_time;
78 bool show_pending_reports; 80 bool show_pending_reports;
79 bool show_completed_reports; 81 bool show_completed_reports;
80 bool show_all_report_info; 82 bool show_all_report_info;
81 bool set_uploads_enabled; 83 bool set_uploads_enabled;
82 bool has_set_uploads_enabled; 84 bool has_set_uploads_enabled;
83 bool utc; 85 bool utc;
84 }; 86 };
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 const base::FilePath argv0( 248 const base::FilePath argv0(
247 ToolSupport::CommandLineArgumentToFilePathStringType(argv[0])); 249 ToolSupport::CommandLineArgumentToFilePathStringType(argv[0]));
248 const base::FilePath me(argv0.BaseName()); 250 const base::FilePath me(argv0.BaseName());
249 251
250 enum OptionFlags { 252 enum OptionFlags {
251 // “Short” (single-character) options. 253 // “Short” (single-character) options.
252 kOptionDatabase = 'd', 254 kOptionDatabase = 'd',
253 255
254 // Long options without short equivalents. 256 // Long options without short equivalents.
255 kOptionLastChar = 255, 257 kOptionLastChar = 255,
258 kOptionCreate,
256 kOptionShowClientID, 259 kOptionShowClientID,
257 kOptionShowUploadsEnabled, 260 kOptionShowUploadsEnabled,
258 kOptionShowLastUploadAttemptTime, 261 kOptionShowLastUploadAttemptTime,
259 kOptionShowPendingReports, 262 kOptionShowPendingReports,
260 kOptionShowCompletedReports, 263 kOptionShowCompletedReports,
261 kOptionShowAllReportInfo, 264 kOptionShowAllReportInfo,
262 kOptionShowReport, 265 kOptionShowReport,
263 kOptionSetUploadsEnabled, 266 kOptionSetUploadsEnabled,
264 kOptionSetLastUploadAttemptTime, 267 kOptionSetLastUploadAttemptTime,
265 kOptionNewReport, 268 kOptionNewReport,
266 kOptionUTC, 269 kOptionUTC,
267 270
268 // Standard options. 271 // Standard options.
269 kOptionHelp = -2, 272 kOptionHelp = -2,
270 kOptionVersion = -3, 273 kOptionVersion = -3,
271 }; 274 };
272 275
273 const option long_options[] = { 276 const option long_options[] = {
277 {"create", no_argument, nullptr, kOptionCreate},
274 {"database", required_argument, nullptr, kOptionDatabase}, 278 {"database", required_argument, nullptr, kOptionDatabase},
275 {"show-client-id", no_argument, nullptr, kOptionShowClientID}, 279 {"show-client-id", no_argument, nullptr, kOptionShowClientID},
276 {"show-uploads-enabled", no_argument, nullptr, kOptionShowUploadsEnabled}, 280 {"show-uploads-enabled", no_argument, nullptr, kOptionShowUploadsEnabled},
277 {"show-last-upload-attempt-time", 281 {"show-last-upload-attempt-time",
278 no_argument, 282 no_argument,
279 nullptr, 283 nullptr,
280 kOptionShowLastUploadAttemptTime}, 284 kOptionShowLastUploadAttemptTime},
281 {"show-pending-reports", no_argument, nullptr, kOptionShowPendingReports}, 285 {"show-pending-reports", no_argument, nullptr, kOptionShowPendingReports},
282 {"show-completed-reports", 286 {"show-completed-reports",
283 no_argument, 287 no_argument,
(...skipping 14 matching lines...) Expand all
298 {"help", no_argument, nullptr, kOptionHelp}, 302 {"help", no_argument, nullptr, kOptionHelp},
299 {"version", no_argument, nullptr, kOptionVersion}, 303 {"version", no_argument, nullptr, kOptionVersion},
300 {nullptr, 0, nullptr, 0}, 304 {nullptr, 0, nullptr, 0},
301 }; 305 };
302 306
303 Options options = {}; 307 Options options = {};
304 308
305 int opt; 309 int opt;
306 while ((opt = getopt_long(argc, argv, "d:", long_options, nullptr)) != -1) { 310 while ((opt = getopt_long(argc, argv, "d:", long_options, nullptr)) != -1) {
307 switch (opt) { 311 switch (opt) {
312 case kOptionCreate: {
313 options.create = true;
314 break;
315 }
308 case kOptionDatabase: { 316 case kOptionDatabase: {
309 options.database = optarg; 317 options.database = optarg;
310 break; 318 break;
311 } 319 }
312 case kOptionShowClientID: { 320 case kOptionShowClientID: {
313 options.show_client_id = true; 321 options.show_client_id = true;
314 break; 322 break;
315 } 323 }
316 case kOptionShowUploadsEnabled: { 324 case kOptionShowUploadsEnabled: {
317 options.show_uploads_enabled = true; 325 options.show_uploads_enabled = true;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 options.show_uploads_enabled + 411 options.show_uploads_enabled +
404 options.show_last_upload_attempt_time + 412 options.show_last_upload_attempt_time +
405 options.show_pending_reports + 413 options.show_pending_reports +
406 options.show_completed_reports + 414 options.show_completed_reports +
407 options.show_reports.size() + 415 options.show_reports.size() +
408 options.new_report_paths.size(); 416 options.new_report_paths.size();
409 const size_t set_operations = 417 const size_t set_operations =
410 options.has_set_uploads_enabled + 418 options.has_set_uploads_enabled +
411 (options.set_last_upload_attempt_time_string != nullptr); 419 (options.set_last_upload_attempt_time_string != nullptr);
412 420
413 if (show_operations + set_operations == 0) { 421 if ((options.create ? 1 : 0) + show_operations + set_operations == 0) {
414 ToolSupport::UsageHint(me, "nothing to do"); 422 ToolSupport::UsageHint(me, "nothing to do");
415 return EXIT_FAILURE; 423 return EXIT_FAILURE;
416 } 424 }
417 425
418 scoped_ptr<CrashReportDatabase> database(CrashReportDatabase::Initialize( 426 scoped_ptr<CrashReportDatabase> database;
419 base::FilePath(ToolSupport::CommandLineArgumentToFilePathStringType( 427 base::FilePath database_path = base::FilePath(
420 options.database)))); 428 ToolSupport::CommandLineArgumentToFilePathStringType(options.database));
429 if (options.create) {
430 database = CrashReportDatabase::Initialize(database_path);
431 } else {
432 database = CrashReportDatabase::InitializeWithoutCreating(database_path);
433 }
421 if (!database) { 434 if (!database) {
422 return EXIT_FAILURE; 435 return EXIT_FAILURE;
423 } 436 }
424 437
425 Settings* settings = database->GetSettings(); 438 Settings* settings = database->GetSettings();
426 439
427 // Handle the “show” options before the “set” options so that when they’re 440 // Handle the “show” options before the “set” options so that when they’re
428 // specified together, the “show” option reflects the initial state. 441 // specified together, the “show” option reflects the initial state.
429 442
430 if (options.show_client_id) { 443 if (options.show_client_id) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 605
593 #if defined(OS_POSIX) 606 #if defined(OS_POSIX)
594 int main(int argc, char* argv[]) { 607 int main(int argc, char* argv[]) {
595 return crashpad::DatabaseUtilMain(argc, argv); 608 return crashpad::DatabaseUtilMain(argc, argv);
596 } 609 }
597 #elif defined(OS_WIN) 610 #elif defined(OS_WIN)
598 int wmain(int argc, wchar_t* argv[]) { 611 int wmain(int argc, wchar_t* argv[]) {
599 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::DatabaseUtilMain); 612 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::DatabaseUtilMain);
600 } 613 }
601 #endif // OS_POSIX 614 #endif // OS_POSIX
OLDNEW
« no previous file with comments | « tools/crashpad_database_util.ad ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698