2020-05-12 19:51:19 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <QString>
|
|
|
|
#include <QByteArray>
|
|
|
|
namespace Process {
|
|
|
|
|
|
|
|
void restartHyperion(bool asNewProcess){}
|
|
|
|
|
2020-06-28 23:12:22 +02:00
|
|
|
QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
|
2020-05-12 19:51:19 +02:00
|
|
|
{
|
|
|
|
return QSTRING_CSTR(QString());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-09-15 20:42:58 +02:00
|
|
|
#include <utils/Process.h>
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
namespace Process {
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-09-15 20:42:58 +02:00
|
|
|
void restartHyperion(bool asNewProcess)
|
|
|
|
{
|
|
|
|
Logger* log = Logger::getInstance("Process");
|
|
|
|
std::cout << std::endl
|
|
|
|
<< " *******************************************" << std::endl
|
|
|
|
<< " * hyperion will restart now *" << std::endl
|
|
|
|
<< " *******************************************" << std::endl << std::endl;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
|
2016-09-15 20:42:58 +02:00
|
|
|
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];
|
2020-06-28 23:12:22 +02:00
|
|
|
strncpy(args[i], qargs[i].toLocal8Bit().constData(),str_size);
|
2016-09-15 20:42:58 +02:00
|
|
|
args[i][str_size] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
execv(args[0],args);
|
|
|
|
Error(log, "error while restarting hyperion");
|
|
|
|
}
|
|
|
|
|
2017-01-29 21:20:12 +01:00
|
|
|
QByteArray command_exec(QString cmd, QByteArray data)
|
2016-09-15 20:42:58 +02:00
|
|
|
{
|
|
|
|
char buffer[128];
|
2020-06-28 23:12:22 +02:00
|
|
|
QString result;
|
2017-01-29 21:20:12 +01:00
|
|
|
|
|
|
|
std::shared_ptr<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
|
2018-12-27 23:11:32 +01:00
|
|
|
if (pipe)
|
2016-09-15 20:42:58 +02:00
|
|
|
{
|
2017-01-29 21:20:12 +01:00
|
|
|
while (!feof(pipe.get()))
|
|
|
|
{
|
|
|
|
if (fgets(buffer, 128, pipe.get()) != NULL)
|
|
|
|
result += buffer;
|
|
|
|
}
|
2016-09-15 20:42:58 +02:00
|
|
|
}
|
2017-03-04 22:17:42 +01:00
|
|
|
return QSTRING_CSTR(result);
|
2016-09-15 20:42:58 +02:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
};
|
2020-05-12 19:51:19 +02:00
|
|
|
|
2020-06-28 23:12:22 +02:00
|
|
|
#endif
|