[icinga-checkins] icinga.org: icinga2/next: Error messages: Properly handle livestatus/ cmd pipe errors.

git at icinga.org git at icinga.org
Thu Jun 5 18:29:54 CEST 2014


Module: icinga2
Branch: next
Commit: efa8fdcb8e5cebe08c27d13e5ba27998245a5063
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=efa8fdcb8e5cebe08c27d13e5ba27998245a5063

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Thu Jun  5 17:43:34 2014 +0200

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 eb9deb8..c51c6cb 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 57bbdff..40fe340 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));



More information about the icinga-checkins mailing list