|
@@ -22,13 +22,54 @@ int inpipefd[2];
|
|
|
int outpipefd[2];
|
|
|
char buf[1025];
|
|
|
QUrl sendFileUrl = QUrl("");
|
|
|
-QString _IP = qsTr("");
|
|
|
+QString _IP = "";
|
|
|
bool _CLI_RUNNING = false;
|
|
|
|
|
|
bool programActive = true;
|
|
|
|
|
|
QMLHandler::QMLHandler(QObject *parent) : QObject(parent) {}
|
|
|
|
|
|
+void QMLHandler::closeCLI() {
|
|
|
+ close(outpipefd[1]);
|
|
|
+ close(inpipefd[0]);
|
|
|
+}
|
|
|
+
|
|
|
+void QMLHandler::reopenCLI(QString ip) {
|
|
|
+ if (_CLI_RUNNING) {
|
|
|
+ closeCLI();
|
|
|
+ }
|
|
|
+
|
|
|
+ _IP = ip;
|
|
|
+ pid_t pid = 0;
|
|
|
+
|
|
|
+ pipe(inpipefd);
|
|
|
+ pipe(outpipefd);
|
|
|
+ pid = fork();
|
|
|
+ if (pid == 0) {
|
|
|
+
|
|
|
+ dup2(outpipefd[0], STDIN_FILENO);
|
|
|
+ dup2(inpipefd[1], STDOUT_FILENO);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ prctl(PR_SET_PDEATHSIG, SIGTERM);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(),
|
|
|
+ "--machine", (char *)NULL);
|
|
|
+
|
|
|
+ _CLI_RUNNING = true;
|
|
|
+
|
|
|
+ exit(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ close(outpipefd[0]);
|
|
|
+ close(inpipefd[1]);
|
|
|
+
|
|
|
+ std::thread(&QMLHandler::readPipeLoop, this).detach();
|
|
|
+}
|
|
|
+
|
|
|
void QMLHandler::onExit() {
|
|
|
write(outpipefd[1], "disconnect\n", strlen("disconnect\n"));
|
|
|
}
|
|
@@ -240,44 +281,3 @@ void QMLHandler::onSignupRegisterButton(QString username, QString passwordOne,
|
|
|
void QMLHandler::onFooterGetStatusButton() {
|
|
|
write(outpipefd[1], "status\n", strlen("status\n"));
|
|
|
}
|
|
|
-
|
|
|
-void QMLHandler::reopenCLI(QString ip) {
|
|
|
- if (_CLI_RUNNING) {
|
|
|
- closeCLI();
|
|
|
- }
|
|
|
-
|
|
|
- _IP = ip;
|
|
|
- pid_t pid = 0;
|
|
|
-
|
|
|
- pipe(inpipefd);
|
|
|
- pipe(outpipefd);
|
|
|
- pid = fork();
|
|
|
- if (pid == 0) {
|
|
|
-
|
|
|
- dup2(outpipefd[0], STDIN_FILENO);
|
|
|
- dup2(inpipefd[1], STDOUT_FILENO);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- prctl(PR_SET_PDEATHSIG, SIGTERM);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- execl("../../cli/build/ccats-cli", "ccats-cli", ip.toUtf8().constData(),
|
|
|
- "--machine", (char *)NULL);
|
|
|
-
|
|
|
- _CLI_RUNNING = true;
|
|
|
-
|
|
|
- exit(1);
|
|
|
- }
|
|
|
-
|
|
|
- close(outpipefd[0]);
|
|
|
- close(inpipefd[1]);
|
|
|
-
|
|
|
- std::thread(&QMLHandler::readPipeLoop, this).detach();
|
|
|
-}
|
|
|
-
|
|
|
-void QMLHandler::closeCLI() {
|
|
|
- close(outpipefd[1]);
|
|
|
- close(inpipefd[0]);
|
|
|
-}
|