annotate hgrunner.cpp @ 188:07b908b4fa5f

* Set python library path when unbundling extension, generally prefer unbundled copy
author Chris Cannam
date Mon, 20 Dec 2010 16:15:43 +0000
parents bf366e0b9050
children 6bb510abe4f1
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
jtkorhonen@0 17
jtkorhonen@0 18 #include "hgrunner.h"
Chris@62 19 #include "common.h"
Chris@57 20 #include "debug.h"
Chris@50 21
Chris@50 22 #include <QPushButton>
Chris@50 23 #include <QListWidget>
Chris@50 24 #include <QDialog>
Chris@50 25 #include <QLabel>
Chris@50 26 #include <QVBoxLayout>
Chris@62 27 #include <QSettings>
Chris@75 28 #include <QInputDialog>
Chris@188 29 #include <QTemporaryFile>
Chris@161 30 #include <QDir>
jtkorhonen@0 31
Chris@43 32 #include <iostream>
Chris@75 33 #include <errno.h>
Chris@75 34 #include <stdio.h>
Chris@111 35 #include <stdlib.h>
jtkorhonen@0 36
Chris@76 37 #ifndef Q_OS_WIN32
Chris@111 38 #include <unistd.h>
Chris@113 39 #include <termios.h>
Chris@111 40 #include <fcntl.h>
Chris@80 41 #endif
Chris@76 42
Chris@172 43 HgRunner::HgRunner(QString myDirPath, QWidget * parent) :
Chris@172 44 QProgressBar(parent),
Chris@172 45 m_myDirPath(myDirPath)
jtkorhonen@0 46 {
Chris@113 47 m_proc = 0;
Chris@84 48
jtkorhonen@0 49 setTextVisible(false);
jtkorhonen@0 50 setVisible(false);
Chris@84 51 m_isRunning = false;
Chris@161 52
Chris@180 53 (void)findExtension();
Chris@180 54 (void)findHgBinaryName();
jtkorhonen@0 55 }
jtkorhonen@0 56
jtkorhonen@0 57 HgRunner::~HgRunner()
jtkorhonen@0 58 {
Chris@111 59 closeTerminal();
Chris@120 60 if (m_proc) {
Chris@120 61 m_proc->kill();
Chris@122 62 m_proc->deleteLater();
Chris@120 63 }
jtkorhonen@0 64 }
jtkorhonen@0 65
Chris@180 66 QString HgRunner::findExtension()
Chris@172 67 {
Chris@188 68 // If we haven't unbundled an extension, always do that (so that
Chris@188 69 // it's available in case someone wants to use it later, e.g. to
Chris@188 70 // fix a malfunctioning setup). But the path we actually prefer
Chris@188 71 // is the one in the settings first; then the unbundled one; then
Chris@188 72 // anything in the path if for some reason unbundling failed
Chris@188 73
Chris@176 74 QSettings settings;
Chris@176 75 settings.beginGroup("Locations");
Chris@188 76
Chris@188 77 QString unbundled = getUnbundledFileName();
Chris@188 78 if (!QFile(unbundled).exists()) {
Chris@188 79 unbundled = unbundleExtension();
Chris@188 80 }
Chris@188 81
Chris@180 82 QString extpath = settings.value("extensionpath", "").toString();
Chris@180 83 if (extpath != "") return extpath;
Chris@188 84
Chris@188 85 extpath = unbundled;
Chris@188 86 if (extpath == "") {
Chris@188 87 extpath = findInPath("easyhg.py", m_myDirPath, false);
Chris@188 88 if (extpath == "easyhg.py") {
Chris@188 89 extpath = "";
Chris@188 90 }
Chris@172 91 }
Chris@188 92
Chris@180 93 settings.setValue("extensionpath", extpath);
Chris@180 94 return extpath;
Chris@172 95 }
Chris@172 96
Chris@188 97 QString HgRunner::getUnbundledFileName()
Chris@188 98 {
Chris@188 99 QString home = QDir::homePath();
Chris@188 100 QString target = QString("%1/.easyhg").arg(home);
Chris@188 101 QString extpath = QString("%1/easyhg.py").arg(target);
Chris@188 102 return extpath;
Chris@188 103 }
Chris@188 104
Chris@180 105 QString HgRunner::unbundleExtension()
Chris@161 106 {
Chris@188 107 // Pull out the bundled Python file into a temporary file, and
Chris@188 108 // copy it to our known extension location, replacing the magic
Chris@188 109 // text NO_EASYHG_IMPORT_PATH with our installation location
Chris@188 110
Chris@161 111 QString bundled = ":easyhg.py";
Chris@188 112 QString unbundled = getUnbundledFileName();
Chris@188 113
Chris@188 114 QString target = QFileInfo(unbundled).path();
Chris@161 115 if (!QDir().mkpath(target)) {
Chris@161 116 DEBUG << "Failed to make unbundle path " << target << endl;
Chris@188 117 std::cerr << "Failed to make unbundle path " << target << std::endl;
Chris@180 118 return "";
Chris@161 119 }
Chris@188 120
Chris@161 121 QFile bf(bundled);
Chris@188 122 DEBUG << "unbundle: bundled file will be " << bundled << endl;
Chris@188 123 if (!bf.exists() || !bf.open(QIODevice::ReadOnly)) {
Chris@180 124 DEBUG << "Bundled extension is missing!" << endl;
Chris@180 125 return "";
Chris@180 126 }
Chris@188 127
Chris@188 128 QTemporaryFile tmpfile(QString("%1/easyhg.py.XXXXXX").arg(target));
Chris@188 129 tmpfile.setAutoRemove(false);
Chris@188 130 DEBUG << "unbundle: temp file will be " << tmpfile.fileName() << endl;
Chris@188 131 if (!tmpfile.open()) {
Chris@188 132 DEBUG << "Failed to open temporary file " << tmpfile.fileName() << endl;
Chris@188 133 std::cerr << "Failed to open temporary file " << tmpfile.fileName() << std::endl;
Chris@180 134 return "";
Chris@161 135 }
Chris@188 136
Chris@188 137 QString all = QString::fromUtf8(bf.readAll());
Chris@188 138 all.replace("NO_EASYHG_IMPORT_PATH", m_myDirPath);
Chris@188 139 tmpfile.write(all.toUtf8());
Chris@188 140 DEBUG << "unbundle: wrote " << all.length() << " characters" << endl;
Chris@188 141
Chris@188 142 tmpfile.close();
Chris@188 143
Chris@188 144 QFile ef(unbundled);
Chris@188 145 if (ef.exists()) {
Chris@188 146 DEBUG << "unbundle: removing old file " << unbundled << endl;
Chris@188 147 ef.remove();
Chris@188 148 }
Chris@188 149 DEBUG << "unbundle: renaming " << tmpfile.fileName() << " to " << unbundled << endl;
Chris@188 150 if (!tmpfile.rename(unbundled)) {
Chris@188 151 DEBUG << "Failed to move temporary file to target file " << unbundled << endl;
Chris@188 152 std::cerr << "Failed to move temporary file to target file " << unbundled << std::endl;
Chris@188 153 return "";
Chris@188 154 }
Chris@188 155
Chris@188 156 DEBUG << "Unbundled extension to " << unbundled << endl;
Chris@188 157 return unbundled;
Chris@161 158 }
Chris@161 159
Chris@109 160 void HgRunner::requestAction(HgAction action)
Chris@109 161 {
Chris@109 162 DEBUG << "requestAction " << action.action << endl;
Chris@109 163 bool pushIt = true;
Chris@109 164 if (m_queue.empty()) {
Chris@109 165 if (action == m_currentAction) {
Chris@109 166 // this request is identical to the thing we're executing
Chris@109 167 DEBUG << "requestAction: we're already handling this one, ignoring identical request" << endl;
Chris@109 168 pushIt = false;
Chris@109 169 }
Chris@109 170 } else {
Chris@109 171 HgAction last = m_queue.back();
Chris@109 172 if (action == last) {
Chris@109 173 // this request is identical to the previous thing we
Chris@109 174 // queued which we haven't executed yet
Chris@109 175 DEBUG << "requestAction: we're already queueing this one, ignoring identical request" << endl;
Chris@109 176 pushIt = false;
Chris@109 177 }
Chris@109 178 }
Chris@109 179 if (pushIt) m_queue.push_back(action);
Chris@109 180 checkQueue();
Chris@109 181 }
Chris@109 182
Chris@180 183 QString HgRunner::findHgBinaryName()
Chris@62 184 {
Chris@62 185 QSettings settings;
Chris@175 186 settings.beginGroup("Locations");
Chris@77 187 QString hg = settings.value("hgbinary", "").toString();
Chris@77 188 if (hg == "") {
Chris@172 189 hg = findInPath("hg", m_myDirPath, true);
Chris@77 190 }
Chris@77 191 if (hg != "hg") {
Chris@77 192 settings.setValue("hgbinary", hg);
Chris@77 193 }
Chris@62 194 return hg;
Chris@62 195 }
Chris@62 196
jtkorhonen@0 197 void HgRunner::started()
jtkorhonen@0 198 {
Chris@104 199 DEBUG << "started" << endl;
Chris@75 200 /*
Chris@104 201 m_proc->write("blah\n");
Chris@104 202 m_proc->write("blah\n");
Chris@104 203 m_proc -> closeWriteChannel();
Chris@75 204 */
jtkorhonen@0 205 }
jtkorhonen@0 206
Chris@84 207 void HgRunner::noteUsername(QString name)
Chris@75 208 {
Chris@84 209 m_userName = name;
Chris@75 210 }
Chris@75 211
Chris@84 212 void HgRunner::noteRealm(QString realm)
Chris@75 213 {
Chris@84 214 m_realm = realm;
Chris@84 215 }
Chris@84 216
Chris@84 217 void HgRunner::getUsername()
Chris@84 218 {
Chris@113 219 if (m_ptyFile) {
Chris@84 220 bool ok = false;
Chris@84 221 QString prompt = tr("User name:");
Chris@84 222 if (m_realm != "") {
Chris@84 223 prompt = tr("User name for \"%1\":").arg(m_realm);
Chris@84 224 }
Chris@84 225 QString pwd = QInputDialog::getText
Chris@84 226 (qobject_cast<QWidget *>(parent()),
Chris@84 227 tr("Enter user name"), prompt,
Chris@84 228 QLineEdit::Normal, QString(), &ok);
Chris@84 229 if (ok) {
Chris@113 230 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8());
Chris@113 231 m_ptyFile->flush();
Chris@84 232 return;
Chris@111 233 } else {
Chris@111 234 DEBUG << "HgRunner::getUsername: user cancelled" << endl;
Chris@111 235 killCurrentCommand();
Chris@111 236 return;
Chris@84 237 }
Chris@84 238 }
Chris@84 239 // user cancelled or something went wrong
Chris@111 240 DEBUG << "HgRunner::getUsername: something went wrong" << endl;
Chris@84 241 killCurrentCommand();
Chris@84 242 }
Chris@84 243
Chris@84 244 void HgRunner::getPassword()
Chris@84 245 {
Chris@113 246 if (m_ptyFile) {
Chris@84 247 bool ok = false;
Chris@84 248 QString prompt = tr("Password:");
Chris@84 249 if (m_userName != "") {
Chris@84 250 if (m_realm != "") {
Chris@84 251 prompt = tr("Password for \"%1\" at \"%2\":")
Chris@84 252 .arg(m_userName).arg(m_realm);
Chris@75 253 } else {
Chris@84 254 prompt = tr("Password for user \"%1\":")
Chris@84 255 .arg(m_userName);
Chris@75 256 }
Chris@75 257 }
Chris@84 258 QString pwd = QInputDialog::getText
Chris@84 259 (qobject_cast<QWidget *>(parent()),
Chris@84 260 tr("Enter password"), prompt,
Chris@84 261 QLineEdit::Password, QString(), &ok);
Chris@84 262 if (ok) {
Chris@113 263 m_ptyFile->write(QString("%1\n").arg(pwd).toUtf8());
Chris@113 264 m_ptyFile->flush();
Chris@84 265 return;
Chris@111 266 } else {
Chris@111 267 DEBUG << "HgRunner::getPassword: user cancelled" << endl;
Chris@111 268 killCurrentCommand();
Chris@111 269 return;
Chris@84 270 }
Chris@75 271 }
Chris@84 272 // user cancelled or something went wrong
Chris@111 273 DEBUG << "HgRunner::getPassword: something went wrong" << endl;
Chris@84 274 killCurrentCommand();
Chris@84 275 }
Chris@84 276
Chris@113 277 bool HgRunner::checkPrompts(QString chunk)
Chris@84 278 {
Chris@93 279 //DEBUG << "checkPrompts: " << chunk << endl;
Chris@84 280
Chris@128 281 if (!m_currentAction.mayBeInteractive()) return false;
Chris@128 282
Chris@84 283 QString text = chunk.trimmed();
Chris@84 284 QString lower = text.toLower();
Chris@84 285 if (lower.endsWith("password:")) {
Chris@84 286 getPassword();
Chris@113 287 return true;
Chris@84 288 }
Chris@128 289 if (lower.endsWith("user:") || lower.endsWith("username:")) {
Chris@84 290 getUsername();
Chris@113 291 return true;
Chris@84 292 }
Chris@128 293 QRegExp userRe("\\buser(name)?:\\s*([^\\s]+)");
Chris@84 294 if (userRe.indexIn(text) >= 0) {
Chris@128 295 noteUsername(userRe.cap(2));
Chris@84 296 }
Chris@84 297 QRegExp realmRe("\\brealmr:\\s*([^\\s]+)");
Chris@84 298 if (realmRe.indexIn(text) >= 0) {
Chris@84 299 noteRealm(realmRe.cap(1));
Chris@84 300 }
Chris@113 301 return false;
Chris@84 302 }
Chris@84 303
Chris@110 304 void HgRunner::dataReadyStdout()
Chris@84 305 {
Chris@110 306 DEBUG << "dataReadyStdout" << endl;
Chris@110 307 QString chunk = QString::fromUtf8(m_proc->readAllStandardOutput());
Chris@113 308 if (!checkPrompts(chunk)) {
Chris@113 309 m_stdout += chunk;
Chris@113 310 }
Chris@110 311 }
Chris@110 312
Chris@110 313 void HgRunner::dataReadyStderr()
Chris@110 314 {
Chris@110 315 DEBUG << "dataReadyStderr" << endl;
Chris@110 316 QString chunk = QString::fromUtf8(m_proc->readAllStandardError());
Chris@113 317 DEBUG << chunk;
Chris@113 318 if (!checkPrompts(chunk)) {
Chris@113 319 m_stderr += chunk;
Chris@113 320 }
Chris@113 321 }
Chris@113 322
Chris@113 323 void HgRunner::dataReadyPty()
Chris@113 324 {
Chris@113 325 DEBUG << "dataReadyPty" << endl;
Chris@113 326 QString chunk = QString::fromUtf8(m_ptyFile->readAll());
Chris@113 327 DEBUG << "chunk of " << chunk.length() << " chars" << endl;
Chris@113 328 if (!checkPrompts(chunk)) {
Chris@113 329 m_stdout += chunk;
Chris@113 330 }
Chris@75 331 }
Chris@75 332
jtkorhonen@0 333 void HgRunner::finished(int procExitCode, QProcess::ExitStatus procExitStatus)
jtkorhonen@0 334 {
Chris@109 335 // Save the current action and reset m_currentAction before we
Chris@109 336 // emit a signal to mark the completion; otherwise we may be
Chris@109 337 // resetting the action after a slot has already tried to set it
Chris@109 338 // to something else to start a new action
Chris@109 339
Chris@109 340 HgAction completedAction = m_currentAction;
Chris@109 341
Chris@84 342 m_isRunning = false;
Chris@109 343 m_currentAction = HgAction();
Chris@84 344
Chris@84 345 closeProcInput();
Chris@113 346 delete m_proc;
Chris@113 347 m_proc = 0;
jtkorhonen@0 348
Chris@109 349 if (completedAction.action == ACT_NONE) {
Chris@109 350 DEBUG << "HgRunner::finished: WARNING: completed action is ACT_NONE" << endl;
Chris@62 351 } else {
Chris@113 352 if (procExitCode == 0 && procExitStatus == QProcess::NormalExit) {
Chris@113 353 DEBUG << "HgRunner::finished: Command completed successfully"
Chris@113 354 << endl;
Chris@124 355 // DEBUG << "stdout is " << m_stdout << endl;
Chris@113 356 emit commandCompleted(completedAction, m_stdout);
Chris@113 357 } else {
Chris@113 358 DEBUG << "HgRunner::finished: Command failed, exit code "
Chris@113 359 << procExitCode << ", exit status " << procExitStatus
Chris@113 360 << ", stderr follows" << endl;
Chris@113 361 DEBUG << m_stderr << endl;
Chris@113 362 emit commandFailed(completedAction, m_stderr);
Chris@113 363 }
jtkorhonen@0 364 }
Chris@109 365
Chris@109 366 checkQueue();
jtkorhonen@0 367 }
jtkorhonen@0 368
Chris@182 369 void HgRunner::killCurrentActions()
Chris@182 370 {
Chris@182 371 m_queue.clear();
Chris@182 372 killCurrentCommand();
Chris@182 373 }
Chris@182 374
Chris@62 375 void HgRunner::killCurrentCommand()
jtkorhonen@0 376 {
Chris@109 377 if (m_isRunning) {
Chris@113 378 m_currentAction.action = ACT_NONE; // so that we don't bother to notify
Chris@113 379 m_proc->kill();
jtkorhonen@0 380 }
jtkorhonen@0 381 }
jtkorhonen@0 382
Chris@109 383 void HgRunner::checkQueue()
Chris@62 384 {
Chris@109 385 if (m_isRunning) {
Chris@109 386 return;
Chris@109 387 }
Chris@109 388 if (m_queue.empty()) {
Chris@109 389 hide();
Chris@109 390 return;
Chris@109 391 }
Chris@109 392 HgAction toRun = m_queue.front();
Chris@109 393 m_queue.pop_front();
Chris@109 394 DEBUG << "checkQueue: have action: running " << toRun.action << endl;
Chris@109 395 startCommand(toRun);
Chris@109 396 }
Chris@109 397
Chris@109 398 void HgRunner::startCommand(HgAction action)
Chris@109 399 {
Chris@109 400 QString executable = action.executable;
Chris@109 401 bool interactive = false;
Chris@109 402 QStringList params = action.params;
Chris@109 403
Chris@109 404 if (executable == "") {
Chris@109 405 // This is a Hg command
Chris@180 406 executable = findHgBinaryName();
Chris@161 407
Chris@161 408 if (action.mayBeInteractive()) {
Chris@161 409 params.push_front("ui.interactive=true");
Chris@161 410 params.push_front("--config");
Chris@176 411
Chris@176 412 QSettings settings;
Chris@176 413 settings.beginGroup("General");
Chris@176 414 if (settings.value("useextension", true).toBool()) {
Chris@180 415 QString extpath = findExtension();
Chris@180 416 params.push_front(QString("extensions.easyhg=%1").arg(extpath));
Chris@176 417 params.push_front("--config");
Chris@176 418 }
Chris@161 419 interactive = true;
Chris@161 420 }
Chris@161 421
Chris@161 422 //!!! want an option to use the mercurial_keyring extension as well
Chris@107 423 }
jtkorhonen@0 424
Chris@84 425 m_isRunning = true;
jtkorhonen@0 426 setRange(0, 0);
Chris@115 427 if (!action.shouldBeFast()) show();
Chris@110 428 m_stdout.clear();
Chris@110 429 m_stderr.clear();
Chris@84 430 m_realm = "";
Chris@84 431 m_userName = "";
jtkorhonen@0 432
Chris@113 433 m_proc = new QProcess;
Chris@113 434
Chris@177 435 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
Chris@177 436
Chris@177 437 #ifdef Q_OS_WIN32
Chris@177 438 if (m_myDirPath != "") {
Chris@177 439 env.insert("PATH", m_myDirPath + ";" + env.value("PATH"));
Chris@172 440 }
Chris@172 441 #endif
Chris@172 442
Chris@113 443 env.insert("LANG", "en_US.utf8");
Chris@113 444 env.insert("LC_ALL", "en_US.utf8");
Chris@113 445 env.insert("HGPLAIN", "1");
Chris@113 446 m_proc->setProcessEnvironment(env);
Chris@113 447
Chris@113 448 connect(m_proc, SIGNAL(started()), this, SLOT(started()));
Chris@113 449 connect(m_proc, SIGNAL(finished(int, QProcess::ExitStatus)),
Chris@113 450 this, SLOT(finished(int, QProcess::ExitStatus)));
Chris@113 451 connect(m_proc, SIGNAL(readyReadStandardOutput()),
Chris@113 452 this, SLOT(dataReadyStdout()));
Chris@113 453 connect(m_proc, SIGNAL(readyReadStandardError()),
Chris@113 454 this, SLOT(dataReadyStderr()));
Chris@113 455
Chris@109 456 if (!action.workingDir.isEmpty()) {
Chris@109 457 m_proc->setWorkingDirectory(action.workingDir);
jtkorhonen@0 458 }
jtkorhonen@0 459
Chris@107 460 if (interactive) {
Chris@111 461 openTerminal();
Chris@111 462 if (m_ptySlaveFilename != "") {
Chris@113 463 DEBUG << "HgRunner: connecting to pseudoterminal" << endl;
Chris@107 464 m_proc->setStandardInputFile(m_ptySlaveFilename);
Chris@114 465 // m_proc->setStandardOutputFile(m_ptySlaveFilename);
Chris@113 466 // m_proc->setStandardErrorFile(m_ptySlaveFilename);
Chris@107 467 }
Chris@84 468 }
Chris@84 469
Chris@109 470 QString cmdline = executable;
Chris@57 471 foreach (QString param, params) cmdline += " " + param;
Chris@64 472 DEBUG << "HgRunner: starting: " << cmdline << " with cwd "
Chris@109 473 << action.workingDir << endl;
Chris@43 474
Chris@109 475 m_currentAction = action;
Chris@109 476
Chris@113 477 // fill these out with what we actually ran
Chris@113 478 m_currentAction.executable = executable;
Chris@113 479 m_currentAction.params = params;
Chris@113 480
Chris@109 481 DEBUG << "set current action to " << m_currentAction.action << endl;
Chris@109 482
Chris@109 483 m_proc->start(executable, params);
Chris@84 484 }
Chris@84 485
Chris@84 486 void HgRunner::closeProcInput()
Chris@84 487 {
Chris@84 488 DEBUG << "closeProcInput" << endl;
Chris@84 489
Chris@84 490 m_proc->closeWriteChannel();
Chris@111 491 }
Chris@111 492
Chris@111 493 void HgRunner::openTerminal()
Chris@111 494 {
Chris@111 495 #ifndef Q_OS_WIN32
Chris@111 496 if (m_ptySlaveFilename != "") return; // already open
Chris@111 497 DEBUG << "HgRunner::openTerminal: trying to open new pty" << endl;
Chris@111 498 int master = posix_openpt(O_RDWR | O_NOCTTY);
Chris@111 499 if (master < 0) {
Chris@111 500 DEBUG << "openpt failed" << endl;
Chris@111 501 perror("openpt failed");
Chris@111 502 return;
Chris@111 503 }
Chris@113 504 struct termios t;
Chris@113 505 if (tcgetattr(master, &t)) {
Chris@113 506 DEBUG << "tcgetattr failed" << endl;
Chris@113 507 perror("tcgetattr failed");
Chris@113 508 }
Chris@113 509 cfmakeraw(&t);
Chris@113 510 if (tcsetattr(master, TCSANOW, &t)) {
Chris@113 511 DEBUG << "tcsetattr failed" << endl;
Chris@113 512 perror("tcsetattr failed");
Chris@113 513 }
Chris@111 514 if (grantpt(master)) {
Chris@111 515 perror("grantpt failed");
Chris@111 516 }
Chris@111 517 if (unlockpt(master)) {
Chris@111 518 perror("unlockpt failed");
Chris@111 519 }
Chris@111 520 char *slave = ptsname(master);
Chris@111 521 if (!slave) {
Chris@111 522 perror("ptsname failed");
Chris@111 523 ::close(master);
Chris@111 524 return;
Chris@111 525 }
Chris@111 526 m_ptyMasterFd = master;
Chris@113 527 m_ptyFile = new QFile();
Chris@113 528 connect(m_ptyFile, SIGNAL(readyRead()), this, SLOT(dataReadyPty()));
Chris@113 529 if (!m_ptyFile->open(m_ptyMasterFd, QFile::ReadWrite)) {
Chris@113 530 DEBUG << "HgRunner::openTerminal: Failed to open QFile on master fd" << endl;
Chris@113 531 }
Chris@111 532 m_ptySlaveFilename = slave;
Chris@111 533 DEBUG << "HgRunner::openTerminal: succeeded, slave is "
Chris@111 534 << m_ptySlaveFilename << endl;
Chris@111 535 #endif
Chris@111 536 }
Chris@111 537
Chris@111 538 void HgRunner::closeTerminal()
Chris@111 539 {
Chris@84 540 #ifndef Q_OS_WIN32
Chris@84 541 if (m_ptySlaveFilename != "") {
Chris@113 542 delete m_ptyFile;
Chris@113 543 m_ptyFile = 0;
Chris@84 544 ::close(m_ptyMasterFd);
Chris@84 545 m_ptySlaveFilename = "";
Chris@84 546 }
Chris@84 547 #endif
jtkorhonen@0 548 }