Error messages: Properly handle livestatus/cmd pipe errors.

Refs #6070
This commit is contained in:
Michael Friedrich 2014-06-05 17:43:34 +02:00
parent f0b0420256
commit efa8fdcb8e
2 changed files with 22 additions and 22 deletions

View File

@ -81,19 +81,19 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; 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) { if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0) {
BOOST_THROW_EXCEPTION(posix_error() std::ostringstream msgbuf;
<< boost::errinfo_api_function("mkfifo") msgbuf << "mkfifo() for fifo path '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
<< boost::errinfo_errno(errno) Log(LogCritical, "LivestatusListener", msgbuf.str());
<< boost::errinfo_file_name(commandPath)); return;
} }
/* mkfifo() uses umask to mask off some bits, which means we need to chmod() the /* mkfifo() uses umask to mask off some bits, which means we need to chmod() the
* fifo to get the right mask. */ * fifo to get the right mask. */
if (chmod(commandPath.CStr(), mode) < 0) { if (chmod(commandPath.CStr(), mode) < 0) {
BOOST_THROW_EXCEPTION(posix_error() std::ostringstream msgbuf;
<< boost::errinfo_api_function("chmod") msgbuf << "chmod() on fifo '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
<< boost::errinfo_errno(errno) Log(LogCritical, "LivestatusListener", msgbuf.str());
<< boost::errinfo_file_name(commandPath)); return;
} }
for (;;) { for (;;) {
@ -104,19 +104,19 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
} while (fd < 0 && errno == EINTR); } while (fd < 0 && errno == EINTR);
if (fd < 0) { if (fd < 0) {
BOOST_THROW_EXCEPTION(posix_error() std::ostringstream msgbuf;
<< boost::errinfo_api_function("open") msgbuf << "open() for fifo path '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
<< boost::errinfo_errno(errno) Log(LogCritical, "LivestatusListener", msgbuf.str());
<< boost::errinfo_file_name(commandPath)); return;
} }
FILE *fp = fdopen(fd, "r"); FILE *fp = fdopen(fd, "r");
if (fp == NULL) { if (fp == NULL) {
(void) close(fd); std::ostringstream msgbuf;
BOOST_THROW_EXCEPTION(posix_error() msgbuf << "fdopen() for fifo path '" << commandPath << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
<< boost::errinfo_api_function("fdopen") Log(LogCritical, "LivestatusListener", msgbuf.str());
<< boost::errinfo_errno(errno)); return;
} }
char line[2048]; char line[2048];
@ -133,9 +133,9 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
Log(LogInformation, "ExternalCommandListener", "Executing external command: " + command); Log(LogInformation, "ExternalCommandListener", "Executing external command: " + command);
ExternalCommandProcessor::Execute(command); ExternalCommandProcessor::Execute(command);
} catch (const std::exception& ex) { } catch (const std::exception&) {
std::ostringstream msgbuf; std::ostringstream msgbuf;
msgbuf << "External command failed: " << DiagnosticInformation(ex); msgbuf << "External command failed.";
Log(LogWarning, "ExternalCommandListener", msgbuf.str()); Log(LogWarning, "ExternalCommandListener", msgbuf.str());
} }
} }

View File

@ -95,10 +95,10 @@ void LivestatusListener::Start(void)
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
if (chmod(GetSocketPath().CStr(), mode) < 0) { if (chmod(GetSocketPath().CStr(), mode) < 0) {
BOOST_THROW_EXCEPTION(posix_error() std::ostringstream msgbuf;
<< boost::errinfo_api_function("chmod") msgbuf << "chmod() on unix socket '" << GetSocketPath() << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
<< boost::errinfo_errno(errno) Log(LogCritical, "LivestatusListener", msgbuf.str());
<< boost::errinfo_file_name(GetSocketPath())); return;
} }
boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket)); boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket));