From efa8fdcb8e5cebe08c27d13e5ba27998245a5063 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 5 Jun 2014 17:43:34 +0200 Subject: [PATCH] Error messages: Properly handle livestatus/cmd pipe errors. Refs #6070 --- components/compat/externalcommandlistener.cpp | 36 +++++++++---------- components/livestatus/livestatuslistener.cpp | 8 ++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/components/compat/externalcommandlistener.cpp b/components/compat/externalcommandlistener.cpp index eb9deb85a..c51c6cb76 100644 --- a/components/compat/externalcommandlistener.cpp +++ b/components/compat/externalcommandlistener.cpp @@ -81,19 +81,19 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath) mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) { - BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("mkfifo") - << boost::errinfo_errno(errno) - << boost::errinfo_file_name(commandPath)); + std::ostringstream msgbuf; + msgbuf << "mkfifo() for fifo path '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; + Log(LogCritical, "LivestatusListener", msgbuf.str()); + return; } /* mkfifo() uses umask to mask off some bits, which means we need to chmod() the * fifo to get the right mask. */ if (chmod(commandPath.CStr(), mode) < 0) { - BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("chmod") - << boost::errinfo_errno(errno) - << boost::errinfo_file_name(commandPath)); + std::ostringstream msgbuf; + msgbuf << "chmod() on fifo '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; + Log(LogCritical, "LivestatusListener", msgbuf.str()); + return; } for (;;) { @@ -104,19 +104,19 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath) } while (fd < 0 && errno == EINTR); if (fd < 0) { - BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("open") - << boost::errinfo_errno(errno) - << boost::errinfo_file_name(commandPath)); + std::ostringstream msgbuf; + msgbuf << "open() for fifo path '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; + Log(LogCritical, "LivestatusListener", msgbuf.str()); + return; } FILE *fp = fdopen(fd, "r"); if (fp == NULL) { - (void) close(fd); - BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("fdopen") - << boost::errinfo_errno(errno)); + std::ostringstream msgbuf; + msgbuf << "fdopen() for fifo path '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; + Log(LogCritical, "LivestatusListener", msgbuf.str()); + return; } char line[2048]; @@ -133,9 +133,9 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath) Log(LogInformation, "ExternalCommandListener", "Executing external command: " + command); ExternalCommandProcessor::Execute(command); - } catch (const std::exception& ex) { + } catch (const std::exception&) { std::ostringstream msgbuf; - msgbuf << "External command failed: " << DiagnosticInformation(ex); + msgbuf << "External command failed."; Log(LogWarning, "ExternalCommandListener", msgbuf.str()); } } diff --git a/components/livestatus/livestatuslistener.cpp b/components/livestatus/livestatuslistener.cpp index 57bbdffcd..40fe340fb 100644 --- a/components/livestatus/livestatuslistener.cpp +++ b/components/livestatus/livestatuslistener.cpp @@ -95,10 +95,10 @@ void LivestatusListener::Start(void) mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; if (chmod(GetSocketPath().CStr(), mode) < 0) { - BOOST_THROW_EXCEPTION(posix_error() - << boost::errinfo_api_function("chmod") - << boost::errinfo_errno(errno) - << boost::errinfo_file_name(GetSocketPath())); + std::ostringstream msgbuf; + msgbuf << "chmod() on unix socket '" << GetSocketPath() << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; + Log(LogCritical, "LivestatusListener", msgbuf.str()); + return; } boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket)); -- 2.40.0