Add slots for catching output of underlying update_psa_script.

iSetting timeout to 200000 when in maintenance-mode.
This commit is contained in:
Gerhard Hoffmann 2023-06-27 17:29:10 +02:00
parent 58684cf3c4
commit c34944af8b

View File

@ -12,7 +12,6 @@
#include <QSharedMemory>
#include <QScopedPointer>
#include <QProcess>
#include <QDir>
#include <QThread>
#include <QDateTime>
@ -134,19 +133,26 @@ bool Update::execUpdateScript() {
QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels);
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
p->start(update_psa);
if (p->waitForStarted(1000)) {
if (p->state() == QProcess::ProcessState::Running) {
int const timeout = 200000; // sometimes signal strength of modem is quite low
// maintenance_mode: update_psa script enters an infinite loop
int const timeout = (m_maintenanceMode ? 200000: -1);
if (p->waitForFinished(timeout)) {
QString output = p->readAllStandardOutput().toStdString().c_str();
QStringList lst = output.split('\n');
for (int i = 0; i < lst.size(); ++i) {
qDebug() << lst[i];
}
qInfo() << "EXECUTED" << update_psa;
return ((p->exitStatus() == QProcess::NormalExit)
&& (p->exitCode() == 0));
if (p->exitStatus() == QProcess::NormalExit) {
qInfo() << "EXECUTED" << update_psa
<< "with code" << p->exitCode();
return (p->exitCode() == 0);
}
} else {
qCritical() << "update-script TIMEDOUT after"
<< timeout/1000 << "seconds";
@ -531,7 +537,26 @@ QStringList Update::split(QString line, QChar sep) {
return lst;
}
void Update::readyReadStandardOutput() {
QProcess *p = (QProcess *)sender();
QByteArray buf = p->readAllStandardOutput();
qCritical() << buf;
}
void Update::readyReadStandardError() {
QProcess *p = (QProcess *)sender();
QByteArray buf = p->readAllStandardError();
qCritical() << buf;
}
void Update::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
QProcess *p = (QProcess *)sender();
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardOutput()));
disconnect(p, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(readyReadStandardError()));
}
bool Update::doUpdate() {
/*
The file referred to by 'update_data' has the following structure for
each line:
@ -626,7 +651,7 @@ bool Update::doUpdate() {
} else if (name.contains("DC2C_cash", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_CASH_TEMPLATE
#if UPDATE_CASH_TEMPLATE == 1
if ((res = updateCashConf(name))) {
qInfo() << "downloaded cash template"<< name;
}
@ -634,7 +659,7 @@ bool Update::doUpdate() {
} else if (name.contains("DC2C_conf", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_CONF_TEMPLATE
#if UPDATE_CONF_TEMPLATE == 1
if ((res= updateConfig(name))) {
qInfo() << "downloaded config template"<< name;
}
@ -642,7 +667,7 @@ bool Update::doUpdate() {
} else if (name.contains("DC2C_device", Qt::CaseInsensitive)
&& name.endsWith(".json", Qt::CaseInsensitive)) {
res = true;
#if UPDATE_DEVICE_TEMPLATE
#if UPDATE_DEVICE_TEMPLATE == 1
if ((res = updateDeviceConf(name))) {
qInfo() << "downloaded device template"<< name;
}
@ -657,7 +682,12 @@ bool Update::doUpdate() {
#if UPDATE_OPKG == 1
QScopedPointer<QProcess> p(new QProcess(this));
p->setProcessChannelMode(QProcess::MergedChannels);
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
p->start(name.trimmed());
if (p->waitForStarted(1000)) {
if (p->state() == QProcess::ProcessState::Running) {
if (p->waitForFinished(100000)) {