Fix bug bash progress can not exit after connect or disconnect wifi

This commit is contained in:
chenlelin 2021-04-21 20:33:16 +08:00
parent 40952d13c4
commit 7cbc2f7884
2 changed files with 22 additions and 20 deletions

View File

@ -31,21 +31,19 @@
BackThread::BackThread(QObject *parent) : QObject(parent) BackThread::BackThread(QObject *parent) : QObject(parent)
{ {
cmdConnWifi = new QProcess(this); cmdProcessWifi = new QProcess(this);
connect(cmdConnWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(onReadOutputWifi())); connect(cmdProcessWifi , SIGNAL(readyReadStandardOutput()) , this , SLOT(onReadOutputWifi()));
connect(cmdConnWifi , SIGNAL(readyReadStandardError()) , this , SLOT(onReadErrorWifi())); connect(cmdProcessWifi , SIGNAL(readyReadStandardError()) , this , SLOT(onReadErrorWifi()));
cmdConnWifi->start("/bin/bash");
cmdConnWifi->waitForStarted();
process = new QProcess(this); cmdProcessLan = new QProcess(this);
connect(process , SIGNAL(readyReadStandardOutput()) , this , SLOT(onReadOutputLan())); connect(cmdProcessLan , SIGNAL(readyReadStandardOutput()) , this , SLOT(onReadOutputLan()));
connect(process , SIGNAL(readyReadStandardError()) , this , SLOT(onReadErrorLan())); connect(cmdProcessLan , SIGNAL(readyReadStandardError()) , this , SLOT(onReadErrorLan()));
} }
BackThread::~BackThread() BackThread::~BackThread()
{ {
cmdConnWifi->close(); cmdProcessWifi->close();
process->close(); cmdProcessLan->close();
} }
//get the connection state of wired and wireles network //get the connection state of wired and wireles network
@ -224,9 +222,9 @@ void BackThread::execConnLan(QString connName, QString ifname, QString connectTy
if (isWiredCableAlready) { if (isWiredCableAlready) {
QStringList options; QStringList options;
options << "-c" << mycmd; options << "-c" << mycmd;
process->start("/bin/bash",options); cmdProcessLan->start("/bin/bash",options);
process->waitForStarted(); cmdProcessLan->waitForStarted();
process->waitForFinished(); cmdProcessLan->waitForFinished();
} else { } else {
qDebug()<<"connect wired network failed for without wired cable plug in."; qDebug()<<"connect wired network failed for without wired cable plug in.";
syslog(LOG_DEBUG, "connect wired network failed for without wired cable plug in."); syslog(LOG_DEBUG, "connect wired network failed for without wired cable plug in.");
@ -238,14 +236,14 @@ void BackThread::execConnLan(QString connName, QString ifname, QString connectTy
void BackThread::onReadOutputLan() void BackThread::onReadOutputLan()
{ {
QByteArray cmdout = process->readAllStandardOutput(); QByteArray cmdout = cmdProcessLan->readAllStandardOutput();
QString strResult = QString::fromLocal8Bit(cmdout); QString strResult = QString::fromLocal8Bit(cmdout);
qDebug()<<"on_readoutput_lan: "<< strResult; qDebug()<<"on_readoutput_lan: "<< strResult;
dellConnectLanResult(strResult); dellConnectLanResult(strResult);
} }
void BackThread::onReadErrorLan() void BackThread::onReadErrorLan()
{ {
QByteArray cmdout = process->readAllStandardError(); QByteArray cmdout = cmdProcessLan->readAllStandardError();
QString strResult = QString::fromLocal8Bit(cmdout); QString strResult = QString::fromLocal8Bit(cmdout);
qDebug()<<"on_readerror_lan: "<< strResult; qDebug()<<"on_readerror_lan: "<< strResult;
dellConnectLanResult(strResult); dellConnectLanResult(strResult);
@ -413,7 +411,11 @@ void BackThread::execConnWifi(QString connName, QString connIfName)
cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + connIfName + "'\n"; cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + connIfName + "'\n";
} }
cmdConnWifi->write(cmdStr.toUtf8().data()); QStringList options;
options << "-c" << cmdStr;
cmdProcessWifi->start("/bin/bash",options);
cmdProcessWifi->waitForStarted();
cmdProcessWifi->waitForFinished();
} }
void BackThread::execReconnWIfi(QString uuid) void BackThread::execReconnWIfi(QString uuid)
@ -426,14 +428,14 @@ void BackThread::execReconnWIfi(QString uuid)
void BackThread::onReadOutputWifi() void BackThread::onReadOutputWifi()
{ {
QString str = cmdConnWifi->readAllStandardOutput(); QString str = cmdProcessWifi->readAllStandardOutput();
qDebug()<<"on_readoutput_wifi: "<< str; qDebug()<<"on_readoutput_wifi: "<< str;
syslog(LOG_DEBUG, "on_readoutput_wifi : %s", str.toUtf8().data()); syslog(LOG_DEBUG, "on_readoutput_wifi : %s", str.toUtf8().data());
dellConnectWifiResult(str); dellConnectWifiResult(str);
} }
void BackThread::onReadErrorWifi() void BackThread::onReadErrorWifi()
{ {
QString str = cmdConnWifi->readAllStandardError(); QString str = cmdProcessWifi->readAllStandardError();
qDebug()<<"on_readerror_wifi: "<< str; qDebug()<<"on_readerror_wifi: "<< str;
syslog(LOG_DEBUG, "on_readerror_wifi : %s", str.toUtf8().data()); syslog(LOG_DEBUG, "on_readerror_wifi : %s", str.toUtf8().data());
dellConnectWifiResult(str); dellConnectWifiResult(str);

View File

@ -48,8 +48,8 @@ public:
IFace* execGetIface(); IFace* execGetIface();
QString getConnProp(QString connName); QString getConnProp(QString connName);
QString execChkLanWidth(QString ethName); QString execChkLanWidth(QString ethName);
QProcess *cmdConnWifi = nullptr; QProcess *cmdProcessWifi = nullptr;
QProcess *process; QProcess *cmdProcessLan;
QString currConnLanUuid; QString currConnLanUuid;
QString currConnLanType; QString currConnLanType;