From 1fb9c5348e3f7d4dd80e5b924aaca93632c651f9 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 22 Dec 2020 18:45:55 +0200 Subject: QProcess: consolidate channel management We have the same channel forwarding, redirecting, and merging rules for all platforms. This makes it possible to introduce the openChannels() function, which consolidates the logic and performs high-level general processing of the channels configuration properties. Change-Id: Id3574fc42a56829328369b6a1a6ec9c95fce8eca Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/corelib/io/qprocess.cpp') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 095847122a..9c6dafd7ef 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -940,6 +940,78 @@ void QProcessPrivate::setErrorAndEmit(QProcess::ProcessError error, const QStrin emit q->errorOccurred(processError); } +/*! + \internal +*/ +bool QProcessPrivate::openChannels() +{ + // stdin channel. + if (inputChannelMode == QProcess::ForwardedInputChannel) { + if (stdinChannel.type != Channel::Normal) + qWarning("QProcess::openChannels: Inconsistent stdin channel configuration"); + } else if (!openChannel(stdinChannel)) { + return false; + } + + // stdout channel. + if (processChannelMode == QProcess::ForwardedChannels + || processChannelMode == QProcess::ForwardedOutputChannel) { + if (stdoutChannel.type != Channel::Normal) + qWarning("QProcess::openChannels: Inconsistent stdout channel configuration"); + } else if (!openChannel(stdoutChannel)) { + return false; + } + + // stderr channel. + if (processChannelMode == QProcess::ForwardedChannels + || processChannelMode == QProcess::ForwardedErrorChannel + || processChannelMode == QProcess::MergedChannels) { + if (stderrChannel.type != Channel::Normal) + qWarning("QProcess::openChannels: Inconsistent stderr channel configuration"); + } else if (!openChannel(stderrChannel)) { + return false; + } + + return true; +} + +/*! + \internal +*/ +bool QProcessPrivate::openChannelsForDetached() +{ + // stdin channel. + if (stdinChannel.type != Channel::Normal + && (stdinChannel.type != Channel::Redirect + || inputChannelMode == QProcess::ForwardedInputChannel)) { + qWarning("QProcess::openChannelsForDetached: Inconsistent stdin channel configuration"); + } + if (stdinChannel.type == Channel::Redirect && !openChannel(stdinChannel)) + return false; + + // stdout channel. + if (stdoutChannel.type != Channel::Normal + && (stdoutChannel.type != Channel::Redirect + || processChannelMode == QProcess::ForwardedChannels + || processChannelMode == QProcess::ForwardedOutputChannel)) { + qWarning("QProcess::openChannelsForDetached: Inconsistent stdout channel configuration"); + } + if (stdoutChannel.type == Channel::Redirect && !openChannel(stdoutChannel)) + return false; + + // stderr channel. + if (processChannelMode == QProcess::MergedChannels || (stderrChannel.type != Channel::Normal + && (stderrChannel.type != Channel::Redirect + || processChannelMode == QProcess::ForwardedChannels + || processChannelMode == QProcess::ForwardedErrorChannel))) { + qWarning("QProcess::openChannelsForDetached: Inconsistent stderr channel configuration"); + } + if (stderrChannel.type == Channel::Redirect && !openChannel(stderrChannel)) + return false; + + return true; +} + /*! \internal Returns \c true if we emitted readyRead(). -- cgit v1.2.3