Fix 'Restart' RPC command (#894)

This commit is contained in:
Murat Seker
2020-07-22 18:15:39 +02:00
committed by GitHub
parent 30f04a326b
commit df0d411ba1
6 changed files with 61 additions and 26 deletions

View File

@@ -18,6 +18,7 @@ QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
#include <utils/Logger.h>
#include <QCoreApplication>
#include <QProcess>
#include <QStringList>
#include <unistd.h>
@@ -31,26 +32,20 @@ namespace Process {
void restartHyperion(bool asNewProcess)
{
Logger* log = Logger::getInstance("Process");
Info(log, "Restarting hyperion ...");
std::cout << std::endl
<< " *******************************************" << std::endl
<< " * hyperion will restart now *" << std::endl
<< " *******************************************" << std::endl << std::endl;
auto arguments = QCoreApplication::arguments();
if (!arguments.contains("--wait-hyperion"))
arguments << "--wait-hyperion";
QStringList qargs = QCoreApplication::arguments();
int size = qargs.size();
char *args[size+1];
args[size] = nullptr;
for(int i=0; i<size; i++)
{
int str_size = qargs[i].toLocal8Bit().size();
args[i] = new char[str_size+1];
strncpy(args[i], qargs[i].toLocal8Bit().constData(),str_size);
args[i][str_size] = '\0';
}
QProcess::startDetached(QCoreApplication::applicationFilePath(), arguments);
execv(args[0],args);
Error(log, "error while restarting hyperion");
QCoreApplication::quit();
}
QByteArray command_exec(QString cmd, QByteArray data)