Use O_CLOEXEC when opening THP sysfs file in init_thp_state.

This commit is contained in:
Itay Bookstein
2026-07-19 13:00:40 +00:00
committed by Slobodan Predolac
parent c597d73778
commit d0705543e0

View File

@@ -826,8 +826,16 @@ init_thp_state(void) {
static const char sys_state_never[] = "always madvise [never]\n"; static const char sys_state_never[] = "always madvise [never]\n";
char buf[sizeof(sys_state_madvise)]; char buf[sizeof(sys_state_madvise)];
# if defined(O_CLOEXEC)
int fd = malloc_open(
"/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY | O_CLOEXEC);
# else
int fd = malloc_open( int fd = malloc_open(
"/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY); "/sys/kernel/mm/transparent_hugepage/enabled", O_RDONLY);
if (fd != -1) {
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
}
# endif
if (fd == -1) { if (fd == -1) {
goto label_error; goto label_error;
} }