diff --git a/src/ChunkedIO.cc b/src/ChunkedIO.cc index d2eff510ce..d54b4eb70b 100644 --- a/src/ChunkedIO.cc +++ b/src/ChunkedIO.cc @@ -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; } diff --git a/src/ChunkedIO.h b/src/ChunkedIO.h index 516f0f7ddc..1f946c18ba 100644 --- a/src/ChunkedIO.h +++ b/src/ChunkedIO.h @@ -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; diff --git a/src/RemoteSerializer.cc b/src/RemoteSerializer.cc index c4869e4328..af52683b76 100644 --- a/src/RemoteSerializer.cc +++ b/src/RemoteSerializer.cc @@ -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 ) diff --git a/src/RemoteSerializer.h b/src/RemoteSerializer.h index 20886544c6..68e7dfa0c7 100644 --- a/src/RemoteSerializer.h +++ b/src/RemoteSerializer.h @@ -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