summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qprocess.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QProcess: fix startCommand() with whitespace-only stringsThiago Macieira2024-04-191-0/+4
| | | | | | | | | | | | | | We'd end up trying to takeFirst() from an empty QStringList. [ChangeLog][QtCore][QProcess] Fixed a bug that would cause startCommand() to crash if passed a string that was empty or contained only whitespace characters. Fixes: QTBUG-124512 Pick-to: 6.5 6.6 6.7 Change-Id: I455fe22ef4ad4b2f9b01fffd17c7689095c39272 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProcess/Doc: remove the note that about FailedToStart after started()Thiago Macieira2024-03-031-3/+0
| | | | | | | | | | | | | | | | | | It was added in commit 75a2c81b0041df4ca59178cf52d9e5a8815f3524: Handle posix_spawn using exit code 127 to indicate fail-to-start Most posix_spawn implementations are done using fork(), so the only way to report errors afer fork() is via a special exit code. Support for posix_spawn was removed when we dropped QNX 6.5 support in Qt 5.7 (commit 005a8bfbf0022f03dafafcf2b5c438ccf0675a49). Also complements commit d012e953bfb498091c0ea9a83a717a3deffc670f. Pick-to: 6.6 6.7 Change-Id: I76ffba14ece04f24b43efffd17aadead7c30146b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QProcessEnvironment: Use new comparison helper macrosRym Bouabid2024-02-221-6/+10
| | | | | | | | | | | | | | | QProcessEnvironment had operator==() and operator!=() defined as public member functions, so use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of these methods and replace them with a hidden friend. Use QT_TEST_ALL_EQUALITY_OPS macro in unit-tests. Use new \compares command in the documentation to describe the comparison operators provided by QProcessEnvironment. Task-number: QTBUG-120303 Change-Id: I4c57f6cfb9589e82a37eea6993e079212b34cecd Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QProcess/Doc: clarify that early crashes happen after started()Thiago Macieira2024-01-211-0/+6
| | | | | | | | | | | This is notable when dynamic linking fails, because that happens before the first line of main() (or equivalent) of the child process, so even banners printed by that function may be missing. Pick-to: 6.7 Change-Id: I5201966b308e48989c06fffd17aa9837156e23f4 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess/Doc: clarify that started() may be emitted very earlyThiago Macieira2024-01-211-12/+15
| | | | | | | | | | | | | | | | | | | | On Windows, process creation is synchronous so we will always emit either started() or errorOccurred() before QProcess::start() returns. This condition doesn't currently happen on Unix systems, but we could do that because we're now using vfork() on most platforms, so the child process has either successfully execve()d or _exit()ed before QProcessPrivate::startProcess continued. Drive-by reorganization of the code to remove the one-line \note in the middle of the docs. Pick-to: 6.5 6.6 6.7 Fixes: QTBUG-120968 Task-number: QTCREATORBUG-30066 Change-Id: I4d0668e0fae5299551ff91480828a68e62fdacec Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
* QProcess/Unix: add a simple way to reset the UID and GID for the childThiago Macieira2023-07-081-0/+6
| | | | | | | | | | | | | | | This is done as one of the last steps inside QProcess itself, so the child modifier and all other tasks still run with the parent process' permissions. On Linux, setting the UID to non-zero will also automatically clear the effective capabilities(7) set. This feature is only useful for setuid or setgid applications, so this commit updates the QCoreApplication::setSetuidAllowed() documentation to mention the QProcess flag. Change-Id: I3e3bfef633af4130a03afffd175e940c0668d244 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QProcess/Unix: add a few, basic session & terminal management flagsThiago Macieira2023-07-081-0/+16
| | | | | | | | | | | | Doing setsid() and disconnecting from the controlling terminal are, in addition to resetting the standard file descriptors to /dev/null, a common task that daemons do. These options allow a QProcess to force a child to be a daemon. QProcess ensures that the operations are done in the correct order. Change-Id: I3e3bfef633af4130a03afffd175e9451d2716d7a Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QProcess/Unix: add failChildProcessModifier()Thiago Macieira2023-06-091-3/+45
| | | | | | | | | | | | | | | QProcess detects other types of failures from inside the modifier as successful starts, because the childStartedPipe gets closed without an error condition getting written. The new method allows a reporting as a proper failure-to-start. Added tests for both cases. [ChangeLog][QtCore][QProcess] Added failChildProcessModifier(). Change-Id: Icfe44ecf285a480fafe4fffd174da2b10306d3c2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProcess/Unix: update the close-file-descriptors feature with a minimumThiago Macieira2023-06-091-4/+13
| | | | | | | | | | | | | | | | | | | | So that one can pass a few extra file descriptors to the child while still closing all the rest. strace -f of this test showed on Linux: [pid 117952] dup3(4, 0, 0) = 0 [pid 117952] dup3(9, 1, 0) = 1 [pid 117952] dup3(11, 2, 0) = 2 [pid 117952] close(12) = 0 [pid 117952] dup2(100, 3) = 3 [pid 117952] close_range(4, 2147483647, 0) = 0 [pid 117952] execve("testUnixProcessParameters/testUnixProcessParameters", ["testUnixProcessParameters/testUn"..., "file-descriptors2", "3", "100"], 0x561793dc87d0 /* 120 vars */ <unfinished ...> Pick-to: 6.6 Change-Id: I3e3bfef633af4130a03afffd175e984bf50b558d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Fix documentation for QProcess::UnixProcessFlagTopi Reinio2023-06-091-1/+1
| | | | | | Pick-to: 6.6 Change-Id: I6001b8c4e73d9785df8338d4d14fcf15f09eae15 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QProcess/Linux: add a flag to re-enable the vfork()-like semanticsThiago Macieira2023-05-221-0/+19
| | | | | | | | | | | | | | | | | | Commit 29b2fe40dc778ec73da7e5643fcfd8979d8ecebc disabled it by reverting commit d6bf71123d3ef073f25610345cb5dc920e4fb783. We now add the promised flag to opt-in. The flag is added to all Unix systems, but it really only applies to Linux right now. No ChangeLog because the whole UnixProcessParameters structure is new and has its own changelog. Task-number: QTBUG-104493 Task-number: QTBUG-111243 Task-number: QTBUG-111964 Change-Id: Icfe44ecf285a480fafe4fffd174d4effd3382495 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess/Unix: add setUnixProcessParameters()Thiago Macieira2023-05-221-8/+127
| | | | | | | | | | | | | | | This commit adds those three flags that are either frequent enough or difficult to do: close all file descriptors above stderr and reset the signal handlers. Setting SIGPIPE to be ignored isn't critical, but is required when the ResetSignalHandlers flag is used, as this is run after the user child process modifier. [ChangeLog][QtCore][QProcess] Added setUnixProcessParameters() function that can be used to modify certain settings of the child process, without the need to provide a callback using setChildProcessModifier(). Change-Id: Icfe44ecf285a480fafe4fffd174d0d1d63840403 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Revert commit "don't ever force fork() instead of forkfd()"Thiago Macieira2023-05-151-9/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit d6bf71123d3ef073f25610345cb5dc920e4fb783 and the docs from commit 82b75570f099911076ad0e144927862e8e359fbd ("QProcess/Linux: fix file descriptor leak in case of failed child start"). Despite the title of the commit being reverted, the actual consequence is slightly different: we always use the forkfd() function, but we change whether we force the use of the fork() library function by use of the FFD_USE_FORK flag. Commit 97645478de3ceffce11f58eab140c4c775e48be5 (5.15) first added the FFD_USE_FORK flag with a hack to detect whether the setupChild() virtual might have been overwritten. A configure-time feature to force the flag was added in commit 2ed99ff5ca338ac02f71c347b1449d4662e6c221 (6.0). Before the 6.0 release, commit d6bf71123d3ef073f25610345cb5dc920e4fb783 removed the conditional use of FFD_USE_FORK, with the changelog message saying "pthread_atfork() callbacks are consistently not invoked". We've also since added vfork()-like behavior. We tried it for Qt 5.15 and reverted shortly afterwards because we had got the memory semantics wrong. Commit e1a787a76ed462e4ed49db78a40c6d7e272182d7 (6.5) finally got it right, for Linux, which revealed another set of problems with functions used in the child process modifier. Therefore, we're going to make vfork() and clone() usage opt-in if the child process modifier is active. This commit is the first part: disabling their use by default. The flag to opt in will come in Qt 6.6. [ChangeLog][QtCore][QProcess] Reverted a change from Qt 6.0 that made the childProcessModifier() callback be run in a child created by means other than a real fork() library call, a situation in which certain other library functions would be unusable, unreliable, or cause deadlocks. A flag to opt in to the solution with better performance will be added to Qt 6.6. Task-number: QTBUG-104493 Fixes: QTBUG-111243 Fixes: QTBUG-111964 Pick-to: 6.5 Change-Id: Icfe44ecf285a480fafe4fffd174d3e66843e5a29 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProcessPrivate: repack and reorganize the membersThiago Macieira2023-05-151-9/+11
| | | | | | | | | | | | | | | | | Reduce the number of #ifdef blocks and use quint8 for the enums that don't need more than 8 bits anyway (none of them do). Plus move the std::function callback to an indirect block, as most users of QProcess won't set them and this type is 4 pointers with libstdc++ and libc++. After this, QProcessPrivate on 64-bit Unix is 688 bytes, of which: - 392 bytes from QIODevicePrivate - 295 bytes of own data - 3x56 bytes per Channel (which have 5 bytes of tail padding each) - 1 byte of tail padding and no middle padding Pick-to: 6.5 Change-Id: Icfe44ecf285a480fafe4fffd174d188a0821d060 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QProcessPrivate: remove the member variable "crashed"Thiago Macieira2023-05-131-3/+1
| | | | | | | | | | | | | It was only used to later set exitStatus = CrashExit, so simply do it early. Drive-by removal of a magic numeric literal in the middle of the source code. It's still magic, but at least we avoid accidentally making typos. Pick-to: 6.5 Change-Id: Icfe44ecf285a480fafe4fffd174d4176a5d87641 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProcess: remove the note that it freezes threads on QNXThiago Macieira2023-05-031-11/+0
| | | | | | | | | | | | | | | | | | The notes were added in commit e3363fd945b3ab961fba720ee013533dd8ba2930 by Rafael, because at the time QNX 6.5.0 did not support fork() in multithreaded applications. We had to use posix_spawn(3) and that doesn't support setting the child's working directory, so we needed to freeze the application while chdir(2)ing in doSpawn(). doSpawn() was removed in commit 005a8bfbf0022f03dafafcf2b5c438ccf0675a49 for Qt 5.7, because fork() works since QNX 6.6.0. But the comments were accidentally left behind. Fixes: QTBUG-112990 Pick-to: 5.15 6.2 6.5 Change-Id: I3b169860d8bd41e9be6bfffd17577276eaabb855 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProcess: reimplement systemEnvironment() using QProcessEnvironmentThiago Macieira2023-03-201-18/+1
| | | | | | | | | | | | [ChangeLog][QtCore][QProcess] Fixed a bug that would cause systemEnvironment() to produce corrupted entries (mojibake) on Windows if the environment contains characters outside of the ANSI character set. Pick-to: 6.2 6.5 Change-Id: Idd5e1bb52be047d7b4fffffd174db6c1024318dd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QProcess/Linux: fix file descriptor leak in case of failed child startThiago Macieira2023-03-161-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the child failed to start, execChild() would (unnecessarily) store -1 in childStartedPipe[1] after writing the failure message to it and closing that pipe. This had worked for the previous 20 years of QProcess existence, because that was run in the child process. However, with 6.5 commit e1a787a76ed462e4ed49db78a40c6d7e272182d7 (cherry-picked to 6.4) we implemented vfork-like behavior, meaning the child would share memory with the parent and ran before the parent, so startProcess() failed to close it: // parent // close the ends we don't use and make all pipes non-blocking qt_safe_close(childStartedPipe[1]); Also updated the docs to account for the fact that this is a vfork() environment and, moreover, not using the vfork() function from glibc on Linux. [ChangeLog][QtCore][QProcess] Fixed a file descriptor leak in QProcess when running on Linux 5.4 or later, if the executable being run failed to start (for example, the file for the executable didn't exist). Pick-to: 6.4.3 6.4 6.5 Task-number: QTBUG-111243 Change-Id: I7f354474adce419ca6c2fffd17481002e4853cc3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Misc: Fix qsizetype-related narrowing coversionsAhmad Samir2023-03-111-1/+1
| | | | | | Task-number: QTBUG-102461 Change-Id: I96757abc50fc45756bc1271a970f819a48021663 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace usages of Q_CLANG_QDOC with Q_QDOCLuca Di Sera2022-10-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | To allow the user to customize the C++ code that QDoc sees, so as to be able to work-around some limitations on QDoc itself, QDoc defines two symbols: Q_QDOC and Q_CLANG_QDOC, both of which are "true" during an entire execution of QDoc. At a certain point in time, QDoc allowed the user the choice between a custom C++ parser and a Clang based one. The Q_QDOC symbol would always be defined while the Q_CLANG_QDOC symbol would be defined only when the Clang based parser was chosen. In more recent times, QDoc always uses a Clang based parser, such that both Q_CLANG_QDOC and Q_QDOC are always defined, making them equivalent. To avoid using different symbols, and the possible confusion and fragmentation that derives from it, all usages of Q_CLANG_QDOC are now replaced by the equivalent usages of Q_QDOC. Change-Id: I5810abb9ad1016a4c5bbea99acd03381b8514b3f Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProcess/docs: add more information about environment variablesThiago Macieira2022-08-221-7/+44
| | | | | | | | Fixes: QTBUG-42500 Pick-to: 6.4 Change-Id: Ie4bb662dcb274440ab8bfffd170a6a56977ef8b9 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* QProcess: Extend the setStandardOutputFile docLaszlo Papp2022-07-231-0/+3
| | | | | | | | | | | | | | | | It seems to be a hidden gem that one can stop redirecting the standard output to a file without creating a new QProcess instance. I have discovered this while browsing the private implementation of QProcess trying to answer this question: https://stackoverflow.com/a/72989131/2682142 I believe that this should be documented unless it is not meant to be guaranteed behavior. Change-Id: I180764d4cc56f6395d6d65942077e3ede63c71ea Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Ensure that readAllStandardError() doesn't crash on assertJarek Kobus2022-04-091-4/+10
| | | | | | | | | | | Ensure that it's safe to call readAllStandardError() when process channel mode is set to MergedChannels. Pick-to: 6.3 6.3.0 Task-number: QTBUG-102177 Task-number: QTCREATORBUG-27196 Change-Id: I01073255d9347dee4654d602802a12d341372b73 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Apply Q_CONSTINIT across the codebaseMarc Mutz2022-03-291-1/+1
| | | | | | | | | Still not complete. Just grepping for static and thread_local. Task-number: QTBUG-100486 Change-Id: I90ca14e8db3a95590ecde5f89924cf6fcc9755a3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicableSona Kurazyan2022-03-251-3/+3
| | | | | | | | | | | As a drive-by, did also minor refactorings/improvements. Task-number: QTBUG-98434 Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* QProcess/Doc: update the information on how the program is foundThiago Macieira2022-03-101-13/+65
| | | | | | Pick-to: 5.15 6.2 6.3 Change-Id: I54f205f6b7314351b078fffd16d05b1eecb24544 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
* Make QProcessEnvironment(Initialization) noexceptIevgenii Meshcheriakov2022-02-111-3/+15
| | | | | | | | | | | Use default noexcept constructor to initialize `d` member. Document Initialization enum. Fixes: QTBUG-100695 Pick-to: 6.3 Change-Id: I7585ad154a9be40021a205b515ffa7b14f188d67 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QProcess: Distinguish between null and empty QProcessEnvironmentIevgenii Meshcheriakov2021-11-071-14/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation for QProcessEnvironment's default constructor says: This constructor creates an empty environment. If set on a QProcess, this will cause the current environment variables to be removed. This is not the case however, because setting such an environment for a process is equivalent to not setting an environment at all and the child process is executed with parent's environment. It is still possible starting from Qt 6.2.0 to create an empty environment by adding a variable to a null environment and removing it, but that's cumbersome, and the comparison operator says that it is equal to the null environment but it is obviously behaving in a different way. This change adds an additional constructor to QProcessEnvironment that can be used to construct a null environment, and changes the default constructor to produce an empty environment. The comparison operator is changed to correctly distinguish between such objects. This is a behavior change, but the current behavior is broken and this is unlikely to affect working code. [ChangeLog][QtCore][QProcessEnvironment] An additional constructor was added to explicitly create an object that when set on QProcess would cause it to inherit the environment from parent (this was formerly the behavior of a default-constructed QProcessEnvironment, which will now (as documented) actually give a process an environment with no variables set). A new method inheritsFromParent() was added to test for such objects. Fixes: QTBUG-58053 Change-Id: I15e20c6a5f01ebe2c736d5578c75dba1ee319320 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Revert "QProcess: do not emit aboutToClose() twice"Alex Trotsenko2021-09-241-0/+1
| | | | | | | | | | This reverts commit efb90f6e7ed3e8d4f7b6c0fb96012cb3a9a9d037. Reason for revert: behavior change for signal listeners Change-Id: Ibe3c5d496cd61a9fccab17a10cc9fda8334fc9d4 Reviewed-by: Björn Schäpers <qt-codereview@hazardy.de> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QProcess: do not emit aboutToClose() twiceAlex Trotsenko2021-09-191-1/+0
| | | | | | | | | This signal is emitted by the QIODevice itself, so we don't have to emit it from QProcess::close(). Pick-to: 6.1 6.2 Change-Id: I9165b3eebadc17a66cc834d5ef54441d13f23d7d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProcess/Win: avoid double buffering on writeAlex Trotsenko2021-06-181-3/+5
| | | | | | | | | | | | | As QWindowsPipeWriter now maintains a chunk queue, there is no need to use the internal QIODevice buffer and wait for the previous operation to complete. This also allows us to get rid of the stdinWriteTrigger timer; however, as a trade-off, QWindowsPipeWriter now needs to accept data even before a handle is assigned. Change-Id: I17fe0e36a6165fe05100bfab3fe01fc0d880d617 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess: untangle platform-specific detailsAlex Trotsenko2021-06-041-117/+0
| | | | | | | | | - add missing #ifdef in header file; - split some functions (writeData(), _q_canWrite(), cleanup()) into their platform-specific implementations. Change-Id: I4e7c1c377ec8468ed120d38acf2543eef9316c01 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess: refine 'Channel' structureAlex Trotsenko2021-06-031-0/+2
| | | | | | | | | | - exclude unused notifier pointer on Windows; - use default initialization for members; - avoid bit fields in declarations as there are extra padding bytes anyway. Change-Id: I2e03c4c269c885c90c0a6d18b8a935885f4b3feb Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* Introduce QProcessPrivate::closeChannels()Alex Trotsenko2021-05-311-3/+11
| | | | | | | Avoid duplicating code for both platforms. Change-Id: Iae00023672b63e8539cf824fa3aaaff2bf9ae0c5 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* Consolidate debug string generationAlex Trotsenko2021-05-311-41/+4
| | | | | | | | | | | | | | Several QIODevice subclasses use the qt_prettyDebug() function to get a printable representation of the buffer data for debug output. Rather than having this feature statically implemented in each respective file, this patch introduces a generic function in the QtDebugUtils namespace. Accordingly, some inaccuracies in the use-cases have been corrected. Change-Id: I1a8465cab08c8acf5fdcdba5085182511b1cbb7b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QProcess/Win: implement async closing of write channelAlex Trotsenko2021-03-111-6/+8
| | | | | | | | | Instead of blocking in QProcessPrivate::closeWriteChannel(), we can handle a pending close in _q_canWrite() slot when there is no more data to write. Change-Id: I2a30789b6099a2ec075292348ebe33a11341bca3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess::startDetached: set the error condition on failure to startThiago Macieira2021-02-211-5/+6
| | | | | | | | | | | | And set *pid to -1. [ChangeLog][QtCore][QProcess] If a startDetached() fails to start the target application, the QProcess object should now have a proper error string in errorString(). Pick-to: 6.1 Change-Id: Ic90d8429a0eb4837971dfffd1664e825ffcb923e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess/Unix: remove dead functionAlex Trotsenko2021-01-291-5/+2
| | | | | | | | findExitCode() doesn't do anything on Unix. Change-Id: I3efdc1380a39437c4c029073f3b10ccf7a65e580 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QProcess/Unix: simplify notifiers deactivationAlex Trotsenko2021-01-271-18/+1
| | | | | | | | To minimize code duplication, move the socket notifier deletion to the closeChannel() function, where the pipe descriptor will be closed. Change-Id: If75ba1c955c706ae6e2b3d9f53f7a25e4aa32fa7 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess/Win: move pipe draining into QWindowsPipeReaderAlex Trotsenko2021-01-221-1/+2
| | | | | | | | | | | | | | | | | | ... where it belongs. To avoid the loop, introduce the drainAndStop() function, which allows QWindowsPipeReader to flush the pipe itself. It determines the number of bytes pending and blocks until the remainder of the process output is received. Note that the loop in drainOutputPipes() didn't actually have to interleave the two pipes (because we're presuming that the operations will finish instantly), so we don't do it now. Also, the code violated the API contract: 'true' was returned when the 'wrong' channel received data; this is now fixed as a side effect. Change-Id: I38ed4861a238e39e793c3716e856e5bfdeed3d74 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess/Win: clean up death notifier teardownAlex Trotsenko2021-01-091-12/+8
| | | | | | | | | | | | To avoid the mostly hypothetical possibility of failure, delete the processFinishedNotifier before closing the handle on which it operates. Previously, because of this, we explicitly disabled the notifier in the processFinished() function, which made the code unclear. Now, we can remove that safely, because cleanup() works correctly, and doing it before calling findExitCode() was not necessary to start with. Change-Id: Ia7095ded2c7eba8f4d738c6b87c7be41aa3cbbc8 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* Split QProcessPrivate::_q_processDied()Alex Trotsenko2021-01-091-31/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The completion of the child process can take place asynchronously or in one of the waitFor...() functions. In both cases, we used the same handler (_q_processDied()), which caused several problems: a. technically, waitForReadyRead() should have taken into account the result of the calls to _q_canRead...() slots inside the _q_processDied() function: - the user calls waitForReadyRead(); - forkfd descriptor becomes signaled, while a grandchild process is still alive; - as readyRead() signal has not been emitted, _q_processDied() is called; - the grandchild process writes to stdout pipe; - now data arrives, and _q_processDied() will collect it, but won't report it. b. we had a bug with recursions on Unix: - death notification comes asynchronously; - waitForDeadChild() closes forkfd; - _q_canRead...() emits readyRead(); - a slot connected to readyRead() calls waitForFinished(); - waitForFinished() hangs (forkfd == -1). c. for blocking functions, drainOutputPipes() was called twice on Windows. By introducing a new processFinished() function, we leave the read operations in the _q_processDied() slot, while the process completion code is guaranteed to run only once. Change-Id: I5f9d09bc68a058169de4d9e490b48fc0b35e94cd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess/Unix: consolidate process state tracking socket notifiersAlex Trotsenko2021-01-081-15/+3
| | | | | | | | | | | | | | | | There is no reason to have the startup notifier and the death notifier be active at the same time, as the former will detect death as well. Previously, these notifiers were racing, but _q_processDied() ordered signals by calling _q_startupNotification() manually. Thus, the started()/finished() sequence was always emitted if the child process was killed anywhere. Now this ordering is simply not necessary anymore. This makes it possible to reuse the startup notifier for death notification. Change-Id: I5ebed9b5f28b19fe56c80498977a3b21be9288fd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* Remove superfluous call in QProcessPrivate::_q_startupNotificationAlex Trotsenko2021-01-051-2/+0
| | | | | | | | There is no need to disable startupSocketNotifier because the call to QProcessPrivate::processStarted() will do that. Change-Id: I20b816533d9a5c4b9bf57135d26166c961a07d07 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess: allow pipelining for detached processesAlex Trotsenko2020-12-311-6/+12
| | | | | | | | [ChangeLog][QtCore][QProcess] Added support for setStandardOutputProcess() with startDetached(). Change-Id: I61278cdb7084127f583c8c017688da392017b44c Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess: allow merged channels forwarding for detached processesAlex Trotsenko2020-12-311-3/+6
| | | | | | | | [ChangeLog][QtCore][QProcess] Added support for QProcess::MergedChannels mode with startDetached(). Change-Id: I953ad2063322015332269522a297f8e2842e438c Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess: consolidate channel managementAlex Trotsenko2020-12-311-0/+72
| | | | | | | | | | We have the same channel forwarding, redirecting, and merging rules for all platforms. This makes it possible to introduce the openChannels() function, which consolidates the logic and performs high-level general processing of the channels configuration properties. Change-Id: Id3574fc42a56829328369b6a1a6ec9c95fce8eca Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
* QProcess: remove unused memberAlex Trotsenko2020-12-151-1/+0
| | | | | Change-Id: I448a32b8ba11426c70d49f7f492b73e7799cc257 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>