Skip to content

Commit

Permalink
Error messages: Properly handle livestatus/cmd pipe errors.
Browse files Browse the repository at this point in the history
Refs #6070
  • Loading branch information
Michael Friedrich committed Jun 5, 2014
1 parent f0b0420 commit efa8fdc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions components/compat/externalcommandlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand All @@ -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];
Expand All @@ -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());
}
}
Expand Down
8 changes: 4 additions & 4 deletions components/livestatus/livestatuslistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit efa8fdc

Please sign in to comment.