Clean up legacy content from Qt 5's QProcess::setupChildProcess()

We needed a derived class because in Qt 5 we needed to override the
setupChildProcess() virtual. Now have setChildProcessModifier(). The
actual subclassing was removed in a prior commit; this merely cleans
stuff up.

Drive-by fix the arguments to setpgid: processId() always returns 0 in
the child process.

Change-Id: Icfe44ecf285a480fafe4fffd174d1073c0e1ddc3
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
Thiago Macieira
2023-03-16 18:25:25 -07:00
parent cacc4aeede
commit 8db29850b1
3 changed files with 20 additions and 34 deletions

View File

@@ -21,20 +21,6 @@
namespace Utils { namespace Utils {
namespace Internal { namespace Internal {
class LauncherProcess : public QProcess
{
public:
LauncherProcess(QObject *parent) : QProcess(parent)
{
#ifdef Q_OS_UNIX
setChildProcessModifier([this] {
const auto pid = static_cast<pid_t>(processId());
setpgid(pid, pid);
});
#endif
}
};
static QString launcherSocketName() static QString launcherSocketName()
{ {
return TemporaryDirectory::masterDirectoryPath() return TemporaryDirectory::masterDirectoryPath()
@@ -64,7 +50,7 @@ signals:
private: private:
QLocalServer * const m_server; QLocalServer * const m_server;
Internal::LauncherSocket *const m_socket; Internal::LauncherSocket *const m_socket;
Internal::LauncherProcess *m_process = nullptr; QProcess *m_process = nullptr;
QString m_pathToLauncher; QString m_pathToLauncher;
}; };
@@ -89,12 +75,18 @@ void LauncherInterfacePrivate::doStart()
emit errorOccurred(m_server->errorString()); emit errorOccurred(m_server->errorString());
return; return;
} }
m_process = new LauncherProcess(this); m_process = new QProcess(this);
connect(m_process, &QProcess::errorOccurred, this, &LauncherInterfacePrivate::handleProcessError); connect(m_process, &QProcess::errorOccurred, this, &LauncherInterfacePrivate::handleProcessError);
connect(m_process, &QProcess::finished, connect(m_process, &QProcess::finished,
this, &LauncherInterfacePrivate::handleProcessFinished); this, &LauncherInterfacePrivate::handleProcessFinished);
connect(m_process, &QProcess::readyReadStandardError, connect(m_process, &QProcess::readyReadStandardError,
this, &LauncherInterfacePrivate::handleProcessStderr); this, &LauncherInterfacePrivate::handleProcessStderr);
#ifdef Q_OS_UNIX
m_process->setChildProcessModifier([] {
setpgid(0, 0);
});
#endif
m_process->start(launcherFilePath(), QStringList(m_server->fullServerName())); m_process->start(launcherFilePath(), QStringList(m_server->fullServerName()));
} }

View File

@@ -107,7 +107,18 @@ ProcessHelper::ProcessHelper(QObject *parent)
: QProcess(parent), m_processStartHandler(this) : QProcess(parent), m_processStartHandler(this)
{ {
#if defined(Q_OS_UNIX) #if defined(Q_OS_UNIX)
setChildProcessModifier([this] { setupChildProcess_impl(); }); setChildProcessModifier([this] {
// nice value range is -20 to +19 where -20 is highest, 0 default and +19 is lowest
if (m_lowPriority) {
errno = 0;
if (::nice(5) == -1 && errno != 0)
perror("Failed to set nice value");
}
// Disable terminal by becoming a session leader.
if (m_unixTerminalDisabled)
setsid();
});
#endif #endif
} }
@@ -153,20 +164,4 @@ void ProcessHelper::interruptProcess(QProcess *process)
ProcessHelper::interruptPid(process->processId()); ProcessHelper::interruptPid(process->processId());
} }
void ProcessHelper::setupChildProcess_impl()
{
#if defined Q_OS_UNIX
// nice value range is -20 to +19 where -20 is highest, 0 default and +19 is lowest
if (m_lowPriority) {
errno = 0;
if (::nice(5) == -1 && errno != 0)
perror("Failed to set nice value");
}
// Disable terminal by becoming a session leader.
if (m_unixTerminalDisabled)
setsid();
#endif
}
} // namespace Utils } // namespace Utils

View File

@@ -50,7 +50,6 @@ public:
private: private:
void terminateProcess(); void terminateProcess();
void setupChildProcess_impl();
bool m_lowPriority = false; bool m_lowPriority = false;
bool m_unixTerminalDisabled = false; bool m_unixTerminalDisabled = false;