From 64d6003f498d7259325719daba021d86d8deda95 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Mon, 31 May 2021 17:30:53 +0300 Subject: [PATCH] Introduce QProcessPrivate::closeChannels() Avoid duplicating code for both platforms. Change-Id: Iae00023672b63e8539cf824fa3aaaff2bf9ae0c5 Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 14 +++++++++++--- src/corelib/io/qprocess_p.h | 1 + src/corelib/io/qprocess_unix.cpp | 8 ++------ src/corelib/io/qprocess_win.cpp | 8 ++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 16fb2be0aee..878f52fd004 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -834,9 +834,7 @@ void QProcessPrivate::cleanup() delete stateNotifier; stateNotifier = nullptr; } - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); - closeChannel(&stdinChannel); + closeChannels(); destroyPipe(childStartedPipe); #ifdef Q_OS_UNIX if (forkfd != -1) @@ -923,6 +921,16 @@ bool QProcessPrivate::openChannels() return true; } +/*! + \internal +*/ +void QProcessPrivate::closeChannels() +{ + closeChannel(&stdoutChannel); + closeChannel(&stderrChannel); + closeChannel(&stdinChannel); +} + /*! \internal */ diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h index f1572055f40..6df359e4414 100644 --- a/src/corelib/io/qprocess_p.h +++ b/src/corelib/io/qprocess_p.h @@ -326,6 +326,7 @@ public: #endif void closeChannel(Channel *channel); void closeWriteChannel(); + void closeChannels(); bool tryReadFromChannel(Channel *channel); // obviously, only stdout and stderr QString program; diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 4fa36238a7b..d31691d9507 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -885,9 +885,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) if (!openChannelsForDetached()) { // openChannel sets the error string - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); return false; } @@ -935,9 +933,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) } int savedErrno = errno; - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); if (childPid == -1) { setErrorAndEmit(QProcess::FailedToStart, QLatin1String("fork: ") + qt_error_string(savedErrno)); diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp index 388e163317f..24a6e2109c7 100644 --- a/src/corelib/io/qprocess_win.cpp +++ b/src/corelib/io/qprocess_win.cpp @@ -905,9 +905,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) if (!openChannelsForDetached()) { // openChannel sets the error string - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); return false; } @@ -955,9 +953,7 @@ bool QProcessPrivate::startDetached(qint64 *pid) setErrorAndEmit(QProcess::FailedToStart); } - closeChannel(&stdinChannel); - closeChannel(&stdoutChannel); - closeChannel(&stderrChannel); + closeChannels(); return success; }