OLD | NEW |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 " --show-uploads-enabled show whether uploads are enabled\n" | 51 " --show-uploads-enabled show whether uploads are enabled\n" |
52 " --show-last-upload-attempt-time\n" | 52 " --show-last-upload-attempt-time\n" |
53 " show the last-upload-attempt time\n" | 53 " show the last-upload-attempt time\n" |
54 " --show-pending-reports show reports eligible for upload\n" | 54 " --show-pending-reports show reports eligible for upload\n" |
55 " --show-completed-reports show reports not eligible for upload\n" | 55 " --show-completed-reports show reports not eligible for upload\n" |
56 " --show-all-report-info with --show-*-reports, show more information\
n" | 56 " --show-all-report-info with --show-*-reports, show more information\
n" |
57 " --show-report=UUID show report stored under UUID\n" | 57 " --show-report=UUID show report stored under UUID\n" |
58 " --set-uploads-enabled=BOOL enable or disable uploads\n" | 58 " --set-uploads-enabled=BOOL enable or disable uploads\n" |
59 " --set-last-upload-attempt-time=TIME\n" | 59 " --set-last-upload-attempt-time=TIME\n" |
60 " set the last-upload-attempt time to TIME\n" | 60 " set the last-upload-attempt time to TIME\n" |
61 " --new-report=PATH submit a new report at PATH\n" | 61 " --new-report=PATH submit a new report at PATH, or - for stdin\n
" |
62 " --utc show and set UTC times instead of local\n" | 62 " --utc show and set UTC times instead of local\n" |
63 " --help display this help and exit\n" | 63 " --help display this help and exit\n" |
64 " --version output version information and exit\n", | 64 " --version output version information and exit\n", |
65 me.value().c_str()); | 65 me.value().c_str()); |
66 ToolSupport::UsageTail(me); | 66 ToolSupport::UsageTail(me); |
67 } | 67 } |
68 | 68 |
69 struct Options { | 69 struct Options { |
70 std::vector<UUID> show_reports; | 70 std::vector<UUID> show_reports; |
71 std::vector<base::FilePath> new_report_paths; | 71 std::vector<base::FilePath> new_report_paths; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 return EXIT_FAILURE; | 520 return EXIT_FAILURE; |
521 } | 521 } |
522 | 522 |
523 if (options.set_last_upload_attempt_time_string && | 523 if (options.set_last_upload_attempt_time_string && |
524 !settings->SetLastUploadAttemptTime( | 524 !settings->SetLastUploadAttemptTime( |
525 options.set_last_upload_attempt_time)) { | 525 options.set_last_upload_attempt_time)) { |
526 return EXIT_FAILURE; | 526 return EXIT_FAILURE; |
527 } | 527 } |
528 | 528 |
529 for (const base::FilePath new_report_path : options.new_report_paths) { | 529 for (const base::FilePath new_report_path : options.new_report_paths) { |
530 FileReader file_reader; | 530 scoped_ptr<FileReaderInterface> file_reader; |
531 if (!file_reader.Open(new_report_path)) { | 531 |
532 return EXIT_FAILURE; | 532 bool is_stdin = false; |
| 533 if (new_report_path.value() == FILE_PATH_LITERAL("-")) { |
| 534 is_stdin = true; |
| 535 file_reader.reset(new WeakStdioFileReader(stdin)); |
| 536 } else { |
| 537 scoped_ptr<FileReader> file_path_reader(new FileReader()); |
| 538 if (!file_path_reader->Open(new_report_path)) { |
| 539 return EXIT_FAILURE; |
| 540 } |
| 541 |
| 542 file_reader = file_path_reader.Pass(); |
533 } | 543 } |
534 | 544 |
535 CrashReportDatabase::NewReport* new_report; | 545 CrashReportDatabase::NewReport* new_report; |
536 CrashReportDatabase::OperationStatus status = | 546 CrashReportDatabase::OperationStatus status = |
537 database->PrepareNewCrashReport(&new_report); | 547 database->PrepareNewCrashReport(&new_report); |
538 if (status != CrashReportDatabase::kNoError) { | 548 if (status != CrashReportDatabase::kNoError) { |
539 return EXIT_FAILURE; | 549 return EXIT_FAILURE; |
540 } | 550 } |
541 | 551 |
542 CrashReportDatabase::CallErrorWritingCrashReport | 552 CrashReportDatabase::CallErrorWritingCrashReport |
543 call_error_writing_crash_report(database.get(), new_report); | 553 call_error_writing_crash_report(database.get(), new_report); |
544 | 554 |
545 char buf[4096]; | 555 char buf[4096]; |
546 ssize_t read_result; | 556 ssize_t read_result; |
547 while ((read_result = file_reader.Read(buf, sizeof(buf))) > 0) { | 557 do { |
548 if (!LoggingWriteFile(new_report->handle, buf, read_result)) { | 558 read_result = file_reader->Read(buf, sizeof(buf)); |
| 559 if (read_result < 0) { |
549 return EXIT_FAILURE; | 560 return EXIT_FAILURE; |
550 } | 561 } |
551 } | 562 if (read_result > 0 && |
552 if (read_result < 0) { | 563 !LoggingWriteFile(new_report->handle, buf, read_result)) { |
553 return EXIT_FAILURE; | 564 return EXIT_FAILURE; |
554 } | 565 } |
| 566 } while (read_result == sizeof(buf)); |
555 | 567 |
556 call_error_writing_crash_report.Disarm(); | 568 call_error_writing_crash_report.Disarm(); |
557 | 569 |
558 UUID uuid; | 570 UUID uuid; |
559 status = database->FinishedWritingCrashReport(new_report, &uuid); | 571 status = database->FinishedWritingCrashReport(new_report, &uuid); |
560 if (status != CrashReportDatabase::kNoError) { | 572 if (status != CrashReportDatabase::kNoError) { |
561 return EXIT_FAILURE; | 573 return EXIT_FAILURE; |
562 } | 574 } |
563 | 575 |
| 576 file_reader.reset(); |
| 577 if (is_stdin) { |
| 578 if (fclose(stdin) == EOF) { |
| 579 STDIO_PLOG(ERROR) << "fclose"; |
| 580 } |
| 581 } |
| 582 |
564 const char* prefix = (show_operations > 1) ? "New report ID: " : ""; | 583 const char* prefix = (show_operations > 1) ? "New report ID: " : ""; |
565 printf("%s%s\n", prefix, uuid.ToString().c_str()); | 584 printf("%s%s\n", prefix, uuid.ToString().c_str()); |
566 } | 585 } |
567 | 586 |
568 return EXIT_SUCCESS; | 587 return EXIT_SUCCESS; |
569 } | 588 } |
570 | 589 |
571 } // namespace | 590 } // namespace |
572 } // namespace crashpad | 591 } // namespace crashpad |
573 | 592 |
574 #if defined(OS_POSIX) | 593 #if defined(OS_POSIX) |
575 int main(int argc, char* argv[]) { | 594 int main(int argc, char* argv[]) { |
576 return crashpad::DatabaseUtilMain(argc, argv); | 595 return crashpad::DatabaseUtilMain(argc, argv); |
577 } | 596 } |
578 #elif defined(OS_WIN) | 597 #elif defined(OS_WIN) |
579 int wmain(int argc, wchar_t* argv[]) { | 598 int wmain(int argc, wchar_t* argv[]) { |
580 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::DatabaseUtilMain); | 599 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::DatabaseUtilMain); |
581 } | 600 } |
582 #endif // OS_POSIX | 601 #endif // OS_POSIX |
OLD | NEW |