From f0d4fd85b116a30319c1b42f1f79c33ebaa69441 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 15 Oct 2021 21:12:26 -0700 Subject: [PATCH] Use __GLIBC_PREREQ instead of parsing gnu_get_libc_version __GLIBC_PREREQ is the preferred way to conditionally enable features based on glibc versions. Use it to avoid expensive parsing and locale sensitivity. See #8204 --- src/env_dispatch.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/env_dispatch.cpp b/src/env_dispatch.cpp index 7304d41ac..f826078fd 100644 --- a/src/env_dispatch.cpp +++ b/src/env_dispatch.cpp @@ -268,8 +268,6 @@ extern "C" { const char *gnu_get_libc_version(); } -// Disallow posix_spawn entirely on glibc <= 2.24. -// See #8021. static bool allow_use_posix_spawn() { // OpenBSD's posix_spawn returns status 127, instead of erroring with ENOEXEC, when faced with a // shebangless script. Disable posix_spawn on OpenBSD. @@ -279,14 +277,17 @@ static bool allow_use_posix_spawn() { bool result = true; // uClibc defines __GLIBC__. #if defined(__GLIBC__) && !defined(__UCLIBC__) - const char *version = gnu_get_libc_version(); - result = version && strtod_l(version, nullptr, fish_c_locale()) >= 2.24; + // Disallow posix_spawn entirely on glibc < 2.24. + // See #8021. + if (!__GLIBC_PREREQ(2, 24)) { + result = false; + } #endif return result; } static void handle_fish_use_posix_spawn_change(const environment_t &vars) { - // Note if the variable is missing or empty, we default to true. + // Note if the variable is missing or empty, we default to true if allowed. if (!allow_use_posix_spawn()) { g_use_posix_spawn = false; } else if (auto var = vars.get(L"fish_use_posix_spawn")) {