Commit Graph

38 Commits

Author SHA1 Message Date
Thiago Macieira
b22b514140 Bump minimum glibc requirement for sys/eventfd.h to glibc 2.8
The file was added to glibc 2.7 along with the functions we need (Added
2007-10-05). But they forgot to install the file until a month and a
half later (2007-11-17), which means it missed the 2.7 release
(2007-10-19).

Note that EFD_CLOEXEC wasn't added until glibc 2.9, so effectively glibc
2.9 is required.

Change-Id: I3868166e5efc45538544fffd14d773ba576fb793
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
2017-08-04 17:56:34 +00:00
Thiago Macieira
37fd42459e forkfd: fix calling the old signal handler when there wasn't one
On some stupid systems, execve() may clear the handler but not clear
the SA_SIGINFO flag.

This change now requires that sa_handler and sa_sigaction be in a union
together. We can't operate otherwise.

Task-number: QTBUG-59246
Change-Id: I33850dcdb2ce4a47878efffd14a84b48a8f6b1e8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-03-06 09:56:35 +00:00
Thiago Macieira
1b81f93183 forkfd: use SA_SIGINFO to pass extra information to chained handlers
This existed in QProcess before forkfd, but was lost in the port to it
(commit 1814142b7a). The original QProcess
fix was done in 97279d0582.

Task-number: QTBUG-57584
Change-Id: Ibc5c715fda334a75bd2efffd14a425871f3162b5
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2017-02-26 05:53:27 +00:00
Kai Koehne
b6f4003b87 Fix forkfd 3rd party documenation
Bring the copyright lines in the license and the one's
in the metadata into line by using the ones from forkfd.c.

Also bring back description of forkfd from 5.6 documentation.

Change-Id: I423ee8d5d1e1c866a34c346f78520d33ea099b5e
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2016-11-23 09:35:41 +00:00
Lars Knoll
ef744f2163 Avoid clang warnings about unused return values
Change-Id: Iebec7fb425a92199592cb3ea92190dd0bb5deabd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2016-11-09 09:42:24 +00:00
Kai Koehne
492ca3e503 Add qt_attribution.json files
The format is documented in

  http://wiki.qt.io/Qt_attribution.json

Also add a LICENSE file in case there is none yet
(usually copied from the source headers).

Task-number: QTBUG-55139
Change-Id: Ib54c73d0bb9946cfd8579e86c6858035184ca516
Reviewed-by: Topi Reiniö <topi.reinio@theqtcompany.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2016-08-12 06:55:01 +00:00
Liang Qi
57057f76ad Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	.qmake.conf
	config.tests/unix/nis/nis.cpp
	mkspecs/unsupported/freebsd-g++/qplatformdefs.h
	src/corelib/tools/qdatetime.cpp
	src/corelib/tools/qsimd.cpp
	src/corelib/tools/qsimd_p.h
	src/network/access/access.pri
	src/network/access/qnetworkreplynsurlconnectionimpl.mm
	src/network/access/qnetworkreplynsurlconnectionimpl_p.h
	src/plugins/platforms/cocoa/qnsview.mm
	src/plugins/printsupport/windows/qwindowsprintdevice.cpp
	tests/auto/corelib/kernel/qobject/tst_qobject.cpp
	tests/auto/network/access/qnetworkreply/BLACKLIST
	tests/auto/widgets/widgets/qopenglwidget/BLACKLIST

Change-Id: I4b32055bbf922392ef0264fd403405416fffee57
2016-06-06 09:04:55 +02:00
Ralf Nolden
4fc7971478 NetBSD/OpenBSD: Compile fix and proper detection of pipe2
Add the necessary defines for HAVE_PIPE2 for NetBSD and OpenBSD depending
on OS version when pipe2(2) was added. This also fixes the compile error
on NetBSD if -Werror=unused-function for ignore_sigpipe() as the
HAVE_PIPE2 tree is prior to O_NOSIGPIPE in create_pipe().

Change-Id: Ic8f875e34ef826a7bf046c77588afecaa097deca
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2016-06-04 18:11:12 +00:00
Thiago Macieira
cf6a2e9617 forkfd: Make sure we handle SIGPIPE too
We can't depend on the application/library ignoring the signal for us,
so we do it. O_NOSIGPIPE exists on the BSDs and I'll add it to Linux. If
it isn't supported, then we need to ignore SIGPIPE globally.

Change-Id: I25d85d86649448d5b2b3fffd1450f6afeaea8b18
Reviewed-by: Ralf Nolden <nolden@kde.org>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2016-05-23 18:22:07 +00:00
Liang Qi
0a1af55a9b Merge "Merge remote-tracking branch 'origin/5.6' into dev" into refs/staging/dev 2016-01-26 11:27:37 +00:00
Thiago Macieira
23bd4651c7 Update the Intel copyright year
Not that we require it, but since The Qt Company did it for all files
they have copyright, even if they haven't touched the file in years
(especially not in 2016), I'm doing the same.

Change-Id: I7a9e11d7b64a4cc78e24ffff142b4c9d53039846
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-21 22:44:16 +00:00
Liang Qi
8f569c740a Merge remote-tracking branch 'origin/5.5' into 5.6
Conflicts:
	config.tests/common/atomic64/atomic64.cpp
	configure
	src/3rdparty/forkfd/forkfd.c
	src/corelib/io/forkfd_qt.cpp
	src/widgets/kernel/qwidgetwindow.cpp
	tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
	tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
	tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
	tools/configure/configureapp.cpp

Change-Id: Ic6168d82e51a0ef1862c3a63bee6722e8f138414
2016-01-19 10:03:01 +01:00
Raphael Kubo da Costa
090bf50771 forkfd: Only enable pipe2 on FreeBSD >= 10.0.
The system call is not present on earlier releases, and since the 9.x
series will be supported until the end of 2016, add a check for the
__FreeBSD_version macro and only enable pipe2 support if the value is
high enough.

Change-Id: I5633531cec7e95d42ff5f4b14afe772ae8d7d66d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2016-01-03 13:42:13 +00:00
Raphael Kubo da Costa
c8c4ad0c62 forkfd: Define __BSD_VISIBLE and _NETBSD_SOURCE.
pipe2's availability on BSD operating systems depends on the
__BSD_VISIBLE macro on FreeBSD and OpenBSD and _NETBSD_SOURCE on
NetBSD (DragonFly BSD appears to define it unconditionally).

Those two macros are generally set by default, except when
_POSIX_C_SOURCE is set. Since we consciously set _POSIX_C_SOURCE but
need pipe2, explicitly define the visibility macros.

This fixes the -no-pch build on FreeBSD at least.

Change-Id: Icc77f6b5d1f9a5bf7bd8048cabbb01f8f89397cc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-12-27 17:02:23 +00:00
Liang Qi
f8246099ea Merge remote-tracking branch 'origin/5.5' into 5.6
Conflicts:
	src/corelib/io/qstorageinfo_unix.cpp
	src/plugins/platforms/windows/qwindowsmousehandler.cpp
	src/widgets/styles/qwindowsvistastyle.cpp

Change-Id: Ie1725933815891cc8c86258d4c0e8ed0ab386edf
2015-11-04 12:28:48 +01:00
Dmitry Shachnev
b7c4f15d67 Undef HAVE_WAITID if needed constants are not defined
That is the case on Hurd, where the code currently breaks because Hurd
does not have WEXITED or WNOWAIT defined.

Change-Id: I4b13633612b1168d36c949d9e8b35bc05bca7d5c
Reviewed-by: Lisandro Damián Nicanor Pérez Meyer <perezmeyer@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-10-26 10:48:12 +00:00
Liang Qi
d0eaa737e1 Merge remote-tracking branch 'origin/5.5' into 5.6
Conflicts:
	qmake/doc/src/qmake-manual.qdoc
	src/corelib/tools/qstring.h
	src/gui/image/qimagereader.cpp
	src/network/access/qnetworkaccessmanager.cpp
	src/tools/qdoc/doc/examples/examples.qdoc
	src/widgets/accessible/qaccessiblewidgetfactory_p.h
	src/widgets/doc/qtwidgets.qdocconf

Change-Id: I8fae62283aebefe24e5ca4b4abd97386560c0fcb
2015-10-02 16:59:55 +02:00
Thiago Macieira
ff1275a3be Fix detection of uClibc version numbers
Major << 16 is 0x90000. Reported in QTBUG-45139

Change-Id: I42e7ef1a481840699a8dffff14057022bc4df8e9
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-09-21 16:39:39 +00:00
Louai Al-Khanji
5919edc523 forkfd: fix _POSIX_SPAWN feature check
Change-Id: Ia44edbac3a1bd2da92ee8c92956abfe49d8763b8
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-09-04 08:59:35 +00:00
Thiago Macieira
0ec809e027 forkfd: Add support for FreeBSD's pdfork(2) system call
pdfork(2) has semantics very close to what we want in forkfd, but not
quite. Differences:
 - we still get SIGCHLD and need to do a wait4
 - no support for atomic FD_CLOEXEC and O_NONBLOCK

On the SIGCHLD case: this commit is an improvement over the generic Unix
case, since we no longer need to install a SIGCHLD handler and do not
need to keep the arrays for matching PIDs and file descriptors. That
matching is done entirely inside the kernel.

However, since SIGCHLD is still sent to the process, an uncooperative
SIGCHLD handler can still "steal" our response. At least Glib is
documented not to reap children it wasn't explicitly asked to watch for
(source code matches), but other libraries are known to do waitpid(-1)
(e.g., EFL's Ecore). At least now the behavior is consistent: we will
never install a handler, so the behavior won't depend on the order in
which the handlers are installed.

Change-Id: Iee8cbc07c4434ce9b560ffff13cb4c63306e43ef
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-08-11 16:37:58 +00:00
Frederik Gladhorn
77da617dc8 Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
	doc/global/qt-cpp-defines.qdocconf
	src/3rdparty/forkfd/forkfd.c
	src/corelib/codecs/qtextcodec.cpp
	src/corelib/kernel/qmetatype.cpp
	src/corelib/tools/qset.qdoc
	src/gui/accessible/qaccessible.cpp
	src/gui/image/qpixmapcache.cpp
	src/opengl/qgl.cpp
	src/tools/qdoc/generator.cpp
	src/widgets/kernel/qwidget.cpp
	tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp

Change-Id: I4fbe1fa756a54c6843aa75f4ef70a1069ba7b085
2015-08-06 10:54:01 +02:00
Thiago Macieira
007ad9e859 FreeBSD has pipe2, so enable it in forkfd.c
Change-Id: Ib056b47dde3341ef9a52ffff13efd1a15748e44d
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-08-06 04:53:35 +00:00
Thiago Macieira
93cb984174 forkfd: introduce system_forkfd to do system calls that do forkfd
This is just to make the code cleaner. The static variable will control
whether we've detected that the system call exists -- if it does, we are
expected to always use it.

Change-Id: Iee8cbc07c4434ce9b560ffff13cb4adc049413c1
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-07-28 23:55:11 +00:00
Thiago Macieira
5cc734e0a3 forkfd: Fix build with uClibc <= 0.9.33
That version of uClibc has neither pipe2 nor eventfd.

There were two problems with our detection. First, it checked for glibc
incorrectly, so the comparison was always true as
	__GLIBC__ << 16 = 0x20000

Second, we needed to check for uClibc's version.

Task-number: QTBUG-47337
Change-Id: Ib306f8f647014b399b87ffff13f3023b7f8d6d4a
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-07-28 20:16:08 +00:00
Thiago Macieira
53ee7444d8 forkfd: use wait4 to get the process status instead of waitid
wait4 gives us the struct rusage contents for us, which may contain
interesting data for other users of forkfd (not Qt, though).

Change-Id: Iee8cbc07c4434ce9b560ffff13cb4aa28e18e790
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-07-18 02:25:23 +00:00
Thiago Macieira
2dbe90c248 forkfd: update the API to add a reading and closing function
Right now the two functions being added are just wrappers, but this will
allow us in the future to support FreeBSD and Linux's system calls that
do the equivalent of forkfd, but have slightly different semantics in
the actual getting of the information from the file descriptor.

See-Also: https://lkml.org/lkml/2015/3/12/1044
See-Also: http://www.freebsd.org/cgi/man.cgi?query=pdfork
Change-Id: Ia0aac2f09e9245339951ffff13c94acb5f4ff204
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-07-17 00:55:45 +00:00
Dyami Caliri
970241a11a Fix forkfd on OS X 10.7 and earlier by avoiding waitid altogether
On OS X 10.7 and earlier, waitid() never sets si_pid, even when using
P_PID. So on OS X, check if waitid() works, and if not, use the same
codepath as if HAVE_WAITID were not defined.

Change-Id: I64331a090f9358bb01f435954d3dfd3ab430a96c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-05-27 14:47:54 +00:00
Thiago Macieira
f25d6ad2aa forkfd: Fix compilation with older glibc
glibc 2.9 is required for pipe2 and version 2.7 for eventfd.

Bionic added them to Android version 2.3.1, but I can't find a version
macro.

uclibc masquerades as glibc version 2.2, so this function won't be
thread-safe with uclibc.

Change-Id: Iee8cbc07c4434ce9b560ffff13cd3c3b63dd7e83
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2015-04-01 14:44:42 +00:00
Thiago Macieira
17cfe1b35f Relicense forkfd under an MIT license
The difference between BSD and MIT is the need to reproduce the
copyright in the documentation and the non-endorsement by a particular
company (the name of which was stale in the forkfd code).

Change-Id: Iee8cbc07c4434ce9b560ffff13cd0174934935e9
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-03-23 06:16:21 +00:00
Thiago Macieira
4da46bbb9a forkfd: dynamically detect whether the Darwin waitid is broken
The Darwin kernel that came with Mac OS X 10.7 has a broken
implementation of waitid when passed a P_ALL first argument. It does
tell us that there is a process that can be wait()ed, but does not fill
in the siginfo_t structure.

See commit 9931fa9df4 for more
information.

Change-Id: Iee8cbc07c4434ce9b560ffff13cafa4c88cdabd6
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-03-16 19:28:13 +00:00
Alex Richardson
eea7791fd4 Fix build of forkfd_qt.cpp on FreeBSD
It no longer compiled after 614f37c8b5 due to
the following:
- forkfd_qt.cpp set _XOPEN_SOURCE to 500
- It then includes qatomic.h which include sys/cdefs.h (the FreeBSD header
  that parses and sets _POSIX_C_SOURCE, _XOPEN_SOURCE and other macros)
- sys/cdefs.h redefines _POSIX_C_SOURCE to 199506 due to _XOPEN_SOURCE's
  value
- Several libc symbols expected to exist by libc++ are hidden due to
  _POSIX_C_SOURCE's value and the build fails

Setting _XOPEN_SOURCE to 700 ensures that _POSIX_C_SOURCE is set to
200809 which is required for libc++ to work correctly

Task-number: QTBUG-45006
Change-Id: Iac93220d19ca5ab9ba8ac61a79748252283c3c47
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-03-15 22:26:40 +00:00
Thiago Macieira
614f37c8b5 forkfd: make only one of forkfd or spawnfd be compiled
We only ever use one, never both.

Change-Id: Iee8cbc07c4434ce9b560ffff13caf94c05dba338
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-03-14 02:17:36 +00:00
Thiago Macieira
f3459a43af Add spawnfd for use where fork / forkfd can't be used
In certain environments, using fork() is not recommended due to the need
for an MMU. This commit adds support for those environments, by using
posix_spawn. Limitations of this environment are:
 - we cannot reliably detect failure to exec (e.g. non-existing executable)
 - we cannot do setsid(); we do setpgrp(0, 0) instead
 - we cannot thread-safely chdir() to the requested dir

Because of the former limitation, the QProcess unit tests that rely on
failure-to-start error conditions are either skipped or marked as
expected failures. There's a non-reliable solution that is implemented
in a another commit.

This change also makes it easier to transition the QNX builds to using
fork(), which is supported from QNX Neutrino 6.6 and onwards.

Change-Id: I5cb46abf2ef8783941525d35cc991f00d2bf2d58
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-01-23 19:13:12 +01:00
Thiago Macieira
9931fa9df4 Fix forkfd on OS X 10.7 and earlier
dtruss logs show that the signal handler does enter and is active, since
it does the first waitid() call, but then returns immediately:

 waitid(0x0, 0x0, 0x7FFF62D7C468)               = 0 0
 sigreturn(0x7FFF62D7C9A0, 0x1E, 0x0)           = 0 Err#-2

Since there was no error return, we conclude that si_pid was zero on
return. Source code for OS X 10.7 confirms that si_pid is set to zero
unconditionally, which is rather stupid:
 http://fxr.watson.org/fxr/source/bsd/kern/kern_exit.c?v=xnu-1699.24.8#L1330

This is fixed for OS X 10.8:
 http://fxr.watson.org/fxr/source/bsd/kern/kern_exit.c?v=xnu-2050.18.24#L1399

Without that information, we have to scan each child anyway, so
just disable the waitid() solution on OS X. This is a "hammer" solution
which will get forkfd working. We can later try and detect at runtime
whether waitid() is working.

Change-Id: Ic5d393bfd36e48a193fcffff13bb584927cdeafe
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-01-23 19:13:07 +01:00
Thiago Macieira
bd1be70e0e Fix compilation of non-waittid forkfd() outside of Linux
POSIX.1 does not guarantee the presence of the si_utime and si_stime
members. So instead of trying to set those members to zero, ask the
compiler to initialize everything for us.

This was found on OS X when HAVE_WAITTID was removed.

forkfd.c:192:11: error: no member named 'si_utime' in '__siginfo'
forkfd.c:193:11: error: no member named 'si_stime' in '__siginfo'

Change-Id: Ic5d393bfd36e48a193fcffff13b90aa6ccf592ae
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2015-01-23 19:12:59 +01:00
Thiago Macieira
c8849dd8d5 Use waitid with WNOWAIT in forkfd
The previous implementation required one syscall per child we're waiting
on to see which one exited. That means the algorithm was O(n).

This implementation uses WNOWAIT to find out which child exited and then
goes straight to that one. So it's O(1) on the number of children, but
runs 2 * number_of_children_that_exited + 1 syscalls, assuming there are
no race conditions with other threads. If there are or if a child not
started by forkfd exits, we'll still iterate over each child we're
managing to see which one exited.

It modifies the existing code so that it will do a waitid() with WNOWAIT
to check on the status of the child: if the child has exited, we'll try
to lock the entry so only one thread will do the final wait(). In the
case we read the PID, then the child exited, was reaped by another
thread, the PID got recycled and that child exited again, we'll fail to
lock the ProcessInfo entry so no harm comes. If by an absurd coincidence
this other child was started by forkfd() and its ProcessInfo is exactly
the one we are looking at, then we'll succeed in locking but that's a
benign race: we'll do what the other thread was trying to do and the
other thread will give up.

Future improvements to the algorithm are discussed in the Gerrit change.

Change-Id: Ie74836dbc388cd9b3fa375a41a8d944602a32df1
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2015-01-23 19:12:53 +01:00
Thiago Macieira
3d051d41a3 Fix forkfd build when O_CLOEXEC isn't defined.
O_CLOEXEC was introduced with the 2008 revision of POSIX.1 and it's the
only way of doing child processes safely with fork(2) in multithreaded
applications.

But we need to support pre-2008 systems, so we can't use that constant.
So let's just choose two arbitrary values for both of our constants --
we need to change both because we need to be sure that FFD_CLOEXEC won't
be the same as FFD_NONBLOCK.

Linux will probably implement them to the O_ constants, like epoll,
signalfd and inotify have done.

Change-Id: I20a5aa6e6264e7a219e19759eeb8747e01df05ff
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
2015-01-16 03:12:09 +01:00
Thiago Macieira
c36b559196 Import forkfd into qtbase
forkfd is a tool that I designed to facilitate spawning
sub-processes. It's implemented in C, not C++, so that it could be
used by other libraries as well.

To work in all platforms Qt supports and with all compilers Qt is
known to work with, we'll need to replace the generic GCC atomics that
are provided here.

Change-Id: I0a6f86cc220a7c52c8d4284bb7140c56d5cf836a
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2014-11-04 19:19:41 +01:00