From 117ecc6cc5c547434225801640468d6854284770 Mon Sep 17 00:00:00 2001 From: handsome-feng Date: Thu, 16 Apr 2020 01:33:12 +0800 Subject: [PATCH] Update the file path from .config to /tmp --- debian/changelog | 9 +++++ src/backthread.cpp | 38 +++++++++----------- src/kylin-network-interface.c | 24 +++++++++---- src/kylin-network-interface.h | 2 +- src/mainwindow.cpp | 13 ++----- wireless-security/dlgconnhidwifi.cpp | 47 ++++++++++++------------- wireless-security/dlgconnhidwifiwpa.cpp | 34 +++++++++--------- 7 files changed, 86 insertions(+), 81 deletions(-) diff --git a/debian/changelog b/debian/changelog index e7166ad4..25f14d29 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +kylin-nm (1.2.4-1) unstable; urgency=medium + + * New upstream bugfix release: + - Fix that the UI stuck under multiple user. + - Fix that the wired network disconnected after docker started. + - Fix the wrong device object path. + + -- handsome_feng Wed, 15 Apr 2020 23:07:10 +0800 + kylin-nm (1.2.3-1) unstable; urgency=medium * New upstream bugfix release: diff --git a/src/backthread.cpp b/src/backthread.cpp index b5bdb0fb..8b590c8f 100644 --- a/src/backthread.cpp +++ b/src/backthread.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include BackThread::BackThread(QObject *parent) : QObject(parent){ cmdConnWifi = new QProcess(this); @@ -45,16 +45,14 @@ BackThread::~BackThread() IFace* BackThread::execGetIface(){ IFace *iface = new IFace(); - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString localPath = homePath.at(0) + "/.config/kylin-nm-iface"; - - QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > " + localPath; + QString tmpPath = "/tmp/kylin-nm-iface-" + QDir::home().dirName(); + QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f TYPE,DEVICE,STATE device > " + tmpPath; Utils::m_system(cmd.toUtf8().data()); // int status = system(cmd.toUtf8().data()); // if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device' in function 'execGetIface' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-iface!"); @@ -230,15 +228,14 @@ void BackThread::execConnLan(QString connName){ void BackThread::execConnWifiPWD(QString connName, QString password){ disConnLanOrWifi("wifi"); - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput"; + QString tmpPath = "/tmp/kylin-nm-btoutput-" + QDir::home().dirName(); - QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > " + localPath; + QString cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli device wifi connect '" + connName + "' password '" + password + "' > " + tmpPath; Utils::m_system(cmdStr.toUtf8().data()); // int status = system(cmdStr.toUtf8().data()); // if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'execConnWifiPWD' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ syslog(LOG_DEBUG, "Can't open the file /tmp/kylin-nm-btoutput !"); qDebug()<<"Can't open the file /tmp/kylin-nm-btoutput !"< " + localPath; + QString cmd = "nmcli connection show '" + connName + "' > " + tmpPath; Utils::m_system(cmd.toUtf8().data()); // int status = system(cmd.toUtf8().data()); // if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'getConnProp' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-connprop!"); qDebug()<<"Can't open the file /tmp/kylin-nm-connprop!"< " + localPath; + QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection show '" + connName + "' > " + tmpPath; Utils::m_system(cmd.toUtf8().data()); // int status = system(cmd.toUtf8().data()); // if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'execChkWifiExist' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-chkwifiexist!"); @@ -380,15 +375,14 @@ bool BackThread::execChkWifiExist(QString connName){ } QString BackThread::execChkLanWidth(QString ethName){ - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString localPath = homePath.at(0) + "/.config/kylin-nm-bandwidth"; + QString tmpPath = "/tmp/kylin-nm-bandwidth-" + QDir::home().dirName(); - QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > " + localPath; + QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';ethtool '" + ethName + "' | grep Speed > " + tmpPath; Utils::m_system(cmd.toUtf8().data()); // int status = system(cmd.toUtf8().data()); // if (status != 0){ syslog(LOG_ERR, "execute 'ethtool' in function 'execChkLanWidth' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-bandwidth!"); diff --git a/src/kylin-network-interface.c b/src/kylin-network-interface.c index ce4ae5e3..fce726ee 100644 --- a/src/kylin-network-interface.c +++ b/src/kylin-network-interface.c @@ -28,6 +28,7 @@ #include #include #include +#include //获取网络接口名 @@ -186,23 +187,30 @@ conlist *kylin_network_get_conlist_info() } //获取当前活动网络连接 -activecon *kylin_network_get_activecon_info(char *path) +activecon *kylin_network_get_activecon_info() { + struct passwd *pwd; + pwd = getpwuid(getuid()); + char *name = pwd->pw_name; + char *tmpPrefix = "/tmp/kylin-nm-activecon-"; char *chr = "nmcli connection show -active > "; - char *cmd = (char *) malloc(strlen(chr) + strlen(path)); - strcpy(cmd, chr); - strcat(cmd, path); + char *cmd; + asprintf(&cmd, "%s%s%s", chr, tmpPrefix, name); + char *path; + asprintf(&path, "%s%s", tmpPrefix, name); int status = system(cmd); - if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show -active' in function 'kylin_network_get_activecon_info' failed");} + if (status != 0) + syslog(LOG_ERR, "execute 'nmcli connection show -active' in function 'kylin_network_get_activecon_info' failed"); + free(cmd); + char *filename = path; FILE *activefp; int activenum=0; char activeStrLine[1024]; - if((activefp=fopen(filename,"r"))==NULL) + if ((activefp=fopen(filename,"r"))==NULL) { printf("error!"); - } fgets(activeStrLine,1024,activefp); while(!feof(activefp)) @@ -222,6 +230,8 @@ activecon *kylin_network_get_activecon_info(char *path) printf("error!"); } + free(path); + fgets(StrLine,1024,fp); while(!feof(fp)) { diff --git a/src/kylin-network-interface.h b/src/kylin-network-interface.h index c705298d..4c7b46aa 100644 --- a/src/kylin-network-interface.h +++ b/src/kylin-network-interface.h @@ -73,7 +73,7 @@ conlist *kylin_network_get_conlist_info(); * Get the active network connection. * return the struct pointer. */ -activecon *kylin_network_get_activecon_info(char *path); +activecon *kylin_network_get_activecon_info(); /* * Create a new Ethernet connection. diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ce225f02..d3be4cda 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -892,10 +892,7 @@ void MainWindow::getActiveInfo() QString actLanName = "--"; QString actWifiName = "--"; - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon"; - - activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data()); + activecon *act = kylin_network_get_activecon_info(); int index = 0; while(act[index].con_name != NULL){ if(QString(act[index].type) == "ethernet"){ @@ -1394,10 +1391,8 @@ void MainWindow::getLanListDone(QStringList slist) // 获取当前连接的lan name QString actLanName = "--"; - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon"; - activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data()); + activecon *act = kylin_network_get_activecon_info(); int index = 0; while(act[index].con_name != NULL){ if(QString(act[index].type) == "ethernet"){ @@ -1529,10 +1524,8 @@ void MainWindow::loadWifiListDone(QStringList slist) // 获取当前连接的wifi name QString actWifiName = "--"; - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString lockPath = homePath.at(0) + "/.config/kylin-nm-activecon"; - activecon *act = kylin_network_get_activecon_info(lockPath.toUtf8().data()); + activecon *act = kylin_network_get_activecon_info(); int index = 0; while(act[index].con_name != NULL){ if(QString(act[index].type) == "wifi"){ diff --git a/wireless-security/dlgconnhidwifi.cpp b/wireless-security/dlgconnhidwifi.cpp index 299db505..1c1b035a 100644 --- a/wireless-security/dlgconnhidwifi.cpp +++ b/wireless-security/dlgconnhidwifi.cpp @@ -26,6 +26,7 @@ #include #include +#include DlgConnHidWifi::DlgConnHidWifi(int type, MainWindow *mainWindow, QWidget *parent) : isUsed(type), @@ -74,12 +75,11 @@ DlgConnHidWifi::DlgConnHidWifi(int type, MainWindow *mainWindow, QWidget *parent ui->btnConnect->setText(tr("Connect")); //连接 ui->cbxConn->addItem(tr("C_reate…")); //新建... - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow"; - QString cmd = "nmcli connection show>" + localPath; + QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName(); + QString cmd = "nmcli connection show>" + tmpPath; int status = system(cmd.toUtf8().data()); if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'DlgConnHidWifi' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug()<<"Can't open the file!"; } @@ -198,13 +198,12 @@ void DlgConnHidWifi::changeWindow(){ ui->cbxSecurity->setEnabled(true); ui->btnConnect->setEnabled(false); }else if (ui->cbxConn->currentIndex() >= 1){ - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString localPath = homePath.at(0) + "/.config/kylin-nm-connshow"; + QString tmpPath = "/tmp/kylin-nm-connshow-" + QDir::home().dirName(); + QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + tmpPath; - QString currStr = "nmcli connection show " + ui->cbxConn->currentText() + " >" + localPath; int status = system(currStr.toUtf8().data()); if (status != 0){ syslog(LOG_ERR, "execute 'nmcli connection show' in function 'changeWindow' failed");} - QFile file(localPath); + QFile file(tmpPath); if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug()<<"Can't open the file!"; } @@ -247,24 +246,24 @@ void DlgConnHidWifi::on_btnConnect_clicked() //点击连接按钮以连接隐藏WiFi if (isUsed == 0){ int x = 0; - do{ + do { sleep(1); - QStringList homePath = QStandardPaths::standardLocations(QStandardPaths::HomeLocation); - QString localPath = homePath.at(0) + "/.config/kylin-nm-btoutput"; - - QString cmd = "nmcli device wifi connect " + wifiName + " password '' hidden yes > " + localPath; - int status = system(cmd.toUtf8().data()); - if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_btnConnect_clicked' failed");} - - QFile file(localPath); - if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) - { - qDebug()<<"Can't open the file!"<