summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemwatcher_inotify.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QInotifyFileSystemWatcherEngine: change to QObject::connect PMF syntaxJuha Vuolle7 days1-1/+2
| | | | | | Task-number: QTBUG-122619 Change-Id: I624d282791a561ebd0d70cadc9bf17594cc1eb5c Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix some narrowing conversion warningsAhmad Samir2023-04-081-1/+1
| | | | | | | | | ioctl call for FIONREAD takes an int arg, it won't work correctly otherwise. Cast the return of the read() call to int, because it won't read more than buffSize (which is an int). Change-Id: I130202a732684257bbb0e79c9358b60a61010c46 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-1/+1
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | 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>
* fix: Optimize the performance of the inotify file system monitoring program。Gong Heng2021-04-301-1/+1
| | | | | | | | | | | | | | When the ioctl() functions is executed correctly, the value of buffSize may be 0. In this situation, there is no need to execute the following code. This modification can solve two benefits: 1. The readFromInotify function runs frequently, and this modification can improve the efficiency of the program. 2. When the buffSize is equal to 0, "read(inotifyFd, buffer.data(), buffSize)" function will be stuck.(I have encountered this kind of problem) Pick-to: 5.15 6.0 6.1 Change-Id: I9f85491ec91e336b4a1bec5c99b911835c5c06a5 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Add some error handling for the inotify file system watcherLu Zhen2021-01-141-1/+3
| | | | | | | | | | In the readFromInotify() function, add a check whether the ioctl function is successful or not. In the case of failure, continuing to execute the following code would cause errors in the read function because there is no data in the buffer. Change-Id: Id53037e9e48c97c9eb75835048143875275b6370 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Introduce QSocketNotifier::activate(QSocketDescriptor, QSN::Type)Mårten Nordheim2020-04-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pre-existing overload passes an int, but this can mean the descriptor gets truncated in compilations where the descriptor is 64-bit. The old overload with int is visible when querying the metaobject system so string-based connects still work as before, and connecting to it will produce a deprecation warning in the output. At the same time the PMF-based connect will, on recompile, pick the QSocketDescriptor overload. As an added improvement it also comes with the notification type, removing the need for separate slots where the code would be mostly shared anyway. The QSocketDescriptor type can be implicitly converted to and from qintptr to ensure existing code still compiles. It can also be constructed from Qt::HANDLE on Windows. In this same patch I also update the existing string-based connects in this module, which then includes updating the parameters for some slots as well. [ChangeLog][QtCore][QSocketNotifier] Added QSocketNotifier::activated(QSocketDescriptor, QSocketNotifier::Type). This replaces the activated(int) signal which in 64-bit environments could truncate the socket descriptor. If you use "activated" with the string-based connect() then you need to update the parameter type of the signal and slot if it had one. If you use it with the pointer to member function based connect() then all you need to do is update your slot's parameter type if it has one. If you need to compile your source code with multiple versions of Qt then connect() to this function using pointer to member function and update the slot's parameter type if needed. Task-number: QTBUG-70441 Change-Id: Ic43d6bc4c5bcb4040867b2ffad8d36fb01eed8af Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Tidy nullptr usageAllan Sandfeld Jensen2019-12-061-1/+1
| | | | | | | | | | | Move away from using 0 as pointer literal. Done using clang-tidy. This is not complete as run-clang-tidy can't handle all of qtbase in one go. Change-Id: I1076a21f32aac0dab078af6f175f7508145eece0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Optimize QInotifyFileSystemWatcherEngine::getPathFromID()Marc Mutz2019-07-151-8/+19
| | | | | | | | | | | | | | | | | | | | | The code basically wants to get the last element of equal_range(id). The problem is that backwards iteration on QHash is very expensive, because it's implemented as forward search with wrap-around at bucket end. So it was implementing its own equal_range with look-ahead. The problem is that it compared each key in the equal_range twice: once in the if, and once more in the following while iteration. I expect to see this kind of algorithm more as we move away from the fake bidirectionalism of QHash, so I decided to implement it in a generic way. We can copy it somewhere else when we find more users. Change-Id: I7951652107ab897f6a456035f02e0339835e078d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QFileSystemWatcherEngines: port some Java-style iterators to ranged-forMarc Mutz2019-05-211-12/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Java-style iterators are scheduled to be deprecated. The general pattern used in the patch is that instead of copying an input list, then iterating over the copy with some calls to it.remove() (which leads to quadratic-complexity loops), we simply copy conditionally (a la remove_copy_if instead of remove_if). To make clearer what's going on, rename the outgoing list to 'unhandled'. To avoid having to touch too much of the loops' structure, which sometimes is quite convoluted, use qScopeGuard to do the append to 'unhandled', unless the original code removed the element. Saves a surprising almost 5KiB in text size on GCC 9.1 optimized AMD64 Linux builds. Change-Id: Ifd861de9aa48d66b420858606998dd08a8401e03 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Prefix textstream operators with Qt::Lars Knoll2019-05-021-1/+1
| | | | | | | As the non prefixed variants are deprecated Change-Id: I2ba09d71b9cea5203b54297a3f2332e6d44fedcf Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Fix QFileSystemWatcher::removePath after move operationsFilippo Cucchetto2018-11-121-5/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Foreword: - During a file or directory move the inotify id for an entity is not changed. - QFileSystemWatcher implementation uses a QMultiHash for mapping an id to its path. Suppose this filesystem hypothetical directory structure - A |--> B and user watches both A and B directories. Suppose that the B directory gets moved by calling "mv B B1". The user receives a directoryChanged event for parent directory A and scan filesystem for changes. During this scan the user notices: - a new directory B1 - a deleted directory B The user simply invoke QFileSystemWatcher::addPath(B1) and QFileSystemWatcher::removePath(B). With the actual implementation the second operation could fail: - The call QFileSystemWatcher::addPath(B1) insert a duplicated records in the QFileSystemWatcher::idToPath multihash ( {0, "A"}, {1, "A/B"} {1, "A/B1"} - The call QFileSystemWatcher::removePath(B) fails because - it first retrieves the the id for path B ---> pathToId("A/B") <-- return 1 - Then it calls idToPath.take with the id obtain in the previous step <--- idToPath.take(1) This last operation could take the record {1, "A/B1"} instead of the {1, "A/B"} (because both have the same key) meaning that the next check "x != path" evaluates to true (making the removePath function fail). This patch fixes the problem in the following way: - Use idToPath.equal_range in order to obtain all paths with the given id - Remove the correct record that match (id, path) - Prevent the removal of the inotify watch if another record with the same id is still present in the multihash (like a simple reference counting). Change-Id: I9c8480b2a869d91e500af5c4aded596b9aa53b46 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Modernize the "filesystemwatcher" featureLiang Qi2018-09-271-4/+0
| | | | | | Change-Id: If030b56ad97e047d89d442629262b4839df306d4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QFileSystemWatcher/Linux: don't print warnings for benign casesThiago Macieira2018-06-071-1/+2
| | | | | | | | | | | | ENOENT (no such file or directory) is a benign error, since it could happen also out of a race condition. All the other errors in the inotify_add_watch(2) man page indicate bugs in Qt or resource exhaustion, so those remain being printed. Task-number: QTBUG-68586 Change-Id: I04b94079b6da48f39a82fffd1535c08d8a3d8c33 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* Android: Fix compile with unified headersBogDan Vatra2017-08-171-1/+9
| | | | | | | | Unified headers now defines _POSIX_THREAD_SAFE_FUNCTIONS but not all libc functions are available in all Android API versions. Change-Id: I01c94f0b89e7f8aa8575e7bbda28d9fe41a68ff1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QtCore: include mocsThiago Macieira2017-05-051-0/+2
| | | | | | | | | | | | | | | | | | | Compilation and link times in CPU seconds with GCC 7, using precompiled headers (not including moc, rcc, uic, etc. steps or headersclean): Before After Debug -O0 198,1 180,3 Debug -Og 240,7 229,2 Release -O3 267,1 249,2 Release LTO 239,4 229,8 QtCore required a little manual adjusting because some files are bootstrapped into moc itself and into qmake. Change-Id: I84e363d735b443cb9beefffd14b8b57c10e7da36 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* QtCore: use printf-style qWarning/qDebug where possible (I)Marc Mutz2016-03-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The printf-style version of QDebug expands to a lot less code than the std::ostream-style version. Of course, you pay in type safety (but compilers warn about it these days), you cannot stream complex Qt types and streaming QStrings is awkward, but in many cases you actually improve on readability. But the main reason is that something that's not supposed to be executed under normal operation has no business bloating executable code size. This is not an attempt at converting all qWarnings() to printf-style, only the low-hanging fruit. In this first part, replace qWarning() << "" with qWarning("..."). Saves ~750b in text size on optimized GCC 5.3 AMD64 builds. Change-Id: I8bf3e46cd5a6b2cae0ceb3e355a50f61925c63d3 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* QtCore: eradicate all Q_FOREACH loops [io]Marc Mutz2016-01-041-1/+1
| | | | | | | | Saves more than 1KiB in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I1a974e903bc8352af800fa26edae0194c1e51705 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QFileSystemWatcher: print out path in case of error.David Faure2015-11-231-1/+2
| | | | | | | | | | | | | Before: QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No such file or directory After: QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch("/home/dfaure/.local/share/user-places.xbel") failed: No such file or directory (assuming "%{function}:" in $QT_MESSAGE_PATTERN) Change-Id: I6cc68529516b33683bd69fbb61e04df8a8aa880d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Add AArch64 support to qfilesystemwatcher_inotify.cppDmitry Shachnev2014-03-141-0/+9
| | | | | | | | Based on a patch by Marcin Juszkiewicz <marcin@juszkiewicz.com.pl>, licensed under CC0 (aka Public Domain) or BSD license. Change-Id: I60815d6893c7a9d2873864ff626b865881ec5ee9 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* expand tabs and related whitespace fixes in *.{cpp,h,qdoc}Oswald Buddenhagen2014-01-131-3/+3
| | | | | | | | the diff -w for this commit is empty. Started-by: Thiago Macieira <thiago.macieira@intel.com> Change-Id: I77bb84e71c63ce75e0709e5b94bee18e3ce6ab9e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix QFileSystemWatcher inotifyRiccardo Ferrazzo2013-09-191-4/+17
| | | | | | | | | | | On linux using QFileSystemWatcher with inotify backend when a watched file is moved and added again to the watched files its path is not replaced with the new one. This behavior prevents the emission of the fileChanged signal with the wrong file path. Task-number: QTBUG-33211 Change-Id: Ib45d8efdf5afbf8b8f6b4b26e43f3d6ee740aca6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove use of 'register' from Qt.Stephen Kelly2013-06-171-1/+1
| | | | | | | | | | It is deprecated and clang is starting to warn about it. Patch mostly generated by clang itself, with some careful grep and sed for the platform-specific parts. Change-Id: I8058e6db0f1b41b33a9e8f17a712739159982450 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* QNX: Use inotify on QNX systems that support itThomas McGuire2012-10-301-0/+8
| | | | | | | Change-Id: Ia9bf8d3c202b17746036e203268ef6229aaa900d Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com> Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update obsolete contact address.Jason McDonald2012-01-231-1/+1
| | | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: Id689fdb78727abafba033bed7b0402e2cf27aba1 Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Fix incorrect check for error when monitoring a path using inotify.Robin Burchell2012-01-211-1/+1
| | | | | | | | | | | Per the manpage, inotify_add_watch will return -1 in the case of error, 0 is a valid watch descriptor. Task-number: QTBUG-12564 Change-Id: I56a54de2f5cf18b40aaeddc6de51d18dacbf8daf Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Giuseppe D'Angelo <dangelog@gmail.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Make QFileSystemWatcherEngines children of QFileSystemWatcherBradley T. Hughes2012-01-121-5/+6
| | | | | | | | | | To support moving QFileSystemWatcher to another thread, the engines need to follow when the watcher is moved. The easiest way to do this is by parenting the engines to the watcher. Change-Id: Ie2bb701c0c148da9cc2302d4de23286b8ef42c4d Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove unnecessary QMutexes in QFileSystemWatcher implementationsBradley T. Hughes2012-01-121-6/+0
| | | | | | | | | | | | | The polling, inotify, and kqueue implementations are no longer threaded, and as such, do not need mutexes to protect their internal data (since QFileSystemWatcher itself is not documented as a thread-safe API). The Windows implementation is unchanged as it uses multiple threads explicitly. Change-Id: Ia82510397e576bf704ce3aed3d776b58b39f7ff3 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
* Avoid races when destroying QFileSystemWatcherBradley T. Hughes2012-01-121-0/+1
| | | | | | | | | | | | | | | On Mac OS X, socket notifiers need to be disabled/destroyed before closing their associated file descriptor, otherwise we cause races inside the CFSocket system. The documentation for CFSocketInvalidate() says that we close the file descriptor after calling this function when the kCFSocketCloseOnInvalidate flag is explicitly cleared (QCocoaEventDispatcher clears this flag). Do the same on the Linux inotify watcher as well, for symmetry. Change-Id: I5592cc4bb5be4b752e48d895a685d3c92826acc7 Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
* Remove thread from QFileSystemWatcherEngine implementations.Robin Burchell2012-01-101-16/+2
| | | | | | | | | | | | | | | | | | | | | | These threads are actually counterproductive, as generally speaking, processing watches is not that expensive an operation, so instead, they process at full speed and can (in the case of slow processing in the thread processing the events) stack up and consume resources for no good reason. Threads also have an additional resource consumption per engine (some ~8mb of thread stack on Linux), so doing away with them is nice. A side effect of this change is that events are now effectively rate-limited by the eventloop speed of the thread they run in, so if your thread runs too slow, and you recieve a lot of events, on some platforms, events may be dropped now where in the past, they would be read by the monitor thread and turned into Qt signals (thus not visibly showing as a problem, apart from invisibly bloating memory usage). Task-number: QTBUG-20028 Change-Id: I345a56a8c709f6f778ca9a0b55b57c05229ba477 Reviewed-by: João Abecasis <joao.abecasis@nokia.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
* Remove duplicate fnctl() call.Robin Burchell2012-01-061-1/+0
| | | | | | | | QInotifyFileSystemWatcherEngine's constructor calls this, there's no need to do it twice. Change-Id: Ic19e758a3f87f2e3a885e5b834f59a5a0fe13f4b Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Fix obsolete contact emailJason McDonald2011-07-281-1/+1
| | | | | | | | | | | Replace the old Trolltech contact email address with the current Qt contact email address. Task-number: QTBUG-20370 Change-Id: If5b9c3a044e1ee46264548eea456c704ced8e363 Reviewed-on: http://codereview.qt.nokia.com/2153 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update licenseheader text in source files for qtbase Qt moduleJyri Tahtela2011-05-241-17/+17
| | | | | | | Updated version of LGPL and FDL licenseheaders. Apply release phase licenseheaders for all source files. Reviewed-by: Trust Me
* Initial import from the monolithic Qt.Qt by Nokia2011-04-271-0/+410
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12