Fix I2P child-process bug

This commit is contained in:
FullGreaM 2026-03-07 00:57:56 +03:00
parent e5740c383f
commit 42f9643874
2 changed files with 29 additions and 1 deletions

View File

@ -2,9 +2,15 @@
#include "prog-constains.h"
#include "locales.h"
#if defined(Q_OS_LINUX)
#include <sys/prctl.h>
#include <signal.h>
#endif
I2PController::I2PController(QObject *parent)
: QObject(parent)
{
i2p.setWorkingDirectory(I2P_INSTALL_PATH);
this->isFatalErrored = false;
connect(&i2p, &QProcess::errorOccurred,
@ -14,7 +20,8 @@ I2PController::I2PController(QObject *parent)
this, &I2PController::onProcessFinished);
connect(&i2p, &QProcess::readyReadStandardOutput, this, [this]() {
qDebug() << "[i2pd]" << i2p.readAllStandardOutput();
// Logging I2P
//qDebug() << "[i2pd]" << i2p.readAllStandardOutput();
});
connect(&i2p, &QProcess::readyReadStandardError, this, [this]() {
@ -42,6 +49,18 @@ I2PController::I2PController(QObject *parent)
});
}
I2PController::~I2PController()
{
if (i2p.state() != QProcess::NotRunning)
{
i2p.terminate();
i2p.waitForFinished(3000);
if (i2p.state() != QProcess::NotRunning)
i2p.kill();
}
}
void I2PController::start() {
if (i2p.state() != QProcess::NotRunning)
{
@ -49,6 +68,13 @@ void I2PController::start() {
return;
}
#if defined(Q_OS_LINUX)
// If SIGKILL on Linux
i2p.setChildProcessModifier([]() {
prctl(PR_SET_PDEATHSIG, SIGTERM);
});
#endif
QStringList args;
#if defined(Q_OS_WIN)
this->i2p.start(QDir(I2P_INSTALL_PATH).filePath("i2pd.exe"), args);
@ -61,6 +87,7 @@ void I2PController::start() {
<< "--tunconf" << QDir(configsFolder).filePath("tunnels.conf")
<< "--log" << QDir(logsFolder).filePath("i2pd.log");
//qDebug() << "i2pd args:" << args;
this->i2p.start(QDir(I2P_INSTALL_PATH).filePath("i2pd"), args);
#else
#endif

View File

@ -12,6 +12,7 @@ class I2PController : public QObject
Q_OBJECT
public:
I2PController(QObject *parent = nullptr);
~I2PController();
void start();
private:
QProcess i2p;