mirror of
https://github.com/zeek/zeek.git
synced 2025-10-07 00:58:19 +00:00
Fix possible abort on writing to a full pipe.
This commit is contained in:
parent
26887dd71b
commit
77955d7677
1 changed files with 16 additions and 2 deletions
18
src/Flare.cc
18
src/Flare.cc
|
@ -1,7 +1,6 @@
|
||||||
// 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 "util.h"
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -16,7 +15,21 @@ Flare::Flare()
|
||||||
void Flare::Fire()
|
void Flare::Fire()
|
||||||
{
|
{
|
||||||
char tmp;
|
char tmp;
|
||||||
safe_write(pipe.WriteFD(), &tmp, 1);
|
|
||||||
|
for ( ; ; )
|
||||||
|
{
|
||||||
|
int n = write(pipe.WriteFD(), &tmp, 1);
|
||||||
|
|
||||||
|
if ( n > 0 )
|
||||||
|
// Success -- wrote a byte to pipe.
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( n < 0 && 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.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flare::Extinguish()
|
void Flare::Extinguish()
|
||||||
|
@ -25,5 +38,6 @@ void Flare::Extinguish()
|
||||||
|
|
||||||
for ( ; ; )
|
for ( ; ; )
|
||||||
if ( read(pipe.ReadFD(), &tmp, sizeof(tmp)) == -1 && errno == EAGAIN )
|
if ( read(pipe.ReadFD(), &tmp, sizeof(tmp)) == -1 && errno == EAGAIN )
|
||||||
|
// Pipe is now drained.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue