From 44022e65c2237bc3dd01b0fc9ccbf8c2dcbdfc51 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 25 Aug 2019 18:29:46 -0500 Subject: [PATCH] Revert "Remove the WSL warning" This reverts commit 5101bdeb9f2d2d0a362619edde3da8c1b9cd7101. --- src/common.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index a775314ce..54856d3af 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -32,6 +31,11 @@ #include #endif +#ifdef __linux__ +// Includes for WSL detection +#include +#endif + #ifdef __FreeBSD__ #include #elif __APPLE__ @@ -153,10 +157,29 @@ bool is_windows_subsystem_for_linux() { #elif not defined(__linux__) return false; #else + // We are purposely not using std::call_once as it may invoke locking, which is an unnecessary + // overhead since there's no actual race condition here - even if multiple threads call this + // routine simultaneously the first time around, we just end up needlessly querying uname(2) one + // more time. + static bool wsl_state = []() { - utsname info{}; + utsname info; uname(&info); - return std::strstr(info.release, "Microsoft") != nullptr; + + // Sample utsname.release under WSL: 4.4.0-17763-Microsoft + if (std::strstr(info.release, "Microsoft") != nullptr) { + const char *dash = std::strchr(info.release, '-'); + if (dash == nullptr || strtod(dash + 1, nullptr) < 17763) { + debug(1, + "This version of WSL is not supported and fish will probably not work " + "correctly!\n" + "Please upgrade to Windows 10 1809 (17763) or higher to use fish!"); + } + + return true; + } else { + return false; + } }(); // Subsequent calls to this function may take place after fork() and before exec() in