From e81d7650981d1958ca568b2e16b020522e9a10de Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Sun, 1 Nov 2020 14:33:17 +0300 Subject: [PATCH] update to new process api --- sources/awesome-widget/plugin/awactions.cpp | 6 +++--- sources/awesome-widget/plugin/awactions.h | 2 +- sources/awesomewidgets/extscript.cpp | 2 +- sources/awesomewidgets/extupgrade.cpp | 5 ++--- sources/extsysmonsources/gpuloadsource.cpp | 5 +++-- sources/extsysmonsources/gputempsource.cpp | 5 +++-- sources/extsysmonsources/hddtempsource.cpp | 10 +++++++--- sources/extsysmonsources/hddtempsource.h | 2 +- sources/extsysmonsources/networksource.cpp | 2 +- 9 files changed, 22 insertions(+), 17 deletions(-) diff --git a/sources/awesome-widget/plugin/awactions.cpp b/sources/awesome-widget/plugin/awactions.cpp index c854770..cd1afa3 100644 --- a/sources/awesome-widget/plugin/awactions.cpp +++ b/sources/awesome-widget/plugin/awactions.cpp @@ -78,13 +78,13 @@ bool AWActions::isDebugEnabled() } -bool AWActions::runCmd(const QString &_cmd) +bool AWActions::runCmd(const QString &_cmd, const QStringList &_args) { - qCDebug(LOG_AW) << "Cmd" << _cmd; + qCDebug(LOG_AW) << "Cmd" << _cmd << "args" << _args; sendNotification(QString("Info"), i18n("Run %1", _cmd)); - return QProcess::startDetached(_cmd); + return QProcess::startDetached(_cmd, _args); } diff --git a/sources/awesome-widget/plugin/awactions.h b/sources/awesome-widget/plugin/awactions.h index c804123..73133e6 100644 --- a/sources/awesome-widget/plugin/awactions.h +++ b/sources/awesome-widget/plugin/awactions.h @@ -35,7 +35,7 @@ public: Q_INVOKABLE void checkUpdates(const bool _showAnyway = false); Q_INVOKABLE static QString getFileContent(const QString &_path); Q_INVOKABLE static bool isDebugEnabled(); - Q_INVOKABLE static bool runCmd(const QString &_cmd); + Q_INVOKABLE static bool runCmd(const QString &_cmd, const QStringList &_args); Q_INVOKABLE static void showLegacyInfo(); Q_INVOKABLE static void showReadme(); // configuration slots diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 8e0ee5f..ba9b909 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -346,7 +346,7 @@ void ExtScript::startProcess() cmdList.append(prefix()); cmdList.append(executable()); qCInfo(LOG_LIB) << "Run cmd" << cmdList.join(' '); - m_process->start(cmdList.join(' ')); + m_process->start("sh", QStringList() << "-c" << cmdList); } diff --git a/sources/awesomewidgets/extupgrade.cpp b/sources/awesomewidgets/extupgrade.cpp index 53da8f1..6673ec2 100644 --- a/sources/awesomewidgets/extupgrade.cpp +++ b/sources/awesomewidgets/extupgrade.cpp @@ -205,9 +205,8 @@ void ExtUpgrade::writeConfiguration() const void ExtUpgrade::startProcess() { - QString cmd = QString("sh -c \"%1\"").arg(executable()); - qCInfo(LOG_LIB) << "Run cmd" << cmd; - m_process->start(cmd); + qCInfo(LOG_LIB) << "Run cmd" << executable(); + m_process->start("sh", QStringList() << "-c" << executable()); } diff --git a/sources/extsysmonsources/gpuloadsource.cpp b/sources/extsysmonsources/gpuloadsource.cpp index 816cc8c..6281637 100644 --- a/sources/extsysmonsources/gpuloadsource.cpp +++ b/sources/extsysmonsources/gpuloadsource.cpp @@ -104,10 +104,11 @@ void GPULoadSource::run() if ((m_device != "nvidia") && (m_device != "ati")) return; // build cmd - QString cmd = m_device == "nvidia" ? "nvidia-smi -q -x" : "aticonfig --od-getclocks"; + QString cmd = m_device == "nvidia" ? "nvidia-smi" : "aticonfig"; + auto args = m_device == "nvidia" ? QStringList({"-q", "-x"}) : QStringList({"--od-getclocks"}); qCInfo(LOG_ESS) << "cmd" << cmd; - m_process->start(cmd); + m_process->start(cmd, args); } diff --git a/sources/extsysmonsources/gputempsource.cpp b/sources/extsysmonsources/gputempsource.cpp index dbf654b..a7edad0 100644 --- a/sources/extsysmonsources/gputempsource.cpp +++ b/sources/extsysmonsources/gputempsource.cpp @@ -83,10 +83,11 @@ void GPUTemperatureSource::run() if ((m_device != "nvidia") && (m_device != "ati")) return; // build cmd - QString cmd = m_device == "nvidia" ? "nvidia-smi -q -x" : "aticonfig --od-gettemperature"; + QString cmd = m_device == "nvidia" ? "nvidia-smi" : "aticonfig"; + auto args = m_device == "nvidia" ? QStringList({"-q", "-x"}) : QStringList({"--od-gettemperature"}); qCInfo(LOG_ESS) << "cmd" << cmd; - m_process->start(cmd); + m_process->start(cmd, args); } diff --git a/sources/extsysmonsources/hddtempsource.cpp b/sources/extsysmonsources/hddtempsource.cpp index 35c9cb7..d434db7 100644 --- a/sources/extsysmonsources/hddtempsource.cpp +++ b/sources/extsysmonsources/hddtempsource.cpp @@ -32,7 +32,7 @@ HDDTemperatureSource::HDDTemperatureSource(QObject *_parent, const QStringList & qCDebug(LOG_ESS) << __PRETTY_FUNCTION__; m_devices = _args.at(0).split(',', Qt::SkipEmptyParts); - m_cmd = _args.at(1); + m_cmd = _args.at(1).split(' '); // lets hope no one put cmd with spaces here lol m_smartctl = m_cmd.contains("smartctl"); qCInfo(LOG_ESS) << "Parse as smartctl" << m_smartctl; @@ -77,8 +77,12 @@ QVariant HDDTemperatureSource::data(const QString &_source) QString device = _source; device.remove("hdd/temperature"); // run cmd - if (m_processes[device]->state() == QProcess::NotRunning) - m_processes[device]->start(QString("%1 %2").arg(m_cmd).arg(device)); + if (m_processes[device]->state() == QProcess::NotRunning) { + auto cmd = m_cmd.first(); + auto args = m_cmd.mid(1); + args.append(device); + m_processes[device]->start(cmd, args); + } return m_values[device]; } diff --git a/sources/extsysmonsources/hddtempsource.h b/sources/extsysmonsources/hddtempsource.h index de33c7a..469a67a 100644 --- a/sources/extsysmonsources/hddtempsource.h +++ b/sources/extsysmonsources/hddtempsource.h @@ -45,7 +45,7 @@ private: // properties QHash m_processes; // configuration and values - QString m_cmd; + QStringList m_cmd; QStringList m_devices; bool m_smartctl; QHash m_values; diff --git a/sources/extsysmonsources/networksource.cpp b/sources/extsysmonsources/networksource.cpp index 48dd60f..a34cdcc 100644 --- a/sources/extsysmonsources/networksource.cpp +++ b/sources/extsysmonsources/networksource.cpp @@ -84,7 +84,7 @@ QVariantMap NetworkSource::initialData(const QString &_source) const void NetworkSource::run() { m_values["network/current/name"] = NetworkSource::getCurrentDevice(); - m_process->start("iwgetid -r"); + m_process->start("iwgetid", QStringList() << "-r"); }