]> granicus.if.org Git - icinga2/commitdiff
Revert "ExternalCommandListener: Use threads per client connection"
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 20 Aug 2014 11:37:06 +0000 (13:37 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 20 Aug 2014 11:37:59 +0000 (13:37 +0200)
This reverts commit accd83693ce699be5538a60facf1d11b5ec3ac57

components/compat/externalcommandlistener.cpp
components/compat/externalcommandlistener.hpp

index 64ec44dfad3f1bbaf31c75769b4f68ef96b80cd1..a4f76a4d9ae1c929529f8dba5b4a73dffc437f73 100644 (file)
@@ -99,63 +99,50 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
        for (;;) {
                int fd;
 
-               try {
-                       do {
-                               fd = open(commandPath.CStr(), O_RDONLY);
-                       } while (fd < 0 && errno == EINTR);
-
-                       if (fd < 0) {
-                               std::ostringstream msgbuf;
-                               msgbuf << "open() for fifo path '" << commandPath << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
-                               Log(LogCritical, "ExternalCommandListener",  msgbuf.str());
-                               return;
-                       }
-
+               do {
+                       fd = open(commandPath.CStr(), O_RDONLY);
+               } while (fd < 0 && errno == EINTR);
+
+               if (fd < 0) {
+                       std::ostringstream msgbuf;
+                       msgbuf << "open() for fifo path '" << commandPath << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
+                       Log(LogCritical, "ExternalCommandListener",  msgbuf.str());
+                       return;
+               }
 
+               FILE *fp = fdopen(fd, "r");
 
-                       Log(LogNotice, "ExternalCommandListener", "Client connected");
-                       Utility::QueueAsyncCallback(boost::bind(&ExternalCommandListener::ClientHandler, this, commandPath, fd));
-               } catch (std::exception&) {
-                       Log(LogCritical, "ExternalCommandListener", "Cannot accept new connection.");
+               if (fp == NULL) {
+                       std::ostringstream msgbuf;
+                       msgbuf << "fdopen() for fifo path '" << commandPath << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
+                       Log(LogCritical, "ExternalCommandListener",  msgbuf.str());
+                       return;
                }
-       }
-}
 
-void ExternalCommandListener::ClientHandler(const String& commandPath, int fd)
-{
-       FILE *fp = fdopen(fd, "r");
-
-       if (fp == NULL) {
-               std::ostringstream msgbuf;
-               msgbuf << "fdopen() for fifo path '" << commandPath << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
-               Log(LogCritical, "ExternalCommandListener",  msgbuf.str());
-               return;
-       }
+               const int linesize = 128 * 1024;
+               char *line = new char[linesize];
 
-       const int linesize = 128 * 1024;
-       char *line = new char[linesize];
+               while (fgets(line, linesize, fp) != NULL) {
+                       // remove trailing new-line
+                       while (strlen(line) > 0 &&
+                           (line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n'))
+                               line[strlen(line) - 1] = '\0';
 
-       while (fgets(line, linesize, fp) != NULL) {
-               // remove trailing new-line
-               while (strlen(line) > 0 &&
-                   (line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n'))
-                       line[strlen(line) - 1] = '\0';
-       }
+                       String command = line;
 
-       String command = line;
+                       try {
+                               Log(LogInformation, "ExternalCommandListener", "Executing external command: " + command);
 
-       try {
-               Log(LogInformation, "ExternalCommandListener", "Executing external command: " + command);
+                               ExternalCommandProcessor::Execute(command);
+                       } catch (const std::exception&) {
+                               std::ostringstream msgbuf;
+                               msgbuf << "External command failed.";
+                               Log(LogWarning, "ExternalCommandListener", msgbuf.str());
+                       }
+               }
 
-               ExternalCommandProcessor::Execute(command);
-       } catch (const std::exception&) {
-               std::ostringstream msgbuf;
-               msgbuf << "External command failed.";
-               Log(LogWarning, "ExternalCommandListener", msgbuf.str());
-               return;
+               delete line;
+               fclose(fp);
        }
-
-       delete line;
-       fclose(fp);
 }
 #endif /* _WIN32 */
index 7e2fed7c086b66ef84723b915179377a1dda93be..0006aec33567ee64e5f79fb6314b8565cfd50f6c 100644 (file)
@@ -49,7 +49,6 @@ private:
        boost::thread m_CommandThread;
 
        void CommandPipeThread(const String& commandPath);
-       void ClientHandler(const String& commandPath, int fd);
 #endif /* _WIN32 */
 };