From 97645478de3ceffce11f58eab140c4c775e48be5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Nov 2019 09:55:46 +0100 Subject: 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 --- src/corelib/io/qprocess_unix.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/corelib') 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. -- cgit v1.2.3