]> granicus.if.org Git - icinga2/commitdiff
Livestatus: Fix crash when socket exception is thrown during query reponse.
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 6 Nov 2013 17:54:01 +0000 (18:54 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 6 Nov 2013 17:54:01 +0000 (18:54 +0100)
Fixes #4619

components/livestatus/query.cpp

index 96ed9e9c0b36da3fda7628ef8ddcc82d0258be58..f6d4ebb5c07cbec1311b872733d86bf58dbb41ff 100644 (file)
@@ -477,8 +477,16 @@ void Query::SendResponse(const Stream::Ptr& stream, int code, const String& data
        if (m_ResponseHeader == "fixed16")
                PrintFixed16(stream, code, data);
 
-       if (m_ResponseHeader == "fixed16" || code == LivestatusErrorOK)
-               stream->Write(data.CStr(), data.GetLength());
+       if (m_ResponseHeader == "fixed16" || code == LivestatusErrorOK) {
+               try {
+                       stream->Write(data.CStr(), data.GetLength());
+               } catch (const std::exception& ex) {
+                       std::ostringstream info;
+                       info << "Exception thrown while writing to the livestatus socket: " << std::endl
+                            << boost::diagnostic_information(ex);
+                       Log(LogCritical, "livestatus", info.str());
+               }
+       }
 }
 
 void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data)
@@ -490,7 +498,14 @@ void Query::PrintFixed16(const Stream::Ptr& stream, int code, const String& data
 
        String header = sCode + String(16 - 3 - sLength.GetLength() - 1, ' ') + sLength + m_Separators[0];
 
-       stream->Write(header.CStr(), header.GetLength());
+       try {
+               stream->Write(header.CStr(), header.GetLength());
+       } catch (const std::exception& ex) {
+               std::ostringstream info;
+               info << "Exception thrown while writing to the livestatus socket: " << std::endl
+                    << boost::diagnostic_information(ex);
+               Log(LogCritical, "livestatus", info.str());
+       }
 }
 
 bool Query::Execute(const Stream::Ptr& stream)