Index: tools/crashpad_database_util.cc |
diff --git a/tools/crashpad_database_util.cc b/tools/crashpad_database_util.cc |
index cd5a2195bd5b2146a1abb28ee0b3dabfea8c329b..47b00818f391c1d98711c45663aefd3353582292 100644 |
--- a/tools/crashpad_database_util.cc |
+++ b/tools/crashpad_database_util.cc |
@@ -56,7 +56,7 @@ void Usage(const std::string& me) { |
" --set-uploads-enabled=BOOL enable or disable uploads\n" |
" --set-last-upload-attempt-time=TIME\n" |
" set the last-upload-attempt time to TIME\n" |
-" --new-report=PATH submit a new report at PATH\n" |
+" --new-report=PATH submit a new report at PATH, or - for stdin\n" |
" --utc show and set UTC times instead of local\n" |
" --help display this help and exit\n" |
" --version output version information and exit\n", |
@@ -518,9 +518,17 @@ int DatabaseUtilMain(int argc, char* argv[]) { |
} |
for (const base::FilePath new_report_path : options.new_report_paths) { |
- FileReader file_reader; |
- if (!file_reader.Open(new_report_path)) { |
- return EXIT_FAILURE; |
+ scoped_ptr<FileReaderInterface> file_reader; |
+ |
+ if (new_report_path.value() == "-") { |
+ file_reader.reset(new WeakStdioFileReader(stdin)); |
+ } else { |
+ scoped_ptr<FileReader> file_path_reader(new FileReader()); |
+ if (!file_path_reader->Open(new_report_path)) { |
+ return EXIT_FAILURE; |
+ } |
+ |
+ file_reader = file_path_reader.Pass(); |
} |
CrashReportDatabase::NewReport* new_report; |
@@ -535,7 +543,7 @@ int DatabaseUtilMain(int argc, char* argv[]) { |
char buf[4096]; |
ssize_t read_result; |
- while ((read_result = file_reader.Read(buf, sizeof(buf))) > 0) { |
+ while ((read_result = file_reader->Read(buf, sizeof(buf))) > 0) { |
if (!LoggingWriteFile(new_report->handle, buf, read_result)) { |
return EXIT_FAILURE; |
} |
@@ -552,6 +560,13 @@ int DatabaseUtilMain(int argc, char* argv[]) { |
return EXIT_FAILURE; |
} |
+ file_reader.reset(); |
+ if (new_report_path.value() == "-") { |
+ if (fclose(stdin) == EOF) { |
+ STDIO_PLOG(ERROR) << "fclose"; |
+ } |
+ } |
+ |
const char* prefix = (show_operations > 1) ? "New report ID: " : ""; |
printf("%s%s\n", prefix, uuid.ToString().c_str()); |
} |