make reading from stdout and stderr simultaneously work.

Needs a few test-cases - but seems ok...
This commit is contained in:
Bernhard Amann 2013-03-16 09:54:48 -07:00
parent 3aeec7ec14
commit 6fef99ee03
4 changed files with 274 additions and 26 deletions

View file

@ -0,0 +1,148 @@
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
..:
F
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
bro
F
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
executestreamrawstderr.bro
F
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
out
F
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
ls: ../nonexistant: No such file or directory
T
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
ls: ../nonexistant2: No such file or directory
T
[source=ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |, reader=Input::READER_RAW, mode=Input::MANUAL, name=input, fields=<no value description>, want_record=F, ev=line
{
print A::outfile, A::description;
print A::outfile, A::tpe;
print A::outfile, A::s;
print A::outfile, A::is_stderr;
A::try = A::try + 1;
if (7 == A::try)
{
print A::outfile, done;
close(A::outfile);
Input::remove(input);
terminate();
}
}, config={
[read_stderr] = 1
}]
Input::EVENT_NEW
ls: ../nonexistant3: No such file or directory
T
done

View file

@ -0,0 +1,44 @@
# @TEST-EXEC: btest-bg-run bro bro -b %INPUT
# @TEST-EXEC: btest-bg-wait -k 5
# @TEST-EXEC: btest-diff out
redef exit_only_after_terminate = T;
module A;
type Val: record {
s: string;
is_stderr: bool;
};
global try: count;
global outfile: file;
event line(description: Input::EventDescription, tpe: Input::Event, s: string, is_stderr: bool)
{
print outfile, description;
print outfile, tpe;
print outfile, s;
print outfile, is_stderr;
try = try + 1;
if ( try == 7 )
{
print outfile, "done";
close(outfile);
Input::remove("input");
terminate();
}
}
event bro_init()
{
local config_strings: table[string] of string = {
["read_stderr"] = "1"
};
outfile = open("../out");
try = 0;
Input::add_event([$source="ls .. ../nonexistant ../nonexistant2 ../nonexistant3 |", $reader=Input::READER_RAW, $name="input", $fields=Val, $ev=line, $want_record=F, $config=config_strings]);
}