mirror of
https://github.com/Icinga/icinga2.git
synced 2025-09-22 09:17:43 +02:00
parent
008f5803e7
commit
963125f746
@ -99,6 +99,7 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
|
||||
for (;;) {
|
||||
int fd;
|
||||
|
||||
try {
|
||||
do {
|
||||
fd = open(commandPath.CStr(), O_RDONLY);
|
||||
} while (fd < 0 && errno == EINTR);
|
||||
@ -110,6 +111,18 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Log(LogNotice, "ExternalCommandListener", "Client connected");
|
||||
Utility::QueueAsyncCallback(boost::bind(&ExternalCommandListener::ClientHandler, this, commandPath, fd));
|
||||
} catch (std::exception&) {
|
||||
Log(LogCritical, "ExternalCommandListener", "Cannot accept new connection.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommandListener::ClientHandler(const String& commandPath, int fd)
|
||||
{
|
||||
FILE *fp = fdopen(fd, "r");
|
||||
|
||||
if (fp == NULL) {
|
||||
@ -127,6 +140,7 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
|
||||
while (strlen(line) > 0 &&
|
||||
(line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n'))
|
||||
line[strlen(line) - 1] = '\0';
|
||||
}
|
||||
|
||||
String command = line;
|
||||
|
||||
@ -138,11 +152,10 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
|
||||
std::ostringstream msgbuf;
|
||||
msgbuf << "External command failed.";
|
||||
Log(LogWarning, "ExternalCommandListener", msgbuf.str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
delete line;
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
@ -49,6 +49,7 @@ private:
|
||||
boost::thread m_CommandThread;
|
||||
|
||||
void CommandPipeThread(const String& commandPath);
|
||||
void ClientHandler(const String& commandPath, int fd);
|
||||
#endif /* _WIN32 */
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user