From 765c7b42b6fc3b8003e568ebfb2585b77151364f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 10 Jul 2024 21:55:37 +0800 Subject: [PATCH 1/6] General: rename `--ts-version` to `--detect-version` And use it in more modules --- CHANGELOG.md | 6 +++ doc/json_schema.json | 10 ++-- src/data/help.json | 20 ++++---- src/detection/de/de_linux.c | 2 + src/detection/editor/editor.c | 2 +- src/detection/initsystem/initsystem_linux.c | 53 +++++++++++---------- src/detection/lm/lm_linux.c | 23 +++++---- src/detection/terminalshell/terminalshell.c | 4 +- src/modules/initsystem/initsystem.c | 2 +- src/options/display.c | 6 +-- src/options/display.h | 1 - src/options/general.c | 12 ++--- src/options/general.h | 1 + 13 files changed, 75 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7590c997f..2062750e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2.18.1 + +Changes: +* `--ts-version` has been renamed to `--detect-version` + * `general.detectVersion` in JSON config file + # 2.18.0 Changes: diff --git a/doc/json_schema.json b/doc/json_schema.json index 0545cce7f..df76141ec 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -339,6 +339,11 @@ "type": "string", "description": "Set the command to be executed before printing logos", "default": "" + }, + "showVersion": { + "type": "boolean", + "description": "Whether to detect and display component versions. Mainly for benchmarking", + "default": true } } }, @@ -573,11 +578,6 @@ "type": "boolean", "description": "Whether to disable the stdout application buffer", "default": false - }, - "tsVersion": { - "type": "boolean", - "description": "Whether to detect and display the version of terminal, shell and editor. Mainly for benchmarking", - "default": true } } }, diff --git a/src/data/help.json b/src/data/help.json index 3fb1678e6..750b4bd8b 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -148,6 +148,16 @@ "false": "Try `wayland`, then `x11`, then `drm`" } } + }, + { + "long": "detect-version", + "desc": "Whether to detect and display the version of terminal, shell and editor", + "remark": "Mainly for benchmarking", + "arg": { + "type": "bool", + "optional": true, + "default": true + } } ], "Logo": [ @@ -725,16 +735,6 @@ "type": "color", "default": "light_red" } - }, - { - "long": "ts-version", - "desc": "Whether to detect and display the version of terminal, shell and editor", - "remark": "Mainly for benchmarking", - "arg": { - "type": "bool", - "optional": true, - "default": true - } } ], "Library path": [ diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index a0db88a92..c17e8ac7f 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -180,6 +180,8 @@ static void getBudgie(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options) { + if (!instance.config.general.detectVersion) return "Disabled by config"; + if (ffStrbufEqualS(deName, FF_DE_PRETTY_PLASMA)) getKDE(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_GNOME)) diff --git a/src/detection/editor/editor.c b/src/detection/editor/editor.c index 84b3b2632..f71544d60 100644 --- a/src/detection/editor/editor.c +++ b/src/detection/editor/editor.c @@ -26,7 +26,7 @@ const char* ffDetectEditor(FFEditorResult* result) return "$VISUAL or $EDITOR not set"; } - if (!instance.config.display.tsVersion) return NULL; + if (!instance.config.general.detectVersion) return NULL; #ifndef _WIN32 if (result->name.chars[0] != '/') diff --git a/src/detection/initsystem/initsystem_linux.c b/src/detection/initsystem/initsystem_linux.c index 078d36f1b..9a6023a1c 100644 --- a/src/detection/initsystem/initsystem_linux.c +++ b/src/detection/initsystem/initsystem_linux.c @@ -17,38 +17,41 @@ const char* ffDetectInitSystem(FFInitSystemResult* result) ffStrbufSetS(&result->exe, buf); } - if (ffStrbufEqualS(&result->name, "systemd")) + if (instance.config.general.detectVersion) { - if (ffProcessAppendStdOut(&result->version, (char* const[]) { - ffStrbufEndsWithS(&result->exe, "/systemd") ? result->exe.chars : "systemctl", // use exe path in case users have another systemd installed - "--version", - NULL, - }) == NULL && result->version.length) + if (ffStrbufEqualS(&result->name, "systemd")) { - uint32_t iStart = ffStrbufFirstIndexC(&result->version, '('); - if (iStart < result->version.length) + if (ffProcessAppendStdOut(&result->version, (char* const[]) { + ffStrbufEndsWithS(&result->exe, "/systemd") ? result->exe.chars : "systemctl", // use exe path in case users have another systemd installed + "--version", + NULL, + }) == NULL && result->version.length) { - uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ')'); - ffStrbufSubstrBefore(&result->version, iEnd); - ffStrbufSubstrAfter(&result->version, iStart); + uint32_t iStart = ffStrbufFirstIndexC(&result->version, '('); + if (iStart < result->version.length) + { + uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ')'); + ffStrbufSubstrBefore(&result->version, iEnd); + ffStrbufSubstrAfter(&result->version, iStart); + } } } - } - else if (ffStrbufEqualS(&result->name, "launchd")) - { - if (ffProcessAppendStdOut(&result->version, (char* const[]) { - "/bin/launchctl", - "version", - NULL, - }) == NULL && result->version.length) + else if (ffStrbufEqualS(&result->name, "launchd")) { - uint32_t iStart = ffStrbufFirstIndexS(&result->version, "Version "); - if (iStart < result->version.length) + if (ffProcessAppendStdOut(&result->version, (char* const[]) { + "/bin/launchctl", + "version", + NULL, + }) == NULL && result->version.length) { - iStart += (uint32_t) strlen("Version"); - uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ':'); - ffStrbufSubstrBefore(&result->version, iEnd); - ffStrbufSubstrAfter(&result->version, iStart); + uint32_t iStart = ffStrbufFirstIndexS(&result->version, "Version "); + if (iStart < result->version.length) + { + iStart += (uint32_t) strlen("Version"); + uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ':'); + ffStrbufSubstrBefore(&result->version, iEnd); + ffStrbufSubstrAfter(&result->version, iStart); + } } } } diff --git a/src/detection/lm/lm_linux.c b/src/detection/lm/lm_linux.c index 4adc9ec82..fc5ff4bbe 100644 --- a/src/detection/lm/lm_linux.c +++ b/src/detection/lm/lm_linux.c @@ -163,16 +163,19 @@ const char* ffDetectLM(FFLMResult* result) })) return "Failed to parse " FF_SYSTEMD_SESSIONS_PATH "$XDG_SESSION_ID"; - if (ffStrbufStartsWithS(&result->service, "gdm")) - getGdmVersion(&result->version); - else if (ffStrbufStartsWithS(&result->service, "sddm")) - getSddmVersion(&result->version); - else if (ffStrbufStartsWithS(&result->service, "xfwm")) - getXfwmVersion(&result->version); - else if (ffStrbufStartsWithS(&result->service, "lightdm")) - getLightdmVersion(&result->version); - else if (ffStrbufStartsWithS(&result->service, "sshd")) - getSshdVersion(&result->version); + if (instance.config.general.detectVersion) + { + if (ffStrbufStartsWithS(&result->service, "gdm")) + getGdmVersion(&result->version); + else if (ffStrbufStartsWithS(&result->service, "sddm")) + getSddmVersion(&result->version); + else if (ffStrbufStartsWithS(&result->service, "xfwm")) + getXfwmVersion(&result->version); + else if (ffStrbufStartsWithS(&result->service, "lightdm")) + getLightdmVersion(&result->version); + else if (ffStrbufStartsWithS(&result->service, "sshd")) + getSshdVersion(&result->version); + } // Correct char cases if (ffStrbufIgnCaseEqualS(&result->type, FF_WM_PROTOCOL_WAYLAND)) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 57ccb6a89..f125523ec 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -226,7 +226,7 @@ static bool getShellVersionGeneric(FFstrbuf* exe, const char* exeName, FFstrbuf* bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version) { - if (!instance.config.display.tsVersion) return false; + if (!instance.config.general.detectVersion) return false; if(ffStrEqualsIgnCase(exeName, "sh")) // #849 return false; @@ -546,7 +546,7 @@ static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version) bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version) { - if (!instance.config.display.tsVersion) return false; + if (!instance.config.general.detectVersion) return false; #ifdef __ANDROID__ diff --git a/src/modules/initsystem/initsystem.c b/src/modules/initsystem/initsystem.c index ec3fa6034..b9e7edfc6 100644 --- a/src/modules/initsystem/initsystem.c +++ b/src/modules/initsystem/initsystem.c @@ -29,7 +29,7 @@ void ffPrintInitSystem(FFInitSystemOptions* options) ffPrintLogoAndKey(FF_INITSYSTEM_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); ffStrbufWriteTo(&result.name, stdout); if (result.version.length) - printf(" (%s)\n", result.version.chars); + printf(" %s\n", result.version.chars); else putchar('\n'); } diff --git a/src/options/display.c b/src/options/display.c index b50488c9e..23fb3273c 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -200,7 +200,7 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va else if (ffStrEqualsIgnCase(key, "keyWidth")) options->keyWidth = (uint32_t) yyjson_get_uint(val); else if (ffStrEqualsIgnCase(key, "tsVersion")) - options->tsVersion = yyjson_get_bool(val); + return "display.tsVersion has been renamed to general.detectVersion"; else return "Unknown display property"; } @@ -357,8 +357,6 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key else return false; } - else if(ffStrEqualsIgnCase(key, "--ts-version")) - options->tsVersion = ffOptionParseBoolean(value); else return false; return true; @@ -406,8 +404,6 @@ void ffOptionsInitDisplay(FFOptionsDisplay* options) ffStrbufInitStatic(&options->percentColorGreen, FF_COLOR_FG_GREEN); ffStrbufInitStatic(&options->percentColorYellow, instance.state.terminalLightTheme ? FF_COLOR_FG_YELLOW : FF_COLOR_FG_LIGHT_YELLOW); ffStrbufInitStatic(&options->percentColorRed, instance.state.terminalLightTheme ? FF_COLOR_FG_RED : FF_COLOR_FG_LIGHT_RED); - - options->tsVersion = true; } void ffOptionsDestroyDisplay(FFOptionsDisplay* options) diff --git a/src/options/display.h b/src/options/display.h index 7f248042b..a3be9baf8 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -53,7 +53,6 @@ typedef struct FFOptionsDisplay FFstrbuf percentColorRed; bool noBuffer; uint32_t keyWidth; - bool tsVersion; } FFOptionsDisplay; const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root); diff --git a/src/options/general.c b/src/options/general.c index b2fe71150..c1eabf9cd 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -36,6 +36,8 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va if (error) return "Failed to execute preRun command"; } + else if (ffStrEqualsIgnCase(key, "detectVersion")) + options->detectVersion = yyjson_get_bool(val); #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) else if (ffStrEqualsIgnCase(key, "escapeBedrock")) @@ -66,13 +68,6 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va options->wmiTimeout = (int32_t) yyjson_get_int(val); #endif - else if (ffStrEqualsIgnCase(key, "stat")) - return "Property `general.stat` has been changed to `display.stat`"; - else if (ffStrEqualsIgnCase(key, "pipe")) - return "Property `general.pipe` has been changed to `display.pipe`"; - else if (ffStrEqualsIgnCase(key, "allowSlowOperations")) - return "Property `general.allowSlowOperations` has been obsoleted. See CHANGELOG for detail"; - else return "Unknown general property"; } @@ -86,6 +81,8 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key options->multithreading = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--processing-timeout")) options->processingTimeout = ffOptionParseInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--detect-version")) + options->detectVersion = ffOptionParseBoolean(value); #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) else if(ffStrEqualsIgnCase(key, "--escape-bedrock")) @@ -116,6 +113,7 @@ void ffOptionsInitGeneral(FFOptionsGeneral* options) { options->processingTimeout = 1000; options->multithreading = true; + options->detectVersion = true; #if defined(__linux__) || defined(__FreeBSD__) options->escapeBedrock = true; diff --git a/src/options/general.h b/src/options/general.h index b388f3f43..8b14283d8 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -13,6 +13,7 @@ typedef struct FFOptionsGeneral { bool multithreading; int32_t processingTimeout; + bool detectVersion; // Module options that cannot be put in module option structure #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) From d9f084894e0124e3d98e93906d02430b86b9800a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 10 Jul 2024 22:09:28 +0800 Subject: [PATCH 2/6] General: support more module for `--detect-version` --- src/detection/host/host_linux.c | 15 ++++++----- .../terminalshell/terminalshell_windows.c | 27 ++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index e6311f0fd..41b1733b8 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -78,12 +78,15 @@ const char* ffDetectHost(FFHostResult* host) ffStrbufAppendF(&host->name, " - %s", wslDistroName); ffStrbufAppendS(&host->family, "WSL"); - ffProcessAppendStdOut(&host->version, (char* const[]){ - "wslinfo", - "--wsl-version", - "-n", - NULL, - }); // supported in 2.2.3 and later + if (instance.config.general.detectVersion) + { + ffProcessAppendStdOut(&host->version, (char* const[]){ + "wslinfo", + "--wsl-version", + "-n", + NULL, + }); // supported in 2.2.3 and later + } } } diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 4470f22bc..4f8e02f57 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -99,21 +99,24 @@ static void setShellInfoDetails(FFShellResult* result) { ffStrbufSetS(&result->prettyName, "CMD"); - FF_AUTO_CLOSE_FD HANDLE snapshot = NULL; - while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {} - - if(snapshot) + if (instance.config.general.detectVersion) { - MODULEENTRY32W module; - module.dwSize = sizeof(module); - for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) + FF_AUTO_CLOSE_FD HANDLE snapshot = NULL; + while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {} + + if(snapshot) { - if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) + MODULEENTRY32W module; + module.dwSize = sizeof(module); + for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) { - ffStrbufAppendS(&result->prettyName, " (with Clink "); - getProductVersion(module.szExePath, &result->prettyName); - ffStrbufAppendC(&result->prettyName, ')'); - break; + if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) + { + ffStrbufAppendS(&result->prettyName, " (with Clink "); + getProductVersion(module.szExePath, &result->prettyName); + ffStrbufAppendC(&result->prettyName, ')'); + break; + } } } } From 48bb38ca85e918979f1125ff33fdf7b652182459 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 11 Jul 2024 08:59:07 +0800 Subject: [PATCH 3/6] GPU (Linux): fix GPU driver detection Regression of e5a04ee8144da438054deaeaf4a9f35637479126 Fix #1084 --- src/detection/gpu/gpu_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 0164f191e..d3e09aebe 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -198,6 +198,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf if (!ffStrbufStartsWithC(buffer, '1')) return "GPU disabled"; } + ffStrbufSubstrBefore(deviceDir, drmDirPathLength); FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString((uint16_t) vendorId)); From 1d837432599eefe2d2557656eec84decc86b03d3 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 11 Jul 2024 09:51:56 +0800 Subject: [PATCH 4/6] GPU (Linux): detect more GPU driver versions --- src/detection/gpu/gpu_linux.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index d3e09aebe..33759a8ca 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -32,29 +32,42 @@ static bool pciDetectDriver(FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer, FF_MAYBE_UNUSED const char* drmKey) { + uint32_t pciDirLength = pciDir->length; ffStrbufAppendS(pciDir, "/driver"); char pathBuf[PATH_MAX]; ssize_t resultLength = readlink(pciDir->chars, pathBuf, sizeof(pathBuf)); - if(resultLength > 0) - { - const char* slash = memrchr(pathBuf, '/', (size_t) resultLength); - if (slash) - { - slash++; - ffStrbufSetNS(&gpu->driver, (uint32_t) (resultLength - (slash - pathBuf)), slash); - } + if(resultLength <= 0) return false; + const char* slash = memrchr(pathBuf, '/', (size_t) resultLength); + if (slash) + { + slash++; + ffStrbufSetNS(&gpu->driver, (uint32_t) (resultLength - (slash - pathBuf)), slash); + } + + if (instance.config.general.detectVersion) + { ffStrbufAppendS(pciDir, "/module/version"); if (ffReadFileBuffer(pciDir->chars, buffer)) { ffStrbufTrimRightSpace(buffer); ffStrbufAppendC(&gpu->driver, ' '); ffStrbufAppend(&gpu->driver, buffer); - return true; + } + else if (ffStrbufEqualS(&gpu->driver, "zx")) + { + ffStrbufSubstrBefore(pciDir, pciDirLength); + ffStrbufAppendS(pciDir, "/zx_info/driver_version"); + if (ffReadFileBuffer(pciDir->chars, buffer)) + { + ffStrbufTrimRightSpace(buffer); + ffStrbufAppendC(&gpu->driver, ' '); + ffStrbufAppend(&gpu->driver, buffer); + } } } - return false; + return true; } static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) From 560e061c254f36a034f12c9156b726b0bd8eddd3 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 11 Jul 2024 10:11:48 +0800 Subject: [PATCH 5/6] CI: upgrade freebsd version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 068825001..bb0c248ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -416,9 +416,9 @@ jobs: with: operating_system: freebsd architecture: x86-64 - cpu_count: 3 + cpu_count: 4 shell: bash - version: '13.2' + version: '14.1' run: | uname -a sudo pkg update From 0707b293265ce60f2f0acb49e66aa2c8a2d70c8d Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 11 Jul 2024 10:19:20 +0800 Subject: [PATCH 6/6] Release: v2.18.1 --- CHANGELOG.md | 5 +++++ CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2062750e6..fb3c71c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ # 2.18.1 +Fix a regression introduced in v2.18.0 + Changes: * `--ts-version` has been renamed to `--detect-version` * `general.detectVersion` in JSON config file +Bugfixes: +* Fix and improve GPU driver detection (#1084, GPU, Linux) + # 2.18.0 Changes: diff --git a/CMakeLists.txt b/CMakeLists.txt index 74a6603eb..fa10b9cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.18.0 + VERSION 2.18.1 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"