There is a strange problem in my console application.
First of all, the code snippet:
main.cpp
#include "DebugInterface.h"
static sigset_t signalSet;
static pthread_t CleanupHandlerThread;
DebugInterface* debugInterface = NULL;
void* CleanupHandler (void* param) {
int32_t sig, err;
err = sigwait (&signalSet, &sig);
delete debugInterface;
debugInterface = NULL;
exit (EXIT_SUCCESS);
return NULL;
}
int32_t main(int32_t argc, char** argv) {
sigemptyset (&signalSet);
sigaddset (&signalSet, SIGINT);
pthread_sigmask (SIG_BLOCK, &signalSet, NULL);
pthread_create (&CleanupHandlerThread, NULL, CleanupHandler, NULL);
debugInterface = new DebugInterface();
if (debugInterface != NULL) {
debugInterface->StartReading();
}
while (true) {
}
return EXIT_SUCCESS;
}
DebugInterface.h
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
#include <readline/readline.h>
#include <readline/history.h>
#include <signal.h>
class DebugInterface {
public:
DebugInterface() { }
virtual ~DebugInterface() { }
private:
pthread_t ConsoleHandlerThread;
private:
static void* ConsoleHandler (void* param);
public:
bool StartReading();
};
DebugInterface.cpp
#include "DebugInterface.h"
void* DebugInterface::ConsoleHandler (void* param) {
while (true) {
char* input = readline ("\n> ");
free (input);
}
return NULL;
}
bool DebugInterface::StartReading() {
if (pthread_create (&ConsoleHandlerThread, NULL, DebugInterface::ConsoleHandler, NULL) != 0) {
return false;
}
return true;
}
The code works fine and, as expected, but when it exits and exits, catching the SIGINT signal, the console output is subsequently hidden (that is, the console / terminal behaves like applying the "stty -echo" command).
( "stty echo" ); CleanupHandler "" , ... , , . , / , /, ( "printf" ).
, / :
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building target: Testproject
Invoking: GCC C++ Linker
g++ -o"Testproject" ./DebugInterface.o ./main.o -lreadline -lpthread
Finished building target: Testproject
, SSH, . , / .
.