summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-05-31 17:30:53 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2021-05-31 21:50:07 +0300
commit64d6003f498d7259325719daba021d86d8deda95 (patch)
tree04727340dce1484ce044f6df1d17cada00e95a66 /src/corelib/io
parent86542054d035c43f926eeb96b517108eb825831e (diff)
Introduce QProcessPrivate::closeChannels()
Avoid duplicating code for both platforms. Change-Id: Iae00023672b63e8539cf824fa3aaaff2bf9ae0c5 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qprocess.cpp14
-rw-r--r--src/corelib/io/qprocess_p.h1
-rw-r--r--src/corelib/io/qprocess_unix.cpp8
-rw-r--r--src/corelib/io/qprocess_win.cpp8
4 files changed, 16 insertions, 15 deletions
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 16fb2be0ae..878f52fd00 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)
@@ -926,6 +924,16 @@ bool QProcessPrivate::openChannels()
/*!
\internal
*/
+void QProcessPrivate::closeChannels()
+{
+ closeChannel(&stdoutChannel);
+ closeChannel(&stderrChannel);
+ closeChannel(&stdinChannel);
+}
+
+/*!
+ \internal
+*/
bool QProcessPrivate::openChannelsForDetached()
{
// stdin channel.
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index f1572055f4..6df359e441 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 4fa36238a7..d31691d950 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 388e163317..24a6e2109c 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;
}