diff options
author | David Timber <dxdt@dev.snart.me> | 2024-03-22 10:58:42 +0900 |
---|---|---|
committer | David Timber <dxdt@dev.snart.me> | 2024-03-22 11:06:45 +0900 |
commit | 5fc02e2e847608a67d46af04d5f935cd889b23c3 (patch) | |
tree | bace61b3c4836a665e004562f48f441ee359d1c2 /flock_mmap/README.md | |
parent | 567496b2b4e68eafb0bc37b7e3ed5acf76afb3a6 (diff) |
Add flock_mmap
Diffstat (limited to 'flock_mmap/README.md')
-rw-r--r-- | flock_mmap/README.md | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/flock_mmap/README.md b/flock_mmap/README.md new file mode 100644 index 0000000..623fd5c --- /dev/null +++ b/flock_mmap/README.md @@ -0,0 +1,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 +``` |