summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2020-12-14 17:19:45 +0200
committerAlex Trotsenko <alex1973tr@gmail.com>2020-12-17 20:48:22 +0200
commit9dbee412724831827019a71627dfb2f8fd85686e (patch)
treeef8e76ab356b30b924a09bac7fc80a4188f800b8 /src/corelib/io
parent331fdee9dd930878f245f09a155da60742bae45e (diff)
QProcess/Unix: do not create pipes for forwarded channels
The child process inherits a standard handle of the main process in such cases: stdin - inputChannelMode == QProcess::ForwardedInputChannel, stdout - processChannelMode == QProcess::ForwardedChannels || processChannelMode == QProcess::ForwardedOutputChannel, stderr - processChannelMode == QProcess::ForwardedChannels || processChannelMode == QProcess::ForwardedErrorChannel || processChannelMode == QProcess::MergedChannels For these combinations we should not create pipes and notifiers as they would not be used. Change-Id: I8e3836e4d840a40b338c85c54645539ebcaab3f6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qprocess_unix.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index bb52233a9c..cc753541a2 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -228,12 +228,29 @@ bool QProcessPrivate::openChannel(Channel &channel)
{
Q_Q(QProcess);
- if (&channel == &stderrChannel && processChannelMode == QProcess::MergedChannels) {
- channel.pipe[0] = -1;
- channel.pipe[1] = -1;
- return true;
+ // Handle forwarding of the process channels.
+ if (&channel == &stdinChannel) {
+ if (inputChannelMode == QProcess::ForwardedInputChannel)
+ return true;
+ } else {
+ switch (processChannelMode) {
+ case QProcess::ForwardedChannels:
+ return true;
+ case QProcess::ForwardedOutputChannel:
+ if (&channel == &stdoutChannel)
+ return true;
+ break;
+ case QProcess::ForwardedErrorChannel:
+ case QProcess::MergedChannels:
+ if (&channel == &stderrChannel)
+ return true;
+ break;
+ default:
+ break;
+ }
}
+ // Create pipes and handle redirections.
if (channel.type == Channel::Normal) {
// we're piping this channel to our own process
if (qt_create_pipe(channel.pipe) != 0)
@@ -538,20 +555,18 @@ void QProcessPrivate::execChild(const char *workingDir, char **argv, char **envp
ChildError error = { 0, {} }; // force zeroing of function[8]
// copy the stdin socket if asked to (without closing on exec)
- if (inputChannelMode != QProcess::ForwardedInputChannel)
+ if (stdinChannel.pipe[0] != INVALID_Q_PIPE)
qt_safe_dup2(stdinChannel.pipe[0], STDIN_FILENO, 0);
// copy the stdout and stderr if asked to
- if (processChannelMode != QProcess::ForwardedChannels) {
- if (processChannelMode != QProcess::ForwardedOutputChannel)
- qt_safe_dup2(stdoutChannel.pipe[1], STDOUT_FILENO, 0);
-
+ if (stdoutChannel.pipe[1] != INVALID_Q_PIPE)
+ qt_safe_dup2(stdoutChannel.pipe[1], STDOUT_FILENO, 0);
+ if (stderrChannel.pipe[1] != INVALID_Q_PIPE) {
+ qt_safe_dup2(stderrChannel.pipe[1], STDERR_FILENO, 0);
+ } else {
// merge stdout and stderr if asked to
- if (processChannelMode == QProcess::MergedChannels) {
+ if (processChannelMode == QProcess::MergedChannels)
qt_safe_dup2(STDOUT_FILENO, STDERR_FILENO, 0);
- } else if (processChannelMode != QProcess::ForwardedErrorChannel) {
- qt_safe_dup2(stderrChannel.pipe[1], STDERR_FILENO, 0);
- }
}
// make sure this fd is closed if execv() succeeds