[icinga-checkins] icinga.org: icinga2/master: Reuse pipe inode if it already exists.

git at icinga.org git at icinga.org
Wed Jan 23 10:18:39 CET 2013


Module: icinga2
Branch: master
Commit: 65c0334b28ce4dea8391020ac8b1e1cde91b6eeb
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=65c0334b28ce4dea8391020ac8b1e1cde91b6eeb

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed Jan 23 10:18:23 2013 +0100

Reuse pipe inode if it already exists.

Fixes #3552

---

 components/compat/compatcomponent.cpp |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp
index c777bea..7d00e38 100644
--- a/components/compat/compatcomponent.cpp
+++ b/components/compat/compatcomponent.cpp
@@ -100,11 +100,20 @@ void CompatComponent::Stop(void)
 #ifndef _WIN32
 void CompatComponent::CommandPipeThread(const String& commandPath)
 {
-	(void) unlink(commandPath.CStr());
+	struct stat statbuf;
+	bool fifo_ok = false;
+
+	if (lstat(commandPath.CStr(), &statbuf) >= 0) {
+		if (S_ISFIFO(statbuf.st_mode) && access(commandPath.CStr(), R_OK) >= 0) {
+			fifo_ok = true;
+		} else {
+			if (unlink(commandPath.CStr()) < 0)
+				throw_exception(PosixException("unlink() failed", errno));
+		}
+	}
 
-	int rc = mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
 
-	if (rc < 0)
+	if (!fifo_ok && mkfifo(commandPath.CStr(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
 		throw_exception(PosixException("mkfifo() failed", errno));
 
 	for (;;) {





More information about the icinga-checkins mailing list