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