# HG changeset patch # User Chris Cannam # Date 1290439272 0 # Node ID 32fa40c3d1740e924ee8a6985665d75c5d2f5da1 # Parent aaeabc920ca80df16a75d80a272b6633493467d3 * OS/X doesn't like fork() without exec(). Scrap that, revert to ioctl diff -r aaeabc920ca8 -r 32fa40c3d174 common.cpp --- a/common.cpp Mon Nov 22 12:30:40 2010 +0000 +++ b/common.cpp Mon Nov 22 15:21:12 2010 +0000 @@ -33,6 +33,10 @@ #include #include #include +#include +#include +#include +#include #endif QString findExecutable(QString name) @@ -148,33 +152,33 @@ void loseControllingTerminal() { #ifndef Q_OS_WIN32 - pid_t sid; - switch (fork()) { - case 0: - sid = setsid(); - if (sid != (pid_t)-1) { - DEBUG << "setsid() succeeded, session ID is " << sid << endl; + + if (!isatty(0)) { + DEBUG << "stdin is not a terminal" << endl; + } else { + DEBUG << "stdin is a terminal, detaching from it" << endl; + if (ioctl(0, TIOCNOTTY, NULL) < 0) { + perror("ioctl failed"); + DEBUG << "ioctl for TIOCNOTTY failed (errno = " << errno << ")" << endl; } else { - perror("setsid failed"); - DEBUG << "setsid() failed (errno = " << errno << ")" << endl; + DEBUG << "ioctl for TIOCNOTTY succeeded" << endl; } - switch (fork()) { - case 0: - return; - case -1: - perror("fork failed"); - DEBUG << "second fork failed (errno = " << errno << ")" << endl; - return; - default: - exit(0); + return; + } + + int ttyfd = open("/dev/tty", O_RDWR); + if (ttyfd < 0) { + DEBUG << "failed to open controlling terminal" << endl; + } else { + if (ioctl(ttyfd, TIOCNOTTY, NULL) < 0) { + perror("ioctl failed"); + DEBUG << "ioctl for TIOCNOTTY failed (errno = " << errno << ")" << endl; + } else { + DEBUG << "ioctl for TIOCNOTTY succeeded" << endl; } - case -1: - perror("fork failed"); - DEBUG << "fork failed (errno = " << errno << ")" << endl; return; - default: - exit(0); } + #endif } diff -r aaeabc920ca8 -r 32fa40c3d174 hgrunner.cpp --- a/hgrunner.cpp Mon Nov 22 12:30:40 2010 +0000 +++ b/hgrunner.cpp Mon Nov 22 15:21:12 2010 +0000 @@ -33,8 +33,12 @@ #include #ifndef Q_OS_WIN32 +#ifdef Q_OS_MAC +#include +#else #include #endif +#endif HgRunner::HgRunner(QWidget * parent): QProgressBar(parent) { @@ -138,7 +142,7 @@ { DEBUG << "stdOutReady" << endl; QString chunk = QString::fromUtf8(proc->readAllStandardOutput()); - DEBUG << "stdout was " << chunk << endl; + //DEBUG << "stdout was " << chunk << endl; stdOut += chunk; } @@ -146,7 +150,7 @@ { DEBUG << "stdErrReady" << endl; QString chunk = QString::fromUtf8(proc->readAllStandardError()); - DEBUG << "stderr was " << chunk << endl; + //DEBUG << "stderr was " << chunk << endl; stdErr += chunk; if (procInput) { if (chunk.toLower().trimmed() == "password:") {