mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
Make unexpected pipe errors fatal as precaution.
Addresses BIT-1260.
This commit is contained in:
parent
cce09b75de
commit
57d0346789
1 changed files with 37 additions and 6 deletions
43
src/Flare.cc
43
src/Flare.cc
|
@ -1,6 +1,7 @@
|
||||||
// See the file "COPYING" in the main distribution directory for copyright.
|
// See the file "COPYING" in the main distribution directory for copyright.
|
||||||
|
|
||||||
#include "Flare.h"
|
#include "Flare.h"
|
||||||
|
#include "Reporter.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -12,6 +13,13 @@ Flare::Flare()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bad_pipe_op(const char* which)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
strerror_r(errno, buf, sizeof(buf));
|
||||||
|
reporter->FatalErrorWithCore("unexpected pipe %s failure: %s", which, buf);
|
||||||
|
}
|
||||||
|
|
||||||
void Flare::Fire()
|
void Flare::Fire()
|
||||||
{
|
{
|
||||||
char tmp;
|
char tmp;
|
||||||
|
@ -24,11 +32,20 @@ void Flare::Fire()
|
||||||
// Success -- wrote a byte to pipe.
|
// Success -- wrote a byte to pipe.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if ( n < 0 && errno == EAGAIN )
|
if ( n < 0 )
|
||||||
// Success -- pipe is full and just need at least one byte in it.
|
{
|
||||||
break;
|
if ( errno == EAGAIN )
|
||||||
|
// Success: pipe is full and just need at least one byte in it.
|
||||||
|
break;
|
||||||
|
|
||||||
// Loop because either the byte wasn't written or got EINTR error.
|
if ( errno == EINTR )
|
||||||
|
// Interrupted: try again.
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bad_pipe_op("write");
|
||||||
|
}
|
||||||
|
|
||||||
|
// No error, but didn't write a byte: try again.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +54,21 @@ void Flare::Extinguish()
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
|
|
||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
if ( read(pipe.ReadFD(), &tmp, sizeof(tmp)) == -1 && errno == EAGAIN )
|
{
|
||||||
// Pipe is now drained.
|
int n = read(pipe.ReadFD(), &tmp, sizeof(tmp));
|
||||||
|
|
||||||
|
if ( n >= 0 )
|
||||||
|
// Pipe may not be empty yet: try again.
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( errno == EAGAIN )
|
||||||
|
// Success: pipe is now empty.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if ( errno == EINTR )
|
||||||
|
// Interrupted: try again.
|
||||||
|
continue;
|
||||||
|
|
||||||
|
bad_pipe_op("read");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue