mirror of https://github.com/mkerrisk/man-pages
open.2: In O_TMPFILE example, describe alternative linkat() call
This was already shown in an earlier version of the page, but Adam Borowski's patch replaced it with an alternative. Probably, it is better to show both possibilities. Reported-by: "Joseph C. Sible" <josephcsible@gmail.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
fc29a199d9
commit
a2587fbb2e
10
man2/open.2
10
man2/open.2
|
@ -812,6 +812,16 @@ fd = open("/path/to/dir", O_TMPFILE | O_RDWR,
|
|||
/* File I/O on 'fd'... */
|
||||
|
||||
linkat(fd, NULL, AT_FDCWD, "/path/for/file", AT_EMPTY_PATH);
|
||||
|
||||
/* If the caller doesn't have the CAP_DAC_READ_SEARCH
|
||||
capability (needed to use AT_EMPTY_PATH with linkat(2)),
|
||||
and there is a proc(5) filesystem mounted, then the
|
||||
linkat(2) call above can be replaced with:
|
||||
|
||||
snprintf(path, PATH_MAX, "/proc/self/fd/%d", fd);
|
||||
linkat(AT_FDCWD, path, AT_FDCWD, "/path/for/file",
|
||||
AT_SYMLINK_FOLLOW);
|
||||
*/
|
||||
.EE
|
||||
.in
|
||||
.IP
|
||||
|
|
Loading…
Reference in New Issue