mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 04:13:08 +00:00
cppcheck: warn on use of flock
This commit is contained in:
parent
2b0bad889a
commit
bf53f39cdd
3 changed files with 17 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<![CDATA[
|
||||
<!-- Sadly we can't enable the following two rules since doing so causes false
|
||||
positives in standard header files rather than just project specific
|
||||
source files. If we can find a way to enable these rules by also
|
||||
|
@ -22,3 +23,13 @@
|
|||
</message>
|
||||
</rule>
|
||||
<--!>
|
||||
]]>
|
||||
|
||||
<rule>
|
||||
<pattern>flock \(</pattern>
|
||||
<message>
|
||||
<id>flockSemanticsWarning</id>
|
||||
<severity>warning</severity>
|
||||
<summary>flock has a fallback implemented in terms of fcntl; ensure that the fcntl semantics will apply (see http://0pointer.de/blog/projects/locking.html)</summary>
|
||||
</message>
|
||||
</rule>
|
||||
|
|
|
@ -595,6 +595,9 @@ bool env_universal_t::open_and_acquire_lock(const wcstring &path, int *out_fd) {
|
|||
// Try taking the lock, if necessary. If we failed, we may be on lockless NFS, etc.; in that
|
||||
// case we pretend we succeeded. See the comment in save_to_path for the rationale.
|
||||
if (needs_lock) {
|
||||
// This is safe in terms of the fallback function implemented in terms of fcntl: only ever
|
||||
// run on the main thread, and protected by the universal variable lock
|
||||
// cppcheck-suppress flockSemanticsWarning
|
||||
while (flock(fd, LOCK_EX) < 0) {
|
||||
/* error */
|
||||
if (errno != EINTR) {
|
||||
|
|
|
@ -129,6 +129,9 @@ int killpg(int pgr, int sig);
|
|||
/// Fallback implementation of flock in terms of fcntl
|
||||
/// Danger! The semantics of flock and fcntl locking are very different.
|
||||
/// Use with caution.
|
||||
// Ignore the cppcheck warning as this is the implementation that it is
|
||||
// warning about!
|
||||
// cppcheck-suppress flockSemanticsWarning
|
||||
int flock(int fd, int op);
|
||||
|
||||
#define LOCK_SH 1 /* Shared lock. */
|
||||
|
|
Loading…
Reference in a new issue