From dccc2aff6cb0bc480c6272536f595936e4ebc31d Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 8 Dec 2020 20:42:34 +0200 Subject: [PATCH] QProcess/Unix: unify waiting in 'Starting' state It makes no sense to poll the I/O pipes if we didn't get a start-up notification yet. And in fact, all waitFor...() functions except waitForReadyRead() did already explicitly wait for process startup completion. So fix that one up, and remove the handling of 'Starting' state from the I/O loops. Change-Id: Ibb7eb7c768bef3f9b6c54009c73b91775570102c Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 10 +++++++++- src/corelib/io/qprocess_unix.cpp | 23 ++--------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 1583f31e347..fb769ef74ce 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1783,7 +1783,15 @@ bool QProcess::waitForReadyRead(int msecs) return false; if (d->currentReadChannel == QProcess::StandardError && d->stderrChannel.closed) return false; - return d->waitForReadyRead(QDeadlineTimer(msecs)); + + QDeadlineTimer deadline(msecs); + if (d->processState == QProcess::Starting) { + bool started = d->waitForStarted(deadline); + if (!started) + return false; + } + + return d->waitForReadyRead(deadline); } /*! \reimp diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 636f6f2e229..bb52233a9c5 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -157,9 +157,8 @@ struct QProcessPoller pollfd &stdoutPipe() { return pfds[1]; } pollfd &stderrPipe() { return pfds[2]; } pollfd &forkfd() { return pfds[3]; } - pollfd &childStartedPipe() { return pfds[4]; } - enum { n_pfds = 5 }; + enum { n_pfds = 4 }; pollfd pfds[n_pfds]; }; @@ -177,15 +176,11 @@ QProcessPoller::QProcessPoller(const QProcessPrivate &proc) } forkfd().fd = proc.forkfd; - - if (proc.processState == QProcess::Starting) - childStartedPipe().fd = proc.childStartedPipe[0]; } int QProcessPoller::poll(const QDeadlineTimer &deadline) { - const nfds_t nfds = (childStartedPipe().fd == -1) ? 4 : 5; - return qt_poll_msecs(pfds, nfds, deadline.remainingTime()); + return qt_poll_msecs(pfds, n_pfds, deadline.remainingTime()); } } // anonymous namespace @@ -740,11 +735,6 @@ bool QProcessPrivate::waitForReadyRead(const QDeadlineTimer &deadline) return false; } - if (qt_pollfd_check(poller.childStartedPipe(), POLLIN)) { - if (!_q_startupNotification()) - return false; - } - // This calls QProcessPrivate::tryReadFromChannel(), which returns true // if we emitted readyRead() signal on the current read channel. bool readyReadEmitted = false; @@ -791,11 +781,6 @@ bool QProcessPrivate::waitForBytesWritten(const QDeadlineTimer &deadline) return false; } - if (qt_pollfd_check(poller.childStartedPipe(), POLLIN)) { - if (!_q_startupNotification()) - return false; - } - if (qt_pollfd_check(poller.stdinPipe(), POLLOUT)) return _q_canWrite(); @@ -837,10 +822,6 @@ bool QProcessPrivate::waitForFinished(const QDeadlineTimer &deadline) return false; } - if (qt_pollfd_check(poller.childStartedPipe(), POLLIN)) { - if (!_q_startupNotification()) - return false; - } if (qt_pollfd_check(poller.stdinPipe(), POLLOUT)) _q_canWrite();