On 01/02/2024 15:45, Kevin Brodsky wrote:
[...] +/*
- Creates a new temporary file and returns an fd to it. The file has no name
- (see open(2) regarding O_TMPFILE) and is deleted when the fd is closed.
- */
+static inline int tmpfd(void) +{
- int fd;
- fd = syscall(__NR_openat, 0, "/", O_TMPFILE | O_RDWR, 0666);
- ASSERT_GE(fd, 0);
The man pages [1] discuss using O_EXCL with O_TMPFILE to prevent fd from being linked into the filesystem with linkat [2]; is this something worth considering here if we want to discourage files opened with tmpfd() from being linked at any time? Just curious, I imagine it isn't a big deal at all since it would be hard to accidentally call tmpfd and link the result in a test, where this is meant to be used.
Akram
[1] https://man7.org/linux/man-pages/man2/open.2.html#DESCRIPTION
[2] https://man7.org/linux/man-pages/man2/linkat.2.html
**