Resolve outstanding stdin parsing issues by buffering the data.
This commit is contained in:
parent
e6c44a586f
commit
e4c7b1753b
3 changed files with 19 additions and 3 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 1f41e59a4dae47720d0aacb422548b45be0daa19
|
||||
Subproject commit fccfbd741a0fd974945bb259854768cc70258f07
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 699016bfd00e2be7f13120f314a4f976eeacadd6
|
||||
Subproject commit 31ab2c052edb3e72fc1fda385d6d118c479407f3
|
||||
|
|
@ -216,7 +216,23 @@ std::size_t session_t::read_data(journal_t& journal,
|
|||
if (data_file == "-") {
|
||||
use_cache = false;
|
||||
journal.sources.push_back("/dev/stdin");
|
||||
entry_count += read_journal(journal, std::cin, "/dev/stdin", acct);
|
||||
|
||||
// To avoid problems with stdin and pipes, etc., we read the entire
|
||||
// file in beforehand into a memory buffer, and then parcel it out
|
||||
// from there.
|
||||
std::ostringstream buffer;
|
||||
|
||||
while (std::cin.good() && ! std::cin.eof()) {
|
||||
static char line[8192];
|
||||
std::cin.read(line, 8192);
|
||||
std::streamsize count = std::cin.gcount();
|
||||
buffer.write(line, count);
|
||||
}
|
||||
buffer.flush();
|
||||
|
||||
std::istringstream buf_in(buffer.str());
|
||||
|
||||
entry_count += read_journal(journal, buf_in, "/dev/stdin", acct);
|
||||
}
|
||||
else if (exists(data_file)) {
|
||||
entry_count += read_journal(journal, data_file, acct);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue