Skip to content

Commit

Permalink
Merge pull request #11538 from NixOS/detect-close_range
Browse files Browse the repository at this point in the history
Use close_range when available
  • Loading branch information
edolstra committed Sep 19, 2024
2 parents a45a7e8 + 5c87c40 commit e60b901
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static char buf[1024];]],
AC_LANG_POP(C++)


AC_CHECK_FUNCS([statvfs pipe2])
AC_CHECK_FUNCS([statvfs pipe2 close_range])


# Check for lutimes, optionally used for changing the mtime of
Expand Down
1 change: 1 addition & 0 deletions src/libutil/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ subdir('build-utils-meson/subprojects')
# HAVE_LUTIMES 1`. The `#define` is unconditional, 0 for not found and 1
# for found. One therefore uses it with `#if` not `#ifdef`.
check_funcs = [
'close_range',
# Optionally used for changing the mtime of symlinks.
'lutimes',
# Optionally used for creating pipes on Unix
Expand Down
5 changes: 4 additions & 1 deletion src/libutil/unix/file-descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ void Pipe::create()
//////////////////////////////////////////////////////////////////////

#if __linux__ || __FreeBSD__
// In future we can use a syscall wrapper, but at the moment musl and older glibc version don't support it.
static int unix_close_range(unsigned int first, unsigned int last, int flags)
{
#if !HAVE_CLOSE_RANGE
return syscall(SYS_close_range, first, last, (unsigned int)flags);
#else
return close_range(first, last, flags);
#endif
}
#endif

Expand Down

0 comments on commit e60b901

Please sign in to comment.