mirror of
https://github.com/zeek/zeek.git
synced 2025-10-12 03:28:19 +00:00
Unlock mutex in raw input reader error cases - BIT-1060
This commit is contained in:
parent
29910e7e7a
commit
f3950da009
2 changed files with 24 additions and 10 deletions
|
@ -90,6 +90,24 @@ void Raw::ClosePipeEnd(int i)
|
||||||
pipes[i] = -1;
|
pipes[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Raw::LockForkMutex()
|
||||||
|
{
|
||||||
|
int res = pthread_mutex_lock(&fork_mutex);
|
||||||
|
if ( res == 0 )
|
||||||
|
return true;
|
||||||
|
Error(Fmt("cannot lock fork mutex: %d", res));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Raw::UnlockForkMutex()
|
||||||
|
{
|
||||||
|
int res = pthread_mutex_unlock(&fork_mutex);
|
||||||
|
if ( res == 0 )
|
||||||
|
return true;
|
||||||
|
Error(Fmt("cannot unlock fork mutex: %d", res));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Raw::Execute()
|
bool Raw::Execute()
|
||||||
{
|
{
|
||||||
// TODO: AFAICT, pipe/fork/exec should be thread-safe, but actually having
|
// TODO: AFAICT, pipe/fork/exec should be thread-safe, but actually having
|
||||||
|
@ -99,15 +117,12 @@ bool Raw::Execute()
|
||||||
// individually or sequentially, that issue never crops up... ("never"
|
// individually or sequentially, that issue never crops up... ("never"
|
||||||
// meaning I haven't seen in it in hundreds of tests using 50+ threads
|
// meaning I haven't seen in it in hundreds of tests using 50+ threads
|
||||||
// where before I'd see the issue w/ just 2 threads ~33% of the time).
|
// where before I'd see the issue w/ just 2 threads ~33% of the time).
|
||||||
int lock_rval = pthread_mutex_lock(&fork_mutex);
|
if ( ! LockForkMutex() )
|
||||||
if ( lock_rval != 0 )
|
|
||||||
{
|
|
||||||
Error(Fmt("cannot lock fork mutex: %d", lock_rval));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if ( pipe(pipes) != 0 || pipe(pipes+2) || pipe(pipes+4) )
|
if ( pipe(pipes) != 0 || pipe(pipes+2) || pipe(pipes+4) )
|
||||||
{
|
{
|
||||||
|
UnlockForkMutex();
|
||||||
Error(Fmt("Could not open pipe: %d", errno));
|
Error(Fmt("Could not open pipe: %d", errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +130,7 @@ bool Raw::Execute()
|
||||||
childpid = fork();
|
childpid = fork();
|
||||||
if ( childpid < 0 )
|
if ( childpid < 0 )
|
||||||
{
|
{
|
||||||
|
UnlockForkMutex();
|
||||||
Error(Fmt("Could not create child process: %d", errno));
|
Error(Fmt("Could not create child process: %d", errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -144,12 +160,8 @@ bool Raw::Execute()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we are the parent
|
// we are the parent
|
||||||
lock_rval = pthread_mutex_unlock(&fork_mutex);
|
if ( ! UnlockForkMutex() )
|
||||||
if ( lock_rval != 0 )
|
|
||||||
{
|
|
||||||
Error(Fmt("cannot unlock fork mutex: %d", lock_rval));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
ClosePipeEnd(stdout_out);
|
ClosePipeEnd(stdout_out);
|
||||||
if ( Info().mode == MODE_STREAM )
|
if ( Info().mode == MODE_STREAM )
|
||||||
|
|
|
@ -32,6 +32,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void ClosePipeEnd(int i);
|
void ClosePipeEnd(int i);
|
||||||
|
bool LockForkMutex();
|
||||||
|
bool UnlockForkMutex();
|
||||||
|
|
||||||
bool OpenInput();
|
bool OpenInput();
|
||||||
bool CloseInput();
|
bool CloseInput();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue