]> granicus.if.org Git - icinga2/commitdiff
Reuse pipe inode if it already exists.
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 23 Jan 2013 09:18:23 +0000 (10:18 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 23 Jan 2013 09:18:23 +0000 (10:18 +0100)
Fixes #3552

components/compat/compatcomponent.cpp

index c777bea3f8318e4fd015aafe39e9124575561ace..7d00e3888b0240574ba03347732b30b337fbc56a 100644 (file)
@@ -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 (;;) {