summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess_unix.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2020-12-28 19:43:52 +0200
committerOswald Buddenhagen <oswald.buddenhagen@gmx.de>2020-12-31 12:16:38 +0000
commit04c34eb7992c88a84b04928985c231c44694ae8f (patch)
tree3906aa6b84a281787ac6ad081c92c69d8b2e3c05 /src/corelib/io/qprocess_unix.cpp
parent1fb9c5348e3f7d4dd80e5b924aaca93632c651f9 (diff)
QProcess: allow merged channels forwarding for detached processes
[ChangeLog][QtCore][QProcess] Added support for QProcess::MergedChannels mode with startDetached(). Change-Id: I953ad2063322015332269522a297f8e2842e438c Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qprocess_unix.cpp')
-rw-r--r--src/corelib/io/qprocess_unix.cpp45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index f12d92b253..c9ede9c3e9 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -319,6 +319,24 @@ bool QProcessPrivate::openChannel(Channel &channel)
}
}
+void QProcessPrivate::commitChannels()
+{
+ // copy the stdin socket if asked to (without closing on exec)
+ 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 (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)
+ qt_safe_dup2(STDOUT_FILENO, STDERR_FILENO, 0);
+ }
+}
+
static char **_q_dupEnvironment(const QProcessEnvironmentPrivate::Map &environment, int *envc)
{
*envc = 0;
@@ -525,20 +543,8 @@ 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 (stdinChannel.pipe[0] != INVALID_Q_PIPE)
- qt_safe_dup2(stdinChannel.pipe[0], STDIN_FILENO, 0);
-
- // copy the stdout and stderr if asked to
- 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)
- qt_safe_dup2(STDOUT_FILENO, STDERR_FILENO, 0);
- }
+ // Render channels configuration.
+ commitChannels();
// make sure this fd is closed if execv() succeeds
qt_safe_close(childStartedPipe[0]);
@@ -901,15 +907,8 @@ bool QProcessPrivate::startDetached(qint64 *pid)
if (doubleForkPid == 0) {
qt_safe_close(pidPipe[1]);
- // copy the stdin socket if asked to (without closing on exec)
- if (stdinChannel.type == Channel::Redirect)
- qt_safe_dup2(stdinChannel.pipe[0], STDIN_FILENO, 0);
-
- // copy the stdout and stderr if asked to
- if (stdoutChannel.type == Channel::Redirect)
- qt_safe_dup2(stdoutChannel.pipe[1], STDOUT_FILENO, 0);
- if (stderrChannel.type == Channel::Redirect)
- qt_safe_dup2(stderrChannel.pipe[1], STDERR_FILENO, 0);
+ // Render channels configuration.
+ commitChannels();
if (!encodedWorkingDirectory.isEmpty()) {
if (QT_CHDIR(encodedWorkingDirectory.constData()) == -1)