From 8db29850b168d9abc3c3d14af94878a819545514 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 16 Mar 2023 18:25:25 -0700 Subject: [PATCH] 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 --- src/libs/utils/launcherinterface.cpp | 24 ++++++++--------------- src/libs/utils/processutils.cpp | 29 ++++++++++++---------------- src/libs/utils/processutils.h | 1 - 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/libs/utils/launcherinterface.cpp b/src/libs/utils/launcherinterface.cpp index e71b09b0edc..218286521db 100644 --- a/src/libs/utils/launcherinterface.cpp +++ b/src/libs/utils/launcherinterface.cpp @@ -21,20 +21,6 @@ namespace Utils { namespace Internal { -class LauncherProcess : public QProcess -{ -public: - LauncherProcess(QObject *parent) : QProcess(parent) - { -#ifdef Q_OS_UNIX - setChildProcessModifier([this] { - const auto pid = static_cast(processId()); - setpgid(pid, pid); - }); -#endif - } -}; - static QString launcherSocketName() { return TemporaryDirectory::masterDirectoryPath() @@ -64,7 +50,7 @@ signals: private: QLocalServer * const m_server; Internal::LauncherSocket *const m_socket; - Internal::LauncherProcess *m_process = nullptr; + QProcess *m_process = nullptr; QString m_pathToLauncher; }; @@ -89,12 +75,18 @@ void LauncherInterfacePrivate::doStart() emit errorOccurred(m_server->errorString()); return; } - m_process = new LauncherProcess(this); + m_process = new QProcess(this); connect(m_process, &QProcess::errorOccurred, this, &LauncherInterfacePrivate::handleProcessError); connect(m_process, &QProcess::finished, this, &LauncherInterfacePrivate::handleProcessFinished); connect(m_process, &QProcess::readyReadStandardError, this, &LauncherInterfacePrivate::handleProcessStderr); +#ifdef Q_OS_UNIX + m_process->setChildProcessModifier([] { + setpgid(0, 0); + }); +#endif + m_process->start(launcherFilePath(), QStringList(m_server->fullServerName())); } diff --git a/src/libs/utils/processutils.cpp b/src/libs/utils/processutils.cpp index b534d6f8bb2..62ea514b658 100644 --- a/src/libs/utils/processutils.cpp +++ b/src/libs/utils/processutils.cpp @@ -107,7 +107,18 @@ ProcessHelper::ProcessHelper(QObject *parent) : QProcess(parent), m_processStartHandler(this) { #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 } @@ -153,20 +164,4 @@ void ProcessHelper::interruptProcess(QProcess *process) 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 diff --git a/src/libs/utils/processutils.h b/src/libs/utils/processutils.h index fa915e2ac42..89202c0daf2 100644 --- a/src/libs/utils/processutils.h +++ b/src/libs/utils/processutils.h @@ -50,7 +50,6 @@ public: private: void terminateProcess(); - void setupChildProcess_impl(); bool m_lowPriority = false; bool m_unixTerminalDisabled = false;