summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qprocess_p.h')
-rw-r--r--src/corelib/io/qprocess_p.h140
1 files changed, 44 insertions, 96 deletions
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index f1572055f4..9510101e74 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QPROCESS_P_H
#define QPROCESS_P_H
@@ -81,7 +45,6 @@ class QSocketNotifier;
class QWindowsPipeReader;
class QWindowsPipeWriter;
class QWinEventNotifier;
-class QTimer;
#ifdef Q_OS_WIN
class QProcEnvKey : public QString
@@ -231,23 +194,13 @@ public:
Q_DECLARE_PUBLIC(QProcess)
struct Channel {
- enum ProcessChannelType {
+ enum ProcessChannelType : char {
Normal = 0,
PipeSource = 1,
PipeSink = 2,
Redirect = 3
- // if you add "= 4" here, increase the number of bits below
};
- Channel() : process(nullptr), notifier(nullptr), type(Normal), closed(false), append(false)
- {
- pipe[0] = INVALID_Q_PIPE;
- pipe[1] = INVALID_Q_PIPE;
-#ifdef Q_OS_WIN
- reader = 0;
-#endif
- }
-
void clear();
Channel &operator=(const QString &fileName)
@@ -273,19 +226,20 @@ public:
}
QString file;
- QProcessPrivate *process;
- QSocketNotifier *notifier;
-#ifdef Q_OS_WIN
+ QProcessPrivate *process = nullptr;
+#ifdef Q_OS_UNIX
+ QSocketNotifier *notifier = nullptr;
+#else
union {
- QWindowsPipeReader *reader;
+ QWindowsPipeReader *reader = nullptr;
QWindowsPipeWriter *writer;
};
#endif
- Q_PIPE pipe[2];
+ Q_PIPE pipe[2] = {INVALID_Q_PIPE, INVALID_Q_PIPE};
- unsigned type : 2;
- bool closed : 1;
- bool append : 1;
+ ProcessChannelType type = Normal;
+ bool closed = false;
+ bool append = false;
};
QProcessPrivate();
@@ -295,65 +249,61 @@ public:
bool _q_canReadStandardOutput();
bool _q_canReadStandardError();
#ifdef Q_OS_WIN
+ qint64 pipeWriterBytesToWrite() const;
void _q_bytesWritten(qint64 bytes);
-#endif
+ void _q_writeFailed();
+#else
bool _q_canWrite();
+ bool writeToStdin();
+#endif
bool _q_startupNotification();
void _q_processDied();
- QProcess::ProcessChannelMode processChannelMode = QProcess::SeparateChannels;
- QProcess::InputChannelMode inputChannelMode = QProcess::ManagedInputChannel;
- QProcess::ProcessError processError = QProcess::UnknownError;
- QProcess::ProcessState processState = QProcess::NotRunning;
- QString workingDirectory;
-#ifdef Q_OS_WIN
- Q_PROCESS_INFORMATION *pid = nullptr;
-#else
- qint64 pid = 0;
-#endif
-
- bool emittedReadyRead = false;
- bool emittedBytesWritten = false;
-
Channel stdinChannel;
Channel stdoutChannel;
Channel stderrChannel;
bool openChannels();
bool openChannelsForDetached();
bool openChannel(Channel &channel);
-#if defined(Q_OS_UNIX)
- void commitChannels();
-#endif
void closeChannel(Channel *channel);
void closeWriteChannel();
+ void closeChannels();
bool tryReadFromChannel(Channel *channel); // obviously, only stdout and stderr
QString program;
QStringList arguments;
+ QString workingDirectory;
+ QProcessEnvironment environment = QProcessEnvironment::InheritFromParent;
#if defined(Q_OS_WIN)
QString nativeArguments;
QProcess::CreateProcessArgumentModifier modifyCreateProcessArgs;
+ QWinEventNotifier *processFinishedNotifier = nullptr;
+ Q_PROCESS_INFORMATION *pid = nullptr;
#else
- std::function<void(void)> childProcessModifier;
-#endif
- QProcessEnvironment environment;
-
- Q_PIPE childStartedPipe[2] = {INVALID_Q_PIPE, INVALID_Q_PIPE};
- void destroyPipe(Q_PIPE pipe[2]);
-
+ struct UnixExtras {
+ std::function<void(void)> childProcessModifier;
+ QProcess::UnixProcessParameters processParameters;
+ };
+ std::unique_ptr<UnixExtras> unixExtras;
QSocketNotifier *stateNotifier = nullptr;
-
+ Q_PIPE childStartedPipe[2] = {INVALID_Q_PIPE, INVALID_Q_PIPE};
+ pid_t pid = 0;
int forkfd = -1;
-
-#ifdef Q_OS_WIN
- QTimer *stdinWriteTrigger = nullptr;
- QWinEventNotifier *processFinishedNotifier = nullptr;
#endif
+ int exitCode = 0;
+ quint8 processState = QProcess::NotRunning;
+ quint8 exitStatus = QProcess::NormalExit;
+ quint8 processError = QProcess::UnknownError;
+ quint8 processChannelMode = QProcess::SeparateChannels;
+ quint8 inputChannelMode = QProcess::ManagedInputChannel;
+ bool emittedReadyRead = false;
+ bool emittedBytesWritten = false;
+
void start(QIODevice::OpenMode mode);
void startProcess();
#if defined(Q_OS_UNIX)
- void execChild(const char *workingDirectory, char **argv, char **envp);
+ void commitChannels() const;
#endif
bool processStarted(QString *errorMessage = nullptr);
void processFinished();
@@ -368,15 +318,10 @@ public:
STARTUPINFOW createStartupInfo();
bool callCreateProcess(QProcess::CreateProcessArguments *cpargs);
bool drainOutputPipes();
- qint64 pipeWriterBytesToWrite() const;
#endif
bool startDetached(qint64 *pPid);
- int exitCode = 0;
- QProcess::ExitStatus exitStatus = QProcess::NormalExit;
- bool crashed = false;
-
bool waitForStarted(const QDeadlineTimer &deadline);
bool waitForReadyRead(const QDeadlineTimer &deadline);
bool waitForBytesWritten(const QDeadlineTimer &deadline);
@@ -384,11 +329,14 @@ public:
qint64 bytesAvailableInChannel(const Channel *channel) const;
qint64 readFromChannel(const Channel *channel, char *data, qint64 maxlen);
- bool writeToStdin();
+ void destroyPipe(Q_PIPE pipe[2]);
void cleanup();
void setError(QProcess::ProcessError error, const QString &description = QString());
void setErrorAndEmit(QProcess::ProcessError error, const QString &description = QString());
+
+ const QProcessEnvironmentPrivate *environmentPrivate() const
+ { return environment.d.constData(); }
};
#endif // QT_CONFIG(process)