diff options
Diffstat (limited to 'src/corelib/io/qprocess_unix.cpp')
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 59 |
1 files changed, 22 insertions, 37 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 8674371baa..2269740a2f 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -377,7 +377,7 @@ void QProcessPrivate::destroyPipe(int *pipe) } } -void QProcessPrivate::destroyChannel(Channel *channel) +void QProcessPrivate::closeChannel(Channel *channel) { destroyPipe(channel->pipe); } @@ -387,7 +387,7 @@ void QProcessPrivate::destroyChannel(Channel *channel) This function must be called in order: stdin, stdout, stderr */ -bool QProcessPrivate::createChannel(Channel &channel) +bool QProcessPrivate::openChannel(Channel &channel) { Q_Q(QProcess); @@ -573,9 +573,9 @@ void QProcessPrivate::startProcess() processManager()->start(); // Initialize pipes - if (!createChannel(stdinChannel) || - !createChannel(stdoutChannel) || - !createChannel(stderrChannel) || + if (!openChannel(stdinChannel) || + !openChannel(stdoutChannel) || + !openChannel(stderrChannel) || qt_create_pipe(childStartedPipe) != 0 || qt_create_pipe(deathPipe) != 0) { processError = QProcess::FailedToStart; @@ -963,47 +963,32 @@ bool QProcessPrivate::processStarted() return i <= 0; } -qint64 QProcessPrivate::bytesAvailableFromStdout() const +qint64 QProcessPrivate::bytesAvailableInChannel(const Channel *channel) const { + Q_ASSERT(channel->pipe[0] != INVALID_Q_PIPE); int nbytes = 0; qint64 available = 0; - if (::ioctl(stdoutChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0) + if (::ioctl(channel->pipe[0], FIONREAD, (char *) &nbytes) >= 0) available = (qint64) nbytes; #if defined (QPROCESS_DEBUG) - qDebug("QProcessPrivate::bytesAvailableFromStdout() == %lld", available); + qDebug("QProcessPrivate::bytesAvailableInChannel(%d) == %lld", channel - &stdinChannel, available); #endif return available; } -qint64 QProcessPrivate::bytesAvailableFromStderr() const +qint64 QProcessPrivate::readFromChannel(const Channel *channel, char *data, qint64 maxlen) { - int nbytes = 0; - qint64 available = 0; - if (::ioctl(stderrChannel.pipe[0], FIONREAD, (char *) &nbytes) >= 0) - available = (qint64) nbytes; -#if defined (QPROCESS_DEBUG) - qDebug("QProcessPrivate::bytesAvailableFromStderr() == %lld", available); -#endif - return available; -} - -qint64 QProcessPrivate::readFromStdout(char *data, qint64 maxlen) -{ - qint64 bytesRead = qt_safe_read(stdoutChannel.pipe[0], data, maxlen); -#if defined QPROCESS_DEBUG - qDebug("QProcessPrivate::readFromStdout(%p \"%s\", %lld) == %lld", - data, qt_prettyDebug(data, bytesRead, 16).constData(), maxlen, bytesRead); -#endif - return bytesRead; -} - -qint64 QProcessPrivate::readFromStderr(char *data, qint64 maxlen) -{ - qint64 bytesRead = qt_safe_read(stderrChannel.pipe[0], data, maxlen); + Q_ASSERT(channel->pipe[0] != INVALID_Q_PIPE); + qint64 bytesRead = qt_safe_read(channel->pipe[0], data, maxlen); #if defined QPROCESS_DEBUG - qDebug("QProcessPrivate::readFromStderr(%p \"%s\", %lld) == %lld", + int save_errno = errno; + qDebug("QProcessPrivate::readFromChannel(%d, %p \"%s\", %lld) == %lld", + channel - &stdinChannel, data, qt_prettyDebug(data, bytesRead, 16).constData(), maxlen, bytesRead); + errno = save_errno; #endif + if (bytesRead == -1 && errno == EWOULDBLOCK) + return -2; return bytesRead; } @@ -1126,7 +1111,7 @@ bool QProcessPrivate::waitForReadyRead(int msecs) if (stderrChannel.pipe[0] != -1) add_fd(nfds, stderrChannel.pipe[0], &fdread); - if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1) + if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1) add_fd(nfds, stdinChannel.pipe[1], &fdwrite); int timeout = qt_timeout_value(msecs, stopWatch.elapsed()); @@ -1188,7 +1173,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) QList<QSocketNotifier *> notifiers = defaultNotifiers(); #endif - while (!writeBuffer.isEmpty()) { + while (!stdinChannel.buffer.isEmpty()) { fd_set fdread; fd_set fdwrite; @@ -1207,7 +1192,7 @@ bool QProcessPrivate::waitForBytesWritten(int msecs) add_fd(nfds, stderrChannel.pipe[0], &fdread); - if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1) + if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1) add_fd(nfds, stdinChannel.pipe[1], &fdwrite); int timeout = qt_timeout_value(msecs, stopWatch.elapsed()); @@ -1282,7 +1267,7 @@ bool QProcessPrivate::waitForFinished(int msecs) if (processState == QProcess::Running) add_fd(nfds, deathPipe[0], &fdread); - if (!writeBuffer.isEmpty() && stdinChannel.pipe[1] != -1) + if (!stdinChannel.buffer.isEmpty() && stdinChannel.pipe[1] != -1) add_fd(nfds, stdinChannel.pipe[1], &fdwrite); int timeout = qt_timeout_value(msecs, stopWatch.elapsed()); |