summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qlockfile.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QLockFile: remove unneeded tryLock_impl middle-manMarc Mutz2023-07-071-5/+1
| | | | | | | | | | | | | It's perfectly ok to de-inline a function, even an exported one, so remove the tryLock_impl() middle-man and pull the Qt 7 pre-programming into the here and now. Amends 5cea5fc80b9e1b19d620ec6be1acd5cdbd220971. Pick-to: 6.6 Change-Id: I7e9626a91d8ebd64e02c3784c74621950da669fb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QLockFile: {set}StaleLockTime: use chrono firstAhmad Samir2023-03-151-11/+26
| | | | | | | | | | This is similar to the tryLock() commit, making the chrono overloads the main methods, this way the lock time isn't limited by the size of int, but rather by std::chrono::milliseconds (which can be as up to int64_t). Task-number: QTBUG-110059 Change-Id: I8d1652748b16be2154233f7db57ed485bcab62c7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLockFile: tryLock(): use chrono firstAhmad Samir2023-03-141-28/+42
| | | | | | | | | | | | I.e. tryLock(chrono::milliseconds) shouldn't call the int overload as that truncates the timeout (milliseconds is typically int64_t). Add a note to the tryLock(millisecons) docs that passing milliseconds::max() will make it wait forever to obtain the lock. Task-number: QTBUG-110059 Change-Id: Ib48d9b1b117ce816348625331543d6ba8a788973 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Use QFileInfo's file times in UTC for file timestampsAhmad Samir2023-01-041-2/+2
| | | | | | | | | | | This is inherently faster than getting it in UTC from the underlying native API stat call, then converting it to the Local Time Zone just to compare them. The same goes for any use-case where you get a QDateTime then the first thing you do is call t.to{Msec,Secs}SinceEpoch(). Change-Id: Ic13bcfd99b937c9f10f102ea7741832950a553c6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-40/+4
| | | | | | | | | | | | | 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>
* QtCore: replace QLatin1String/QLatin1Char with _L1/u'' where applicableSona Kurazyan2022-03-251-1/+3
| | | | | | | | | | | As a drive-by, did also minor refactorings/improvements. Task-number: QTBUG-98434 Change-Id: I81964176ae2f07ea63674c96f47f9c6aa046854f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
* QLockFile: don't use the local timezone to compare file timesThiago Macieira2021-04-261-1/+1
| | | | | | | | | There's no need to find the local time zone and do expensive conversions to compare regular, old seconds-since-1970 to the time now. Task-number: QTBUG-93069 Change-Id: I6cdea00671e8479b9c50fffd167897b91a04ce03 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Fix qdoc warnings from new QLockFile membersVolker Hilsheimer2021-04-131-4/+3
| | | | | | Change-Id: I06210fe37a3d90a958064fff48331a34bced2a8b Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Nico Vertriest <nico.vertriest@qt.io>
* Add std::chrono overloads for QLockFile functionsShantanu Tushar2021-04-011-0/+49
| | | | | | | | This makes it convenient to use QLockFile for projects which are able to use std::chrono to denote durations. Change-Id: Ib4520f6142412bdefe659fccc1e6d15b81af2f25 Reviewed-by: David Faure <david.faure@kdab.com>
* Add function to access QLockFile's file nameShantanu Tushar2020-10-181-0/+8
| | | | | | | | This is useful in cases like error handling when you need to print the name of the lock file. Change-Id: Ife4901ed53ae81d19e68cce7f1c173ef3745d56f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLockFile/Unix: save the boot and machine IDs in the lock file tooThiago Macieira2017-11-141-3/+28
| | | | | | | | | | | | | | | This allows us to make sure that the PID we read is from the same boot as we are right now running. The collision could happen on embedded systems where the boot sequence is fixed, so all the same processes would have the exact same PIDs after reboot as they did before. [ChangeLog][QtCore][QLockFile] QLockFile can now properly conclude that a lock file from a previous boot of the same device is stale and can be removed. This is implemented only for Linux and Apple operating systems. Task-number: QTBUG-63425 Change-Id: I0b48fc8e90304e0dacc3fffd14e8e3a197211788 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* QLockFile: don't use QCoreApplication::applicationName()Thiago Macieira2017-10-061-1/+1
| | | | | | | | | | | | | | | | | | | That was stupid for two reasons. First, applicationName() can be changed by the user by calling QCoreApplication::setApplicationName(), so if that happens, we won't be able to properly identify a lock belonging to a given application because the name changed. Second, because applicationName() is not what we compare to. Instead, let's use processNameByPid() on both content creation and verification. [ChangeLog][QtCore][QLockFile] Fixed a bug that would cause QLockFile mis-identify valid lock files as stale if the application name was set with QCoreApplication::setApplicationName(). Change-Id: I0b48fc8e90304e0dacc3fffd14e912a5c98c87e7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QLockInfo: Centralize the management of the lock file's contentsThiago Macieira2017-10-061-10/+61
| | | | | | | | | We duplicated both the creation of the contents and the check if the file was stale. Centralize everything in qlockfile.cpp. Change-Id: I0b48fc8e90304e0dacc3fffd14e91174af79841f Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QLockFile: Don't deadlock if the lock file has a mtime in the futureOlivier Goffart2017-03-101-0/+3
| | | | | | | | | | | | Stale Lock files in the future can happen in some situations. For exemple two computers with different clocks access the same file system. It could be that one of the timestamp is totaly off (several years into the future). [ChangeLog][QtCore][QLockFile] Fixed a deadlock occurring if a corrupted lock file's modification time is in the future. Change-Id: I8dac98a0e898c76bcef67f8c195e126c996b6add Reviewed-by: David Faure <david.faure@kdab.com>
* Doc: add a quick note about unfixed Windows encoding bugThiago Macieira2016-12-281-0/+3
| | | | | | Task-number: QTBUG-49640 Change-Id: Icb0289e3118a41dd9438fffd1492925b03de62d6 Reviewed-by: David Faure <david.faure@kdab.com>
* QLockFile::tryLock: prevent over-sleeping in certain casesThiago Macieira2016-08-301-1/+6
| | | | | | | | | | | | | | | The sleep time increases exponentially, but we never checked whether the time to sleep was less than the remaining time. For example, if timeout was 4000 ms on entry, we'd progressively sleep 100 ms, 200, 400, 800, 1600 ms. At this point, the accummulated sleep time would be 3100 ms and the next sleep should be no more than 900 ms. Prior to this change, the tryLock() would then proceed to sleep 3200 ms, for a total wait time of 6300 ms, or 57.5% above the timeout provided by the user. Change-Id: Ifc295639c8cf4ddcaa69fffd146f7586a7ee95e4 Reviewed-by: David Faure <david.faure@kdab.com>
* QLockFile: Use QDeadlineTimer in tryLockThiago Macieira2016-08-301-5/+3
| | | | | | | This simplifies the code a bit. Change-Id: Ifc295639c8cf4ddcaa69fffd146f7535d646cb15 Reviewed-by: David Faure <david.faure@kdab.com>
* QLockFile: move early out earlier to avoid allocations.Anton Kudryavtsev2016-04-251-2/+2
| | | | | | | | Saves reading two lines and allocating storage for them. Change-Id: I71f6c7019f4c097897945eea52851e4623b75dc2 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com>
* QtCore: replace QStringLiteral with QLatin1String when appendingMarc Mutz2016-02-251-1/+1
| | | | | | | | | | | | | | | | | | It makes little sense to use QStringLiteral for strings which are immediately appended to, or which are appended to other strings, because no dynamic memory allocation is saved by doing so. But if the only advantage of QStringLiteral does not apply, all its disadvantages dominate, to wit: injection of calls to qstring dtor, non-sharability of data between C strings and QStringLiterals and among QStringLiterals, and doubled storage requirements. Fix by replacing QStringLiteral with QLatin1String. Saves 1156B in text size on stripped optimized Linux AMD64 GCC 4.9 builds. Change-Id: If805e431f570ec1d2ac62c548f516f1b17390c3a Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.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>
* take process name into account for QLockFile's pid clash resolutionJoerg Bornemann2015-05-261-4/+8
| | | | | | | | | | | | | | | | To cover the situation that the process ID got reused, the current process name is compared to the name of the process that corresponds to the process ID from the lock file. If the process names differ, the lock file is considered stale. [ChangeLog][QtCore][QLockFile] Detection of stale lock files got more robust and takes the name of the process that belongs to the stored PID into account. Task-number: QTBUG-45497 Change-Id: Ic3c0d7e066435451203e77b9b9ce2d70bfb9c570 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> Reviewed-by: David Faure <david.faure@kdab.com>
* Update copyright headersJani Heikkinen2015-02-111-6/+6
| | | | | | | | | | | | | | | | | | 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>
* Allow hostname from lock files to be emptyRainer Keller2014-10-271-1/+1
| | | | | | | | | | | The common format for lock files is to only contain the PID. (See http://www.pathname.com/fhs/2.2/fhs-5.9.html) Qt includes some extra information but we can not expect this information to be present. Otherwise lock files created by other (non-Qt) processes are not handled correctly. Change-Id: Ib9be3c9f07eb8e87193f56d96f5559bbdd5180b8 Reviewed-by: David Faure <david.faure@kdab.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-18/+10
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Doc: Adding mark-up to boolean default values.Jerome Pasion2013-10-081-9/+9
| | | | | | | | | | | | | | | | | Default values should have mark-up to denote that they are code. This commit changes: -"property is true" to "property is \c true". -"Returns true" to "Returns \c true". -"property is false" to "property is \c false". -"returns true" to "returns \c true". -"returns false" to "returns \c false". src/3rdparty and non-documentation instances were ignored. Task-number: QTBUG-33360 Change-Id: Ie87eaa57af947caa1230602b61c5c46292a4cf4e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Long live QLockFileDavid Faure2013-03-051-0/+346
Locking between processes, implemented with open(O_EXCL) on Unix and CreateFile(CREATE_NEW) on Windows. Supports detecting stale lock files and deleting them. Advisory locking is used to prevent deletion of files that are still in use. Change-Id: Id00ee2a4e77a29483d869037c7047c59cb909339 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>