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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 !settings->SetUploadsEnabled(options.set_uploads_enabled)) { | 553 !settings->SetUploadsEnabled(options.set_uploads_enabled)) { |
554 return EXIT_FAILURE; | 554 return EXIT_FAILURE; |
555 } | 555 } |
556 | 556 |
557 if (options.set_last_upload_attempt_time_string && | 557 if (options.set_last_upload_attempt_time_string && |
558 !settings->SetLastUploadAttemptTime( | 558 !settings->SetLastUploadAttemptTime( |
559 options.set_last_upload_attempt_time)) { | 559 options.set_last_upload_attempt_time)) { |
560 return EXIT_FAILURE; | 560 return EXIT_FAILURE; |
561 } | 561 } |
562 | 562 |
| 563 bool used_stdin = false; |
563 for (const base::FilePath new_report_path : options.new_report_paths) { | 564 for (const base::FilePath new_report_path : options.new_report_paths) { |
564 std::unique_ptr<FileReaderInterface> file_reader; | 565 std::unique_ptr<FileReaderInterface> file_reader; |
565 | 566 |
566 bool is_stdin = false; | |
567 if (new_report_path.value() == FILE_PATH_LITERAL("-")) { | 567 if (new_report_path.value() == FILE_PATH_LITERAL("-")) { |
568 is_stdin = true; | 568 if (used_stdin) { |
569 file_reader.reset(new WeakStdioFileReader(stdin)); | 569 fprintf(stderr, |
| 570 "%" PRFilePath |
| 571 ": Only one --new-report may be read from standard input\n", |
| 572 me.value().c_str()); |
| 573 return EXIT_FAILURE; |
| 574 } |
| 575 used_stdin = true; |
| 576 file_reader.reset(new WeakFileHandleFileReader( |
| 577 StdioFileHandle(StdioStream::kStandardInput))); |
570 } else { | 578 } else { |
571 std::unique_ptr<FileReader> file_path_reader(new FileReader()); | 579 std::unique_ptr<FileReader> file_path_reader(new FileReader()); |
572 if (!file_path_reader->Open(new_report_path)) { | 580 if (!file_path_reader->Open(new_report_path)) { |
573 return EXIT_FAILURE; | 581 return EXIT_FAILURE; |
574 } | 582 } |
575 | 583 |
576 file_reader = std::move(file_path_reader); | 584 file_reader = std::move(file_path_reader); |
577 } | 585 } |
578 | 586 |
579 CrashReportDatabase::NewReport* new_report; | 587 CrashReportDatabase::NewReport* new_report; |
(...skipping 10 matching lines...) Expand all Loading... |
590 FileOperationResult read_result; | 598 FileOperationResult read_result; |
591 do { | 599 do { |
592 read_result = file_reader->Read(buf, sizeof(buf)); | 600 read_result = file_reader->Read(buf, sizeof(buf)); |
593 if (read_result < 0) { | 601 if (read_result < 0) { |
594 return EXIT_FAILURE; | 602 return EXIT_FAILURE; |
595 } | 603 } |
596 if (read_result > 0 && | 604 if (read_result > 0 && |
597 !LoggingWriteFile(new_report->handle, buf, read_result)) { | 605 !LoggingWriteFile(new_report->handle, buf, read_result)) { |
598 return EXIT_FAILURE; | 606 return EXIT_FAILURE; |
599 } | 607 } |
600 } while (read_result == sizeof(buf)); | 608 } while (read_result > 0); |
601 | 609 |
602 call_error_writing_crash_report.Disarm(); | 610 call_error_writing_crash_report.Disarm(); |
603 | 611 |
604 UUID uuid; | 612 UUID uuid; |
605 status = database->FinishedWritingCrashReport(new_report, &uuid); | 613 status = database->FinishedWritingCrashReport(new_report, &uuid); |
606 if (status != CrashReportDatabase::kNoError) { | 614 if (status != CrashReportDatabase::kNoError) { |
607 return EXIT_FAILURE; | 615 return EXIT_FAILURE; |
608 } | 616 } |
609 | 617 |
610 file_reader.reset(); | |
611 if (is_stdin) { | |
612 if (fclose(stdin) == EOF) { | |
613 STDIO_PLOG(ERROR) << "fclose"; | |
614 } | |
615 } | |
616 | |
617 const char* prefix = (show_operations > 1) ? "New report ID: " : ""; | 618 const char* prefix = (show_operations > 1) ? "New report ID: " : ""; |
618 printf("%s%s\n", prefix, uuid.ToString().c_str()); | 619 printf("%s%s\n", prefix, uuid.ToString().c_str()); |
619 } | 620 } |
620 | 621 |
621 return EXIT_SUCCESS; | 622 return EXIT_SUCCESS; |
622 } | 623 } |
623 | 624 |
624 } // namespace | 625 } // namespace |
625 } // namespace crashpad | 626 } // namespace crashpad |
626 | 627 |
627 #if defined(OS_POSIX) | 628 #if defined(OS_POSIX) |
628 int main(int argc, char* argv[]) { | 629 int main(int argc, char* argv[]) { |
629 return crashpad::DatabaseUtilMain(argc, argv); | 630 return crashpad::DatabaseUtilMain(argc, argv); |
630 } | 631 } |
631 #elif defined(OS_WIN) | 632 #elif defined(OS_WIN) |
632 int wmain(int argc, wchar_t* argv[]) { | 633 int wmain(int argc, wchar_t* argv[]) { |
633 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::DatabaseUtilMain); | 634 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::DatabaseUtilMain); |
634 } | 635 } |
635 #endif // OS_POSIX | 636 #endif // OS_POSIX |
OLD | NEW |