summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/forkfd
Commit message (Collapse)AuthorAgeFilesLines
* Merge "Merge remote-tracking branch 'origin/5.6' into dev" into refs/staging/devLiang Qi2016-01-261-1/+1
|\
| * Merge remote-tracking branch 'origin/5.5' into 5.6Liang Qi2016-01-191-1/+1
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| | * forkfd: Only enable pipe2 on FreeBSD >= 10.0.Raphael Kubo da Costa2016-01-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| | * forkfd: Define __BSD_VISIBLE and _NETBSD_SOURCE.Raphael Kubo da Costa2015-12-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | | Update the Intel copyright yearThiago Macieira2016-01-213-3/+3
|/ / | | | | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/5.5' into 5.6Liang Qi2015-11-041-0/+3
|\| | | | | | | | | | | | | | | | | Conflicts: src/corelib/io/qstorageinfo_unix.cpp src/plugins/platforms/windows/qwindowsmousehandler.cpp src/widgets/styles/qwindowsvistastyle.cpp Change-Id: Ie1725933815891cc8c86258d4c0e8ed0ab386edf
| * Undef HAVE_WAITID if needed constants are not definedDmitry Shachnev2015-10-261-0/+3
| | | | | | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/5.5' into 5.6Liang Qi2015-10-022-5/+5
|\| | | | | | | | | | | | | | | | | | | | | | | | | 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
| * Fix detection of uClibc version numbersThiago Macieira2015-09-211-2/+2
| | | | | | | | | | | | | | | | 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>
| * forkfd: fix _POSIX_SPAWN feature checkLouai Al-Khanji2015-09-042-3/+3
| | | | | | | | | | Change-Id: Ia44edbac3a1bd2da92ee8c92956abfe49d8763b8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | forkfd: Add support for FreeBSD's pdfork(2) system callThiago Macieira2015-08-111-0/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/5.5' into devFrederik Gladhorn2015-08-061-2/+8
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
| * FreeBSD has pipe2, so enable it in forkfd.cThiago Macieira2015-08-061-0/+4
| | | | | | | | | | Change-Id: Ib056b47dde3341ef9a52ffff13efd1a15748e44d Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
| * forkfd: Fix build with uClibc <= 0.9.33Thiago Macieira2015-07-281-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | forkfd: introduce system_forkfd to do system calls that do forkfdThiago Macieira2015-07-281-0/+16
| | | | | | | | | | | | | | | | | | | | 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>
* | forkfd: use wait4 to get the process status instead of waitidThiago Macieira2015-07-181-19/+34
|/ | | | | | | | 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>
* forkfd: update the API to add a reading and closing functionThiago Macieira2015-07-172-26/+81
| | | | | | | | | | | | | | 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>
* Fix forkfd on OS X 10.7 and earlier by avoiding waitid altogetherDyami Caliri2015-05-271-24/+32
| | | | | | | | | 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>
* forkfd: Fix compilation with older glibcThiago Macieira2015-04-011-3/+7
| | | | | | | | | | | | | | 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>
* Relicense forkfd under an MIT licenseThiago Macieira2015-03-233-85/+47
| | | | | | | | | 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>
* forkfd: dynamically detect whether the Darwin waitid is brokenThiago Macieira2015-03-161-4/+31
| | | | | | | | | | | | | 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 9931fa9df4cb96a4006a3390db64f87e3b5bc1a0 for more information. Change-Id: Iee8cbc07c4434ce9b560ffff13cafa4c88cdabd6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Fix build of forkfd_qt.cpp on FreeBSDAlex Richardson2015-03-151-1/+1
| | | | | | | | | | | | | | | | | | | It no longer compiled after 614f37c8b559a722538c58dd1f65229cfca7d35b 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>
* forkfd: make only one of forkfd or spawnfd be compiledThiago Macieira2015-03-141-2/+4
| | | | | | | We only ever use one, never both. Change-Id: Iee8cbc07c4434ce9b560ffff13caf94c05dba338 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* Add spawnfd for use where fork / forkfd can't be usedThiago Macieira2015-01-232-0/+76
| | | | | | | | | | | | | | | | | | | | 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>
* Fix forkfd on OS X 10.7 and earlierThiago Macieira2015-01-231-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix compilation of non-waittid forkfd() outside of LinuxThiago Macieira2015-01-231-2/+2
| | | | | | | | | | | | | | | 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>
* Use waitid with WNOWAIT in forkfdThiago Macieira2015-01-231-2/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* Fix forkfd build when O_CLOEXEC isn't defined.Thiago Macieira2015-01-162-3/+3
| | | | | | | | | | | | | | | | | | 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>
* Import forkfd into qtbaseThiago Macieira2014-11-043-0/+629
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>