mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 00:28:21 +00:00
Fixing bugs in communication.
- The reporter can't be used from the child process. - Don't attempt to send a zero-sized chunk when remote print buffer is empty.
This commit is contained in:
parent
b520f98541
commit
4580bef3e6
4 changed files with 29 additions and 16 deletions
|
@ -195,7 +195,7 @@ bool ChunkedIOFd::WriteChunk(Chunk* chunk, bool partial)
|
|||
assert(chunk->len <= BUFFER_SIZE - sizeof(uint32) );
|
||||
|
||||
if ( chunk->len == 0 )
|
||||
reporter->InternalError("attempt to write 0 bytes chunk");
|
||||
InternalError("attempt to write 0 bytes chunk");
|
||||
|
||||
if ( partial )
|
||||
chunk->len |= FLAG_PARTIAL;
|
||||
|
@ -285,7 +285,7 @@ bool ChunkedIOFd::FlushWriteBuffer()
|
|||
}
|
||||
|
||||
if ( written == 0 )
|
||||
reporter->InternalError("written==0");
|
||||
InternalError("written==0");
|
||||
|
||||
// Short write.
|
||||
write_pos += written;
|
||||
|
@ -906,7 +906,7 @@ bool ChunkedIOSSL::WriteData(char* p, uint32 len, bool* error)
|
|||
return false;
|
||||
}
|
||||
|
||||
reporter->InternalError("can't be reached");
|
||||
InternalError("can't be reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1026,7 +1026,7 @@ bool ChunkedIOSSL::ReadData(char* p, uint32 len, bool* error)
|
|||
}
|
||||
|
||||
// Can't be reached.
|
||||
reporter->InternalError("can't be reached");
|
||||
InternalError("can't be reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,11 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
void InternalError(const char* msg)
|
||||
// We can't use the reporter here as we might be running in a
|
||||
// sub-process.
|
||||
{ fprintf(stderr, "%s", msg); abort(); }
|
||||
|
||||
Statistics stats;
|
||||
const char* tag;
|
||||
|
||||
|
|
|
@ -2375,7 +2375,7 @@ bool RemoteSerializer::FlushPrintBuffer(Peer* p)
|
|||
if ( p->state == Peer::CLOSING )
|
||||
return false;
|
||||
|
||||
if ( ! p->print_buffer )
|
||||
if ( ! (p->print_buffer && p->print_buffer_used) )
|
||||
return true;
|
||||
|
||||
SendToChild(MSG_REMOTE_PRINT, p, p->print_buffer, p->print_buffer_used);
|
||||
|
@ -3407,11 +3407,11 @@ bool SocketComm::ProcessParentMessage()
|
|||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("unknown msg type %d", parent_msgtype);
|
||||
InternalError(fmt("unknown msg type %d", parent_msgtype));
|
||||
return true;
|
||||
}
|
||||
|
||||
reporter->InternalError("cannot be reached");
|
||||
InternalError("cannot be reached");
|
||||
}
|
||||
|
||||
case ARGS:
|
||||
|
@ -3434,10 +3434,10 @@ bool SocketComm::ProcessParentMessage()
|
|||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("unknown msgstate");
|
||||
InternalError("unknown msgstate");
|
||||
}
|
||||
|
||||
reporter->InternalError("cannot be reached");
|
||||
InternalError("cannot be reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3496,7 +3496,7 @@ bool SocketComm::DoParentMessage()
|
|||
peers[j]->io->DumpDebugData(fmt("comm-dump.child.peer.%d", id), false);
|
||||
}
|
||||
#else
|
||||
reporter->InternalError("DEBUG_DUMP support not compiled in");
|
||||
InternalError("DEBUG_DUMP support not compiled in");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -3556,10 +3556,10 @@ bool SocketComm::DoParentMessage()
|
|||
return ForwardChunkToPeer();
|
||||
|
||||
default:
|
||||
reporter->InternalError("ProcessParentMessage: unexpected state");
|
||||
InternalError("ProcessParentMessage: unexpected state");
|
||||
}
|
||||
|
||||
reporter->InternalError("cannot be reached");
|
||||
InternalError("cannot be reached");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -3620,7 +3620,7 @@ bool SocketComm::ProcessListen()
|
|||
bool SocketComm::ProcessParentCompress()
|
||||
{
|
||||
#ifndef HAVE_LIBZ
|
||||
reporter->InternalError("supposed to enable compression but don't have zlib");
|
||||
InternalError("supposed to enable compression but don't have zlib");
|
||||
return false;
|
||||
#else
|
||||
|
||||
|
@ -3740,11 +3740,10 @@ bool SocketComm::ProcessRemoteMessage(SocketComm::Peer* peer)
|
|||
}
|
||||
|
||||
default:
|
||||
reporter->InternalError("ProcessRemoteMessage: unexpected state");
|
||||
InternalError("ProcessRemoteMessage: unexpected state");
|
||||
}
|
||||
|
||||
assert(false); // Cannot be reached.
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SocketComm::ForwardChunkToParent(Peer* peer, ChunkedIO::Chunk* c)
|
||||
|
@ -4051,6 +4050,12 @@ void SocketComm::Log(const char* msg, Peer* peer)
|
|||
DEBUG_COMM(fmt("child: %s", buffer));
|
||||
}
|
||||
|
||||
void SocketComm::InternalError(const char* msg)
|
||||
{
|
||||
fprintf(stderr, "interal error in child: %s\n", msg);
|
||||
Kill();
|
||||
}
|
||||
|
||||
void SocketComm::Kill()
|
||||
{
|
||||
if ( killing )
|
||||
|
|
|
@ -463,6 +463,9 @@ protected:
|
|||
// Check whether everything has been sent out.
|
||||
void CheckFinished();
|
||||
|
||||
// Reports the error and terminates the process.
|
||||
void InternalError(const char* msg);
|
||||
|
||||
// Communication helpers.
|
||||
bool SendToParent(char type, Peer* peer, const char* str, int len = -1);
|
||||
bool SendToParent(char type, Peer* peer, int nargs, ...); // can send uints32 only
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue