summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qprocess.h')
-rw-r--r--src/corelib/io/qprocess.h133
1 files changed, 71 insertions, 62 deletions
diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h
index f43dfad840..34724a6794 100644
--- a/src/corelib/io/qprocess.h
+++ b/src/corelib/io/qprocess.h
@@ -1,45 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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) 2023 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_H
#define QPROCESS_H
+#include <QtCore/qcompare.h>
#include <QtCore/qiodevice.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qshareddata.h>
@@ -48,13 +14,13 @@
QT_REQUIRE_CONFIG(processenvironment);
-#ifdef Q_OS_WIN
-typedef struct _PROCESS_INFORMATION *Q_PID;
-#endif
-
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
-typedef struct _SECURITY_ATTRIBUTES Q_SECURITY_ATTRIBUTES;
-typedef struct _STARTUPINFOW Q_STARTUPINFO;
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
+struct _PROCESS_INFORMATION;
+struct _SECURITY_ATTRIBUTES;
+struct _STARTUPINFOW;
+using Q_PROCESS_INFORMATION = _PROCESS_INFORMATION;
+using Q_SECURITY_ATTRIBUTES = _SECURITY_ATTRIBUTES;
+using Q_STARTUPINFO = _STARTUPINFOW;
#endif
QT_BEGIN_NAMESPACE
@@ -62,26 +28,28 @@ QT_BEGIN_NAMESPACE
class QProcessPrivate;
class QProcessEnvironmentPrivate;
-#ifndef Q_OS_WIN
-typedef qint64 Q_PID;
-#endif
-
class Q_CORE_EXPORT QProcessEnvironment
{
public:
+ enum Initialization { InheritFromParent };
+
QProcessEnvironment();
+ QProcessEnvironment(Initialization) noexcept;
QProcessEnvironment(const QProcessEnvironment &other);
~QProcessEnvironment();
- QProcessEnvironment &operator=(QProcessEnvironment && other) noexcept { swap(other); return *this; }
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QProcessEnvironment)
QProcessEnvironment &operator=(const QProcessEnvironment &other);
- void swap(QProcessEnvironment &other) noexcept { qSwap(d, other.d); }
+ void swap(QProcessEnvironment &other) noexcept { d.swap(other.d); }
+#if QT_CORE_REMOVED_SINCE(6, 8)
bool operator==(const QProcessEnvironment &other) const;
inline bool operator!=(const QProcessEnvironment &other) const
- { return !(*this == other); }
+ { return !operator==(other); }
+#endif
bool isEmpty() const;
+ [[nodiscard]] bool inheritsFromParent() const;
void clear();
bool contains(const QString &name) const;
@@ -98,6 +66,9 @@ public:
static QProcessEnvironment systemEnvironment();
private:
+ friend Q_CORE_EXPORT bool comparesEqual(const QProcessEnvironment &lhs,
+ const QProcessEnvironment &rhs);
+ Q_DECLARE_EQUALITY_COMPARABLE(QProcessEnvironment)
friend class QProcessPrivate;
friend class QProcessEnvironmentPrivate;
QSharedDataPointer<QProcessEnvironmentPrivate> d;
@@ -112,7 +83,7 @@ class Q_CORE_EXPORT QProcess : public QIODevice
Q_OBJECT
public:
enum ProcessError {
- FailedToStart, //### file not found, resource error
+ FailedToStart,
Crashed,
Timedout,
ReadError,
@@ -160,6 +131,7 @@ public:
void start(const QString &program, const QStringList &arguments = {}, OpenMode mode = ReadWrite);
void start(OpenMode mode = ReadWrite);
+ void startCommand(const QString &command, OpenMode mode = ReadWrite);
bool startDetached(qint64 *pid = nullptr);
bool open(OpenMode mode = ReadWrite) override;
@@ -185,7 +157,7 @@ public:
void setStandardErrorFile(const QString &fileName, OpenMode mode = Truncate);
void setStandardOutputProcess(QProcess *destination);
-#if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC)
+#if defined(Q_OS_WIN) || defined(Q_QDOC)
QString nativeArguments() const;
void setNativeArguments(const QString &arguments);
struct CreateProcessArguments
@@ -199,12 +171,39 @@ public:
void *environment;
const wchar_t *currentDirectory;
Q_STARTUPINFO *startupInfo;
- Q_PID processInformation;
+ Q_PROCESS_INFORMATION *processInformation;
};
typedef std::function<void(CreateProcessArguments *)> CreateProcessArgumentModifier;
CreateProcessArgumentModifier createProcessArgumentsModifier() const;
void setCreateProcessArgumentsModifier(CreateProcessArgumentModifier modifier);
-#endif // Q_OS_WIN || Q_CLANG_QDOC
+#endif // Q_OS_WIN || Q_QDOC
+#if defined(Q_OS_UNIX) || defined(Q_QDOC)
+ std::function<void(void)> childProcessModifier() const;
+ void setChildProcessModifier(const std::function<void(void)> &modifier);
+ Q_NORETURN void failChildProcessModifier(const char *description, int error = 0) noexcept;
+
+ enum class UnixProcessFlag : quint32 {
+ ResetSignalHandlers = 0x0001, // like POSIX_SPAWN_SETSIGDEF
+ IgnoreSigPipe = 0x0002,
+ // some room if we want to add IgnoreSigHup or so
+ CloseFileDescriptors = 0x0010,
+ UseVFork = 0x0020, // like POSIX_SPAWN_USEVFORK
+ CreateNewSession = 0x0040, // like POSIX_SPAWN_SETSID
+ DisconnectControllingTerminal = 0x0080,
+ ResetIds = 0x0100, // like POSIX_SPAWN_RESETIDS
+ };
+ Q_DECLARE_FLAGS(UnixProcessFlags, UnixProcessFlag)
+ struct UnixProcessParameters
+ {
+ UnixProcessFlags flags = {};
+ int lowestFileDescriptorToClose = 0;
+
+ quint32 _reserved[6] {};
+ };
+ UnixProcessParameters unixProcessParameters() const noexcept;
+ void setUnixProcessParameters(const UnixProcessParameters &params);
+ void setUnixProcessParameters(UnixProcessFlags flagsOnly);
+#endif
QString workingDirectory() const;
void setWorkingDirectory(const QString &dir);
@@ -217,8 +216,6 @@ public:
QProcess::ProcessError error() const;
QProcess::ProcessState state() const;
- // #### Qt 5: Q_PID is a pointer on Windows and a value on Unix
- Q_PID pid() const;
qint64 processId() const;
bool waitForStarted(int msecs = 30000);
@@ -263,8 +260,6 @@ Q_SIGNALS:
protected:
void setProcessState(ProcessState state);
- virtual void setupChildProcess();
-
// QIODevice
qint64 readData(char *data, qint64 maxlen) override;
qint64 writeData(const char *data, qint64 len) override;
@@ -273,14 +268,28 @@ private:
Q_DECLARE_PRIVATE(QProcess)
Q_DISABLE_COPY(QProcess)
+#if QT_VERSION < QT_VERSION_CHECK(7,0,0)
+ // ### Qt7: Remove this struct and the virtual function; they're here only
+ // to cause build errors in Qt 5 code that wasn't updated to Qt 6's
+ // setChildProcessModifier()
+ struct Use_setChildProcessModifier_Instead {};
+ QT_DEPRECATED_X("Use setChildProcessModifier() instead")
+ virtual Use_setChildProcessModifier_Instead setupChildProcess();
+#endif
+
Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardOutput())
Q_PRIVATE_SLOT(d_func(), bool _q_canReadStandardError())
+#ifdef Q_OS_UNIX
Q_PRIVATE_SLOT(d_func(), bool _q_canWrite())
+#endif
Q_PRIVATE_SLOT(d_func(), bool _q_startupNotification())
- Q_PRIVATE_SLOT(d_func(), bool _q_processDied())
- friend class QProcessManager;
+ Q_PRIVATE_SLOT(d_func(), void _q_processDied())
};
+#ifdef Q_OS_UNIX
+Q_DECLARE_OPERATORS_FOR_FLAGS(QProcess::UnixProcessFlags)
+#endif
+
#endif // QT_CONFIG(process)
QT_END_NAMESPACE