Use threads for external commands

refs #6589
fixes #6942
This commit is contained in:
Gunnar Beutner 2014-08-20 13:45:31 +02:00
parent dae120beb6
commit e1b8b05ef3
2 changed files with 17 additions and 11 deletions

View File

@ -113,6 +113,8 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
FILE *fp = fdopen(fd, "r"); FILE *fp = fdopen(fd, "r");
if (fp == NULL) { if (fp == NULL) {
(void) close(fd);
std::ostringstream msgbuf; std::ostringstream msgbuf;
msgbuf << "fdopen() for fifo path '" << commandPath << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\""; msgbuf << "fdopen() for fifo path '" << commandPath << "' failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
Log(LogCritical, "ExternalCommandListener", msgbuf.str()); Log(LogCritical, "ExternalCommandListener", msgbuf.str());
@ -128,21 +130,24 @@ void ExternalCommandListener::CommandPipeThread(const String& commandPath)
(line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n')) (line[strlen(line) - 1] == '\r' || line[strlen(line) - 1] == '\n'))
line[strlen(line) - 1] = '\0'; line[strlen(line) - 1] = '\0';
String command = line; Utility::QueueAsyncCallback(boost::bind(&ExternalCommandListener::ExecuteCommand, line));
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());
}
} }
delete line; delete line;
fclose(fp); fclose(fp);
} }
} }
void ExternalCommandListener::ExecuteCommand(const String& command)
{
try {
Log(LogInformation, "ExternalCommandListener", "Executing external command: " + command);
ExternalCommandProcessor::Execute(command);
} catch (const std::exception&) {
std::ostringstream msgbuf;
msgbuf << "External command failed: " << command;
Log(LogWarning, "ExternalCommandListener", msgbuf.str());
}
}
#endif /* _WIN32 */ #endif /* _WIN32 */

View File

@ -49,6 +49,7 @@ private:
boost::thread m_CommandThread; boost::thread m_CommandThread;
void CommandPipeThread(const String& commandPath); void CommandPipeThread(const String& commandPath);
static void ExecuteCommand(const String& command);
#endif /* _WIN32 */ #endif /* _WIN32 */
}; };