|
@@ -51,8 +51,6 @@ ctkFDHandler::ctkFDHandler(ctkErrorLogFDMessageHandler* messageHandler,
|
|
|
this->TerminalOutput = terminalOutput;
|
|
|
this->SavedFDNumber = 0;
|
|
|
this->Enabled = false;
|
|
|
- this->Initialized = false;
|
|
|
- this->init();
|
|
|
}
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
@@ -61,7 +59,7 @@ ctkFDHandler::~ctkFDHandler()
|
|
|
}
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
-void ctkFDHandler::init()
|
|
|
+void ctkFDHandler::setupPipe()
|
|
|
{
|
|
|
#ifdef Q_OS_WIN32
|
|
|
int status = _pipe(this->Pipe, 65536, _O_TEXT);
|
|
@@ -73,7 +71,6 @@ void ctkFDHandler::init()
|
|
|
qCritical().nospace() << "ctkFDHandler - Failed to create pipe !";
|
|
|
return;
|
|
|
}
|
|
|
- this->Initialized = true;
|
|
|
}
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
@@ -85,10 +82,6 @@ FILE* ctkFDHandler::terminalOutputFile()
|
|
|
// --------------------------------------------------------------------------
|
|
|
void ctkFDHandler::setEnabled(bool value)
|
|
|
{
|
|
|
- if (!this->Initialized)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
if (this->Enabled == value)
|
|
|
{
|
|
|
return;
|
|
@@ -96,6 +89,8 @@ void ctkFDHandler::setEnabled(bool value)
|
|
|
|
|
|
if (value)
|
|
|
{
|
|
|
+ this->setupPipe();
|
|
|
+
|
|
|
// Flush (stdout|stderr) so that any buffered messages are delivered
|
|
|
fflush(this->terminalOutputFile());
|
|
|
|
|
@@ -117,6 +112,12 @@ void ctkFDHandler::setEnabled(bool value)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ // Print one character to "unblock" the read function associated with the polling thread
|
|
|
+ ssize_t res = write(fileno(this->terminalOutputFile()), "\n", 1);
|
|
|
+ if (res == -1)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
// Flush stdout or stderr so that any buffered messages are delivered
|
|
|
fflush(this->terminalOutputFile());
|
|
|
|
|
@@ -147,11 +148,14 @@ void ctkFDHandler::setEnabled(bool value)
|
|
|
clearerr(this->terminalOutputFile());
|
|
|
fsetpos(this->terminalOutputFile(), &this->SavedFDPos);
|
|
|
|
|
|
+
|
|
|
#ifdef Q_OS_WIN32
|
|
|
- this->SavedFDNumber = _fileno(this->terminalOutputFile());
|
|
|
+ _close(this->Pipe[0]);
|
|
|
#else
|
|
|
- this->SavedFDNumber = fileno(this->terminalOutputFile());
|
|
|
+ close(this->Pipe[0]);
|
|
|
#endif
|
|
|
+
|
|
|
+ this->SavedFDNumber = 0;
|
|
|
}
|
|
|
|
|
|
ctkErrorLogTerminalOutput * terminalOutput =
|