From 9747ab19d16af0126733346f6b5c65ae5f1fc488 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 14 Jan 2024 10:44:23 -0800 Subject: [PATCH] Eliminate UVAR_FILE_SET_MTIME_HACK checks This was previously limited to Linux predicated on the existence of certain headers, but Rust just exposes those functions unconditionally. So remove the check and just perform the mtime hack on Linux and Android. --- cmake/ConfigureChecks.cmake | 9 --------- config_cmake.h.in | 3 --- src/env_universal_common.rs | 12 +++++------- src/libc.c | 9 --------- src/libc.rs | 1 - 5 files changed, 5 insertions(+), 29 deletions(-) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 0686d4ef0..58021ac0f 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -44,15 +44,6 @@ include(CheckCXXSymbolExists) include(CheckCXXSourceCompiles) include(CheckTypeSize) -# workaround for lousy mtime precision on a Linux kernel -if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android") - check_cxx_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME) - check_cxx_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) - if ((HAVE_CLOCK_GETTIME) AND (HAVE_FUTIMENS)) - set(UVAR_FILE_SET_MTIME_HACK 1) - endif() -endif() - check_cxx_symbol_exists(gettext libintl.h HAVE_GETTEXT) check_type_size("wchar_t[8]" WCHAR_T_BITS LANGUAGE CXX) diff --git a/config_cmake.h.in b/config_cmake.h.in index b212e5735..81887c52f 100644 --- a/config_cmake.h.in +++ b/config_cmake.h.in @@ -7,9 +7,6 @@ /* Define to 1 if the _nl_msg_cat_cntr symbol is exported. */ #cmakedefine HAVE__NL_MSG_CAT_CNTR 1 -/* Define to use clock_gettime and futimens to hack around Linux mtime issue */ -#cmakedefine UVAR_FILE_SET_MTIME_HACK 1 - /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "https://github.com/fish-shell/fish-shell/issues" diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index 1867395dd..efad49460 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -9,7 +9,6 @@ use crate::fallback::fish_mkstemp_cloexec; use crate::fds::AutoCloseFd; use crate::fds::{open_cloexec, wopen_cloexec}; use crate::flog::{FLOG, FLOGF}; -use crate::libc::UVAR_FILE_SET_MTIME_HACK; use crate::path::path_get_config; use crate::path::{path_get_config_remoteness, DirRemoteness}; use crate::wchar::prelude::*; @@ -20,9 +19,7 @@ use crate::wutil::{ wunlink, FileId, INVALID_FILE_ID, }; use errno::{errno, Errno}; -use libc::{ - CLOCK_REALTIME, EINTR, ENOTSUP, EOPNOTSUPP, LOCK_EX, O_CREAT, O_RDONLY, O_RDWR, UTIME_OMIT, -}; +use libc::{EINTR, ENOTSUP, EOPNOTSUPP, LOCK_EX, O_CREAT, O_RDONLY, O_RDWR}; use std::collections::hash_map::Entry; use std::collections::HashSet; use std::ffi::CString; @@ -800,10 +797,11 @@ impl EnvUniversal { // // It's probably worth finding a simpler solution to this. The tests ran into this, but it's // unlikely to affect users. - if unsafe { UVAR_FILE_SET_MTIME_HACK() } { + #[cfg(any(target_os = "linux", target_os = "android"))] + { let mut times: [libc::timespec; 2] = unsafe { std::mem::zeroed() }; - times[0].tv_nsec = UTIME_OMIT; // don't change ctime - if unsafe { libc::clock_gettime(CLOCK_REALTIME, &mut times[1]) } != 0 { + times[0].tv_nsec = libc::UTIME_OMIT; // don't change ctime + if unsafe { libc::clock_gettime(libc::CLOCK_REALTIME, &mut times[1]) } != 0 { unsafe { libc::futimens(private_fd.fd(), ×[0]); } diff --git a/src/libc.c b/src/libc.c index c1f1ddc35..6440878ac 100644 --- a/src/libc.c +++ b/src/libc.c @@ -64,15 +64,6 @@ int C_PC_CASE_SENSITIVE() { FILE* stdout_stream() { return stdout; } -static const bool uvar_file_set_mtime_hack = -#ifdef UVAR_FILE_SET_MTIME_HACK - true; -#else - false; -#endif -#undef UVAR_FILE_SET_MTIME_HACK -bool UVAR_FILE_SET_MTIME_HACK() { return uvar_file_set_mtime_hack; } - int C_RLIMIT_CORE() { return RLIMIT_CORE; } int C_RLIMIT_DATA() { return RLIMIT_DATA; } int C_RLIMIT_FSIZE() { return RLIMIT_FSIZE; } diff --git a/src/libc.rs b/src/libc.rs index 5b26f56b0..8e3af35e5 100644 --- a/src/libc.rs +++ b/src/libc.rs @@ -48,7 +48,6 @@ extern "C" { len: libc::size_t, ) -> libc::size_t; pub fn stdout_stream() -> *mut libc::FILE; - pub fn UVAR_FILE_SET_MTIME_HACK() -> bool; pub fn setlinebuf(stream: *mut libc::FILE); }