From 6c0c4fa2cf979b0516852685487b45c0947e50fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 21 Apr 2024 17:28:40 +0800 Subject: [PATCH] Host (Linux): improve performance of WSL version detection --- src/detection/host/host_linux.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index 92b1c49f9..e6311f0fd 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -78,20 +78,12 @@ const char* ffDetectHost(FFHostResult* host) ffStrbufAppendF(&host->name, " - %s", wslDistroName); ffStrbufAppendS(&host->family, "WSL"); - FF_STRBUF_AUTO_DESTROY wslVer = ffStrbufCreate(); //Wide characters - if(!ffProcessAppendStdOut(&wslVer, (char* const[]){ - "wsl.exe", - "--version", - NULL - }) && wslVer.length > 0) - { - ffStrbufSubstrBeforeFirstC(&wslVer, '\r'); //CRLF - ffStrbufSubstrAfterLastC(&wslVer, ' '); - for(uint32_t i = 0; i < wslVer.length; ++i) { - if(wslVer.chars[i]) //don't append \0 - ffStrbufAppendC(&host->version, wslVer.chars[i]); - } - } + ffProcessAppendStdOut(&host->version, (char* const[]){ + "wslinfo", + "--wsl-version", + "-n", + NULL, + }); // supported in 2.2.3 and later } }