diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2019-11-22 09:55:46 +0100 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-01-09 22:52:28 +0100 |
commit | 97645478de3ceffce11f58eab140c4c775e48be5 (patch) | |
tree | a4e48abc61dedc5ebd3b377e680ba3ecfb6e980f /src/corelib | |
parent | 702e49eeb5654b6881f91618e5bc95853e206b6c (diff) |
QProcess: use FFD_USE_FORK when the class is not QProcess itself
If the user derived from QProcess, it's likely to override the
setupChildProcess() virtual. Unlike fork(), the system calls for
enhenced functionality (FreeBSD pdfork() and Linux's clone()) won't call
pthread_atfork() callbacks and the environment in the child process
could be inconsistent. Qt's own code is safe, but we can't make the same
statement about users' code.
So we err on the safe side for correctness and run the old, less safe
implementation (thread-unsafe, subject to hijacking of the signal
handler, etc.).
Change-Id: Ia2aa807ffa8a4c798425fffd15d9703bd03f6f09
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 9cd3bd531b..2186f23ab6 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -451,8 +451,13 @@ void QProcessPrivate::startProcess() } // Start the process manager, and fork off the child process. + // ### Qt6: revisit whether the change in behavior due to not using fork() + // is acceptable for derived classes. + int ffdflags = FFD_CLOEXEC; + if (typeid(*q) != typeid(QProcess)) + ffdflags |= FFD_USE_FORK; pid_t childPid; - forkfd = ::forkfd(FFD_CLOEXEC, &childPid); + forkfd = ::forkfd(ffdflags , &childPid); int lastForkErrno = errno; if (forkfd != FFD_CHILD_PROCESS) { // Parent process. |