MCPcopy Create free account
hub / github.com/KDE/kdevelop / findExternalTTY

Method findExternalTTY

plugins/debuggercommon/stty.cpp:315–400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313}
314
315void STTY::findExternalTTY(QStringList terminalCommandLine)
316{
317#ifndef Q_OS_WIN
318 Q_ASSERT(!terminalCommandLine.empty());
319 const auto appName = terminalCommandLine.takeFirst();
320
321 if (QStandardPaths::findExecutable(appName).isEmpty()) {
322 m_lastError = i18n("%1 is incorrect terminal name", appName);
323 return;
324 }
325
326 QTemporaryFile file;
327 if (!file.open()) {
328 m_lastError = i18n("Can't create a temporary file");
329 return;
330 }
331
332 std::unique_ptr<QProcess, LaterDeleter> externalTerminal(new QProcess);
333
334 terminalCommandLine << QStringLiteral("sh") << QStringLiteral("-c")
335 << QLatin1String("tty>") + file.fileName()
336 + QLatin1String(";exec<&-;exec>&-;while :;do sleep 3600;done");
337
338 externalTerminal->start(appName, terminalCommandLine);
339
340 if (!externalTerminal->waitForStarted(500)) {
341 m_lastError = QLatin1String("Can't run terminal: ") + appName;
342 externalTerminal->terminate();
343 return;
344 }
345
346 for (int i = 0; i < 800; i++) {
347 if (!file.bytesAvailable()) {
348 if (externalTerminal->state() == QProcess::NotRunning && externalTerminal->exitCode()) {
349 break;
350 }
351 QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
352 usleep(8000);
353 } else {
354 qCDebug(DEBUGGERCOMMON) << "Received terminal output(tty)";
355 break;
356 }
357 }
358
359 usleep(1000);
360 ttySlave = QString::fromUtf8(file.readAll().trimmed());
361
362 file.close();
363
364 if (ttySlave.isEmpty()) {
365 m_lastError = i18n(
366 "Can't receive %1 tty/pty. Check that %1 is actually a terminal and that it accepts these arguments: %2",
367 appName, KShell::joinArgs(terminalCommandLine));
368 return;
369 }
370
371 if (externalTerminal->state() == QProcess::NotRunning) {
372 // This branch may be taken in case of inadequate external terminal command configuration.

Callers

nothing calls this directly

Calls 11

emptyMethod · 0.80
releaseMethod · 0.80
findExecutableFunction · 0.50
isEmptyMethod · 0.45
openMethod · 0.45
fileNameMethod · 0.45
startMethod · 0.45
stateMethod · 0.45
closeMethod · 0.45
setParentMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected