[icinga-checkins] icinga.org: icinga2/fix/sync-zones.d-recursively-6328: Replace existing mkdir() calls with Utility::MkDir()

git at icinga.org git at icinga.org
Fri Jun 13 09:23:47 CEST 2014


Module: icinga2
Branch: fix/sync-zones.d-recursively-6328
Commit: dea57e9dcf6b251e5d3b4cc33cd3a98b47807702
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=dea57e9dcf6b251e5d3b4cc33cd3a98b47807702

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Jun 13 09:23:05 2014 +0200

Replace existing mkdir() calls with Utility::MkDir()

refs #6328

---

 lib/remote/apilistener-sync.cpp |   26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/remote/apilistener-sync.cpp b/lib/remote/apilistener-sync.cpp
index fab2d92..3210ab4 100644
--- a/lib/remote/apilistener-sync.cpp
+++ b/lib/remote/apilistener-sync.cpp
@@ -110,11 +110,11 @@ void ApiListener::SyncZoneDir(const Zone::Ptr& zone) const
 	String newDir = Application::GetZonesDir() + "/" + zone->GetName();
 	String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName();
 
-#ifndef _WIN32
-	if (mkdir(oldDir.CStr(), 0700) < 0 && errno != EEXIST) {
-#else /*_ WIN32 */
-	if (mkdir(oldDir.CStr()) < 0 && errno != EEXIST) {
-#endif /* _WIN32 */
+	if (!Utility::MkDir(oldDir, 0700)) {
+		std::ostringstream msgbuf;
+		msgbuf << "mkdir() for path '" << oldDir << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
+		Log(LogCritical, "ApiListener",  msgbuf.str());
+
 		BOOST_THROW_EXCEPTION(posix_error()
 			<< boost::errinfo_api_function("mkdir")
 			<< boost::errinfo_errno(errno)
@@ -133,7 +133,11 @@ void ApiListener::SyncZoneDirs(void) const
 		if (!IsConfigMaster(zone))
 			continue;
 
-		SyncZoneDir(zone);
+		try {
+			SyncZoneDir(zone);
+		} catch (std::exception&) {
+			continue;
+		}
 	}
 }
 
@@ -213,11 +217,11 @@ Value ApiListener::ConfigUpdateHandler(const MessageOrigin& origin, const Dictio
 
 		String oldDir = Application::GetLocalStateDir() + "/lib/icinga2/api/zones/" + zone->GetName();
 
-#ifndef _WIN32
-		if (mkdir(oldDir.CStr(), 0700) < 0 && errno != EEXIST) {
-#else /*_ WIN32 */
-		if (mkdir(oldDir.CStr()) < 0 && errno != EEXIST) {
-#endif /* _WIN32 */
+		if (!Utility::MkDir(oldDir, 0700)) {
+			std::ostringstream msgbuf;
+			msgbuf << "mkdir() for path '" << oldDir << "'failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
+			Log(LogCritical, "ApiListener",  msgbuf.str());
+
 			BOOST_THROW_EXCEPTION(posix_error()
 				<< boost::errinfo_api_function("mkdir")
 				<< boost::errinfo_errno(errno)



More information about the icinga-checkins mailing list