From a0916048f7cccab1b83530d4bc3cd14e63c4dba3 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 4 Jan 2025 21:36:18 +0800 Subject: misc: O_CLOEXEC to all open-related syscalls --- misc/open_file.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/open_file.go b/misc/open_file.go index 2ee53db..5bc6067 100644 --- a/misc/open_file.go +++ b/misc/open_file.go @@ -29,7 +29,7 @@ func Open_file_at(dir Dir_t, filename string, flags int, perms os.FileMode) (*os // Open a file at or beneath the given directory. func Open_file_beneath(dir Dir_t, filename string, flags int, perms os.FileMode) (*os.File, error) { fd, err := Openat2(dir.fd, filename, &Open_how_t{ - Flags: uint64(flags), + Flags: uint64(flags)|syscall.O_CLOEXEC, Mode: uint64(syscallMode(perms)), Resolve: RESOLVE_BENEATH|RESOLVE_NO_SYMLINKS, }) @@ -47,7 +47,7 @@ func Open_file_beneath(dir Dir_t, filename string, flags int, perms os.FileMode) // Open a directory as read-only and return a Dir_t to it. The caller is // responsible for closing the directory with [Close_directory]. func Open_directory_readonly(path string) (Dir_t, error) { - _fd, err := syscall.Open(path, os.O_RDONLY|syscall.O_DIRECTORY, 0) + _fd, err := syscall.Open(path, syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_CLOEXEC, 0) return Dir_t{fd: _fd, name: path}, err } -- cgit v1.2.3