forked from qt-creator/qt-creator
Utils: Dont auto add sudo to all processes
Terminal processes need to add to the stub and not the target app, so sudo is only automatically added for default processes. The terminal interface is changed such that sudo is added to the stub. Task-number: QTCREATORBUG-27519 Change-Id: Ife11e937644c4e946401a5b079e90fa64aee2c52 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -216,6 +216,13 @@ void DefaultImpl::start()
|
||||
return;
|
||||
if (!ensureProgramExists(program))
|
||||
return;
|
||||
|
||||
if (m_setup.m_runAsRoot && !HostOsInfo::isWindowsHost()) {
|
||||
arguments.prepend(program);
|
||||
arguments.prepend("-A");
|
||||
program = "sudo";
|
||||
}
|
||||
|
||||
s_start.measureAndRun(&DefaultImpl::doDefaultStart, this, program, arguments);
|
||||
}
|
||||
|
||||
@@ -766,15 +773,6 @@ public:
|
||||
m_blockingInterface->setParent(this);
|
||||
}
|
||||
|
||||
CommandLine fullCommandLine() const
|
||||
{
|
||||
if (!m_setup.m_runAsRoot || HostOsInfo::isWindowsHost())
|
||||
return m_setup.m_commandLine;
|
||||
CommandLine rootCommand("sudo", {"-A"});
|
||||
rootCommand.addCommandLineAsArgs(m_setup.m_commandLine);
|
||||
return rootCommand;
|
||||
}
|
||||
|
||||
Process *q;
|
||||
std::unique_ptr<ProcessBlockingInterface> m_blockingInterface;
|
||||
std::unique_ptr<ProcessInterface> m_process;
|
||||
@@ -1217,7 +1215,6 @@ void Process::start()
|
||||
d->setProcessInterface(processImpl);
|
||||
d->m_state = QProcess::Starting;
|
||||
d->m_process->m_setup = d->m_setup;
|
||||
d->m_process->m_setup.m_commandLine = d->fullCommandLine();
|
||||
d->emitGuardedSignal(&Process::starting);
|
||||
d->m_process->start();
|
||||
}
|
||||
|
||||
@@ -385,6 +385,22 @@ void TerminalInterface::start()
|
||||
ProcessSetupData stubSetupData = m_setup;
|
||||
stubSetupData.m_commandLine = cmd;
|
||||
|
||||
if (m_setup.m_runAsRoot && !HostOsInfo::isWindowsHost()) {
|
||||
CommandLine rootCommand(FilePath("sudo").searchInPath(), {"-A"});
|
||||
rootCommand.addCommandLineAsArgs(cmd);
|
||||
|
||||
const FilePath askPassPath = FilePath::fromUserInput(QCoreApplication::applicationDirPath())
|
||||
.pathAppended(QLatin1String(RELATIVE_LIBEXEC_PATH))
|
||||
.pathAppended(QLatin1String("qtc-askpass"));
|
||||
|
||||
if (askPassPath.exists())
|
||||
stubSetupData.m_environment.setFallback("SUDO_ASKPASS", askPassPath.toUserOutput());
|
||||
|
||||
stubSetupData.m_commandLine = rootCommand;
|
||||
} else {
|
||||
stubSetupData.m_commandLine = cmd;
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
d->stubCreator,
|
||||
[stubSetupData, this] { d->stubCreator->startStubProcess(stubSetupData); },
|
||||
|
||||
Reference in New Issue
Block a user