diff --git a/0004-after-export-all-log-program-abort.patch b/0004-after-export-all-log-program-abort.patch new file mode 100644 index 0000000000000000000000000000000000000000..20113d3fe6dce79ddf5baf7be3e94c51a3f71e94 --- /dev/null +++ b/0004-after-export-all-log-program-abort.patch @@ -0,0 +1,169 @@ +diff --git a/nfs-logtools-1.0.0/getcontent.cpp b/nfs-logtools-1.0.0/getcontent.cpp +index 0e70044..8931bbb 100644 +--- a/nfs-logtools-1.0.0/getcontent.cpp ++++ b/nfs-logtools-1.0.0/getcontent.cpp +@@ -11,13 +11,51 @@ QString GetContent::getHomePath() + QStringList getUserName; + QStringList curHome; + QString curUser = ""; ++ QString ret =""; ++ QString tmpLine =""; ++ QStringList contentList; ++ QStringList tmpLineList; ++ QString firstLine = ""; + QString curUsrPawdInfo = ""; + +- execCmd->start("who", params); ++ /* 使用who命令获取当前用户名,如果多用户登灵会产生问题*/ ++ /* execCmd->start("who", params); + execCmd->waitForFinished(); + curUser = execCmd->readAllStandardOutput(); + getUserName = curUser.split(" "); +- curUser = getUserName[0]; ++ curUser = getUserName[0];*/ ++ ++ /*使用last命令获取首行still logged in的用户*/ ++ execCmd->start("last", params); ++ execCmd->waitForFinished(); ++ ret = execCmd->readAllStandardOutput(); ++ ++ //将整体返回的字符串按\n为一行,存储到list中 ++ for (auto ch:ret) { ++ if ('\n'!= ch) { ++ tmpLine.append(ch); ++ } ++ else { ++ contentList.append(tmpLine); ++ tmpLine.clear(); ++ } ++ } ++ ++ //取第一个非root的用户 ++ int i= 0; ++ do { ++ if (contentList[i].contains("root", Qt::CaseInsensitive)) { ++ continue; ++ } ++ else { ++ getUserName = contentList[i].split(" "); ++ curUser = getUserName[0]; ++ break; ++ } ++ i++; ++ } while (istart("bash", QStringList() << "-c" << "cat /etc/passwd | grep " + curUser); + execCmd->waitForFinished(); +@@ -70,16 +108,31 @@ bool GetContent::checkDirPathExists(QString &dirPath) + } + } + ++int GetContent::getSubStringCount(QString &str) ++{ ++ QString substr = "\x1b"; ++ QRegExp rx(substr); ++ int count = 0; ++ int pos = 0; ++ while ((pos = rx.indexIn(str, pos)) != -1) { ++ ++count; ++ pos += rx.matchedLength(); ++ } ++ return count; ++} ++ + void GetContent::removeColorString(QString &str) + { + int colorStringLeft = 0; + int colorStringRight = 0; + int pos = 0; + int count = 0; ++ int substrCount = getSubStringCount(str); + QString substr = "\x1b"; + + colorStringLeft = str.indexOf(substr, pos); +- while (colorStringLeft != -1) { ++ ++ for (int i=0; istart("who", params); +- execCmd->waitForFinished(); +- curUser = execCmd->readAllStandardOutput(); +- getUserName = curUser.split(" "); +- curUser = getUserName[0]; +- this->exportPath = "/home/" + curUser + "/桌面/"; +- execCmd->close(); +- // qDebug() << this->exportPath; ++ this->exportPath = GetContent::getHomePath() + "/桌面/"; + } + + void Logtools::logtoolsMessagesBox() +@@ -1676,7 +1664,7 @@ void Logtools::logtoolsSyslogSlots() + QString crashDir = "/var/crash"; + QString dstDir = this->exportPath + "/system-all-log"; + GetContent checkDir; +- QString messageBoxText = "系统日志将导出到桌面,确认导出吗?"; ++ QString messageBoxText = "系统日志将导出到" + this->exportPath + ",确认导出吗?"; + + QMessageBox *exportCupsLog = new QMessageBox; + exportCupsLog->setWindowTitle(" "); +@@ -1718,7 +1706,7 @@ void Logtools::logtoolsPrintRelatedSlots() + QString srcDir = "/var/log/cups"; + QString dstDir = this->exportPath + "/cups"; + GetContent checkDir; +- QString messageBoxText = "打印日志将导出到桌面,确认导出吗?"; ++ QString messageBoxText = "打印日志将导出到" + this->exportPath + ",确认导出吗?"; + + if (!checkDir.checkDirPathExists(srcDir)) { + return ; +@@ -1814,7 +1802,7 @@ void Logtools::on_pushButtonExportCur_clicked() + QString currentDate = currentDateTime.toString("yyyy.MM.dd-hh:mm:ss"); + exportFile = "log_" + currentDate; //format eg: log_2022.08.16-14:36:05 + QString logFile = this->exportPath + exportFile; +- QString messageBoxText = "当前日志将导出到桌面,确认导出吗?"; ++ QString messageBoxText = "当前日志将导出到" + this->exportPath + ",确认导出吗?"; + QMessageBox *exportCurLog = new QMessageBox; + + exportCurLog->setWindowTitle(" "); +@@ -1853,7 +1841,7 @@ void Logtools::on_pushButtonExportAll_clicked() + QString folderNmae = "export"; + QDir dir(QDir::tempPath()); + GetContent checkDir; +- QString messageBoxText = "系统日志将导出到桌面,确认导出吗?"; ++ QString messageBoxText = "系统日志将导出到" + this->exportPath + ",确认导出吗?"; + QMessageBox *exportLog = new QMessageBox; + exportLog->setWindowTitle(" "); + exportLog->setText(messageBoxText); diff --git a/nfs-logtools.spec b/nfs-logtools.spec index 289a54bf3c8bbba7962f39f2d502bf685629d58d..f8d67c5087f31f130ba896b03674f78803203372 100644 --- a/nfs-logtools.spec +++ b/nfs-logtools.spec @@ -3,10 +3,15 @@ Name: nfs-logtools Version: 1.0.0 -Release: 1 +Release: 4%{?dist} Summary: A log tools of Nfs. License: GPLv2+ Source0: %{name}-%{version}.tar.gz +Patch0: 0001-fix-display-version-error.patch +Patch1: 0002-adj-xsession-error-log-path.patch +Patch2: 0003-auto-scaling-and-fix-error.patch +Patch3: 0004-after-export-all-log-program-abort.patch + BuildRequires: qt5-qttools-devel qt5-qtbase-devel glibc-devel Requires: coreutils %global debug_package %{nil} @@ -38,3 +43,6 @@ make %{?_smp_mflags} %config /usr/sbin/nfs-logtools %changelog + +* Wed Oct 18 2023 ruizhe - 1.0.0-4 +- Fix: after export all log, program abort