summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2020-12-22 18:45:55 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2020-12-31 09:34:54 +0200
commit1fb9c5348e3f7d4dd80e5b924aaca93632c651f9 (patch)
treeec320f33446073cc8a6c57a50752a390dae7851b /src/corelib/io/qprocess.cpp
parent8be9fb66f7872dc1e7a6ad729459be66ee5a1540 (diff)
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 <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qprocess.cpp')
-rw-r--r--src/corelib/io/qprocess.cpp72
1 files changed, 72 insertions, 0 deletions
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
@@ -942,6 +942,78 @@ void QProcessPrivate::setErrorAndEmit(QProcess::ProcessError error, const QStrin
/*!
\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().
*/
bool QProcessPrivate::tryReadFromChannel(Channel *channel)