Browse Source

fix thread spawning on refused connection

Missingmew 5 years ago
parent
commit
4247dd59cd
1 changed files with 5 additions and 3 deletions
  1. 5 3
      gui/src/qmlhandler.cpp

+ 5 - 3
gui/src/qmlhandler.cpp

@@ -33,6 +33,7 @@ QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
 void QMLHandler::closeCLI() {
   close(outpipefd[1]);
   close(inpipefd[0]);
+  _CLI_RUNNING = false;
 }
 
 void QMLHandler::reopenCLI(QString ip) {
@@ -60,11 +61,12 @@ void QMLHandler::reopenCLI(QString ip) {
     execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(),
           "--machine", (char *)NULL);
 
-    _CLI_RUNNING = true;
 
     exit(1);
   }
 
+  _CLI_RUNNING = true;
+  
   close(outpipefd[0]);
   close(inpipefd[1]);
 
@@ -138,7 +140,7 @@ void QMLHandler::handleJSON(string buffer) {
     if (root["accept"].asBool()) {
     } else {
       emit ipPopupSetStatus(root["error"].asString().c_str());
-      reopenCLI(_IP);
+      closeCLI();
     }
   }
 
@@ -220,7 +222,7 @@ void QMLHandler::readPipeLoop() {
   vector<string> inputs;
   string pipeInput;
 
-  while (programActive) {
+  while (programActive && _CLI_RUNNING) {
     inputs = vector<string>();
     poll(&inPipeStatus, 1, 100);