blob: 623fd5cbe66b76dc2a40ebdfdd025c882ea6d2dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# Mixing flock() and close() on Various Unices
https://stackoverflow.com/questions/70045539/file-retains-lock-after-mmap-and-close
This turned out to be a bigger problem than I thought. Well, too late to fix the
kernel now.
Added `fcntl()` as control.
## INSTALL
```sh
mkdir flock_mmap
cd flock_mmap
wget \
https://github.com/dxdxdt/gists/raw/master/flock_mmap/tests.sh \
https://github.com/dxdxdt/gists/raw/master/flock_mmap/Makefile \
https://github.com/dxdxdt/gists/raw/master/flock_mmap/flock_mmap.c \
https://github.com/dxdxdt/gists/raw/master/flock_mmap/README.md
chmod 755 tests.sh
```
## Run it
```sh
make 2> /dev/null
```
### Result A
- Linux
```
./tests.sh
[TEST]fcntl(fd, F_SETLK, ...) and close() unlocks the file: YES
[TEST]fcntl(fd, F_SETLK, ...) and holding unlocks the file: NO
[TEST]flock() and close() unlocks the file*: NO
[TEST]flock() and holding unlocks the file : NO
```
### Result B
- FreeBSD
- OpenBSD
- mac
```
./tests.sh
[TEST]fcntl(fd, F_SETLK, ...) and close() unlocks the file: YES
[TEST]fcntl(fd, F_SETLK, ...) and holding unlocks the file: NO
[TEST]flock() and close() unlocks the file*: YES
[TEST]flock() and holding unlocks the file : NO
```
|