diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-03-28 11:05:46 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-03-30 11:45:05 +0200 |
commit | 65e179a1e7021ab655c07dc392d5dd6fba2d2acb (patch) | |
tree | 7b460ed7fd3c049be03c9d7e996a2737b346c33f /docs | |
parent | 5ccf06074abfd53e7f580764137eb17542830928 (diff) | |
download | systemd-65e179a1e7021ab655c07dc392d5dd6fba2d2acb.tar.gz |
tmpfiles: Try to take a BSD lock on files as well
Similar to what we do for directories, just before we remove a file,
let's try to take a BSD lock on it. If that fails, skip removing the
file.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/TEMPORARY_DIRECTORIES.md | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/docs/TEMPORARY_DIRECTORIES.md b/docs/TEMPORARY_DIRECTORIES.md index 4e815ed4d2..d655b9ca77 100644 --- a/docs/TEMPORARY_DIRECTORIES.md +++ b/docs/TEMPORARY_DIRECTORIES.md @@ -111,14 +111,13 @@ strategies to avoid these issues: towards unexpected program termination as there are never files on disk that need to be explicitly deleted. -3. 🥇 Operate below a sub-directory of `/tmp/` and `/var/tmp/` you created, and - take a BSD file lock ([`flock(dir_fd, - LOCK_SH)`](https://man7.org/linux/man-pages/man2/flock.2.html)) on that - sub-directory. This is particularly interesting when operating on more than - a single file, or on file nodes that are not plain regular files, for - example when extracting a tarball to a temporary directory. The ageing - algorithm will skip all directories (and everything below them) that are - locked through a BSD file lock. As BSD file locks are automatically released +3. 🥇 Take an exclusive or shared BSD file lock ([`flock()`]( + https://man7.org/linux/man-pages/man2/flock.2.html)) on files and directories + you don't want to be removed. This is particularly interesting when operating + on more than a single file, or on file nodes that are not plain regular files, + for example when extracting a tarball to a temporary directory. The ageing + algorithm will skip all directories (and everything below them) and files that + are locked through a BSD file lock. As BSD file locks are automatically released when the file descriptor they are taken on is closed, and all file descriptors opened by a process are implicitly closed when it exits, this is a robust mechanism that ensures all temporary files are subject to ageing @@ -127,9 +126,7 @@ strategies to avoid these issues: modification/access times, as extracted files are otherwise immediately candidates for deletion by the ageing algorithm. The [`flock`](https://man7.org/linux/man-pages/man1/flock.1.html) tool of the - `util-linux` packages makes this concept available to shell scripts. Note - that `systemd-tmpfiles` only checks for BSD file locks on directories, locks - on other types of file nodes (including regular files) are not considered. + `util-linux` packages makes this concept available to shell scripts. 4. Keep the access time of all temporary files created current. In regular intervals, use `utimensat()` or a related call to update the access time |