From 59c1e3d8c534ec8f0bb58ebd64cb1bc275ec87b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 28 Jan 2024 09:56:36 +0800 Subject: [PATCH 1/6] Platform: detect real path of exe path --- src/util/platform/FFPlatform_unix.c | 20 +++++++++++++------- src/util/platform/FFPlatform_windows.c | 8 ++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index a233c3bc47..255211a344 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -17,17 +17,17 @@ static void getExePath(FFPlatform* platform) { - FFstrbuf* const exePath = &platform->exePath; - ffStrbufEnsureFree(exePath, PATH_MAX); + char exePath[PATH_MAX + 1]; #ifdef __linux__ - ssize_t exePathLen = readlink("/proc/self/exe", exePath->chars, exePath->allocated - 1); + ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1); + exePath[exePathLen] = '\0'; #elif defined(__APPLE__) - int exePathLen = proc_pidpath((int) getpid(), exePath->chars, exePath->allocated); + int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath)); #elif defined(__FreeBSD__) - size_t exePathLen = exePath->allocated; + size_t exePathLen = sizeof(exePath); if(sysctl( (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, - exePath->chars, &exePathLen, + exePath, &exePathLen, NULL, 0 ) < 0) exePathLen = 0; @@ -35,7 +35,13 @@ static void getExePath(FFPlatform* platform) exePathLen--; // remove terminating NUL #endif if (exePathLen > 0) - exePath->length = (uint32_t) exePathLen; + { + ffStrbufEnsureFree(&platform->exePath, PATH_MAX); + if (realpath(platform->exePath.chars, exePath)) + ffStrbufRecalculateLength(&platform->exePath); + else + ffStrbufSetNS(&platform->exePath, (uint32_t) exePathLen, exePath); + } } static void platformPathAddEnv(FFlist* dirs, const char* env) diff --git a/src/util/platform/FFPlatform_windows.c b/src/util/platform/FFPlatform_windows.c index 59696df43a..81e0fd4353 100644 --- a/src/util/platform/FFPlatform_windows.c +++ b/src/util/platform/FFPlatform_windows.c @@ -18,6 +18,14 @@ static void getExePath(FFPlatform* platform) DWORD exePathWLen = GetModuleFileNameW(NULL, exePathW, MAX_PATH); if (exePathWLen == 0 && exePathWLen >= MAX_PATH) return; + FF_AUTO_CLOSE_FD HANDLE hPath = CreateFileW(exePathW, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (hPath != INVALID_HANDLE_VALUE) + { + DWORD len = GetFinalPathNameByHandleW(hPath, exePathW, MAX_PATH, FILE_NAME_OPENED); + if (len > 0 && len < MAX_PATH) + exePathWLen = len; + } + ffStrbufSetNWS(&platform->exePath, exePathWLen, exePathW); if (ffStrbufStartsWithS(&platform->exePath, "\\\\?\\")) ffStrbufSubstrAfter(&platform->exePath, 3); From 3747683f0dfa032d93eb9ea1670193564d9414c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 29 Jan 2024 21:48:33 +0800 Subject: [PATCH 2/6] GPU: add vendor code of QTI & MTK --- src/detection/gpu/gpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/detection/gpu/gpu.c b/src/detection/gpu/gpu.c index 66e11c8056..72b464ac27 100644 --- a/src/detection/gpu/gpu.c +++ b/src/detection/gpu/gpu.c @@ -6,6 +6,8 @@ const char* FF_GPU_VENDOR_NAME_APPLE = "Apple"; const char* FF_GPU_VENDOR_NAME_AMD = "AMD"; const char* FF_GPU_VENDOR_NAME_INTEL = "Intel"; const char* FF_GPU_VENDOR_NAME_NVIDIA = "NVIDIA"; +const char* FF_GPU_VENDOR_NAME_QUALCOMM = "Qualcomm"; +const char* FF_GPU_VENDOR_NAME_MTK = "MTK"; const char* FF_GPU_VENDOR_NAME_VMWARE = "VMware"; const char* FF_GPU_VENDOR_NAME_PARALLEL = "Parallel"; const char* FF_GPU_VENDOR_NAME_MICROSOFT = "Microsoft"; @@ -33,6 +35,10 @@ const char* ffGetGPUVendorString(unsigned vendorId) return FF_GPU_VENDOR_NAME_INTEL; else if(arrayContains((const unsigned[]) {0x0955, 0x10de, 0x12d2}, vendorId, 3)) return FF_GPU_VENDOR_NAME_NVIDIA; + else if(arrayContains((const unsigned[]) {0x5143}, vendorId, 3)) + return FF_GPU_VENDOR_NAME_QUALCOMM; + else if(arrayContains((const unsigned[]) {0x14c3}, vendorId, 3)) + return FF_GPU_VENDOR_NAME_MTK; else if(arrayContains((const unsigned[]) {0x15ad}, vendorId, 1)) return FF_GPU_VENDOR_NAME_VMWARE; else if(arrayContains((const unsigned[]) {0x1af4}, vendorId, 1)) From 53cd1e53781a3a583036672356cf0340835aa775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 23 Jan 2024 21:21:30 +0800 Subject: [PATCH 3/6] DateTime: print timezone info; simplify code --- src/modules/datetime/datetime.c | 100 ++++++++++++-------------------- 1 file changed, 37 insertions(+), 63 deletions(-) diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 77926b27e4..25a685538f 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -9,7 +9,7 @@ #pragma GCC diagnostic ignored "-Wformat" // warning: unknown conversion type character 'F' in format #define FF_DATETIME_DISPLAY_NAME "Date & Time" -#define FF_DATETIME_NUM_FORMAT_ARGS 20 +#define FF_DATETIME_NUM_FORMAT_ARGS 22 typedef struct FFDateTimeResult { @@ -17,23 +17,25 @@ typedef struct FFDateTimeResult uint16_t year; //2022 uint8_t yearShort; //22 uint8_t month; //2 - FFstrbuf monthPretty; //02 - FFstrbuf monthName; //February - FFstrbuf monthNameShort; //Feb + char monthPretty[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //02 + char monthName[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //February + char monthNameShort[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //Feb uint8_t week; //8 - FFstrbuf weekday; //Monday - FFstrbuf weekdayShort; //Mon + char weekday[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //Monday + char weekdayShort[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //Mon uint16_t dayInYear; //52 uint8_t dayInMonth; //21 uint8_t dayInWeek; //1 uint8_t hour; //15 - FFstrbuf hourPretty; //15 + char hourPretty[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //15 uint8_t hour12; //3 - FFstrbuf hour12Pretty; //03 + char hour12Pretty[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //03 uint8_t minute; //18 - FFstrbuf minutePretty; //18 + char minutePretty[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //18 uint8_t second; //37 - FFstrbuf secondPretty; //37 + char secondPretty[FASTFETCH_STRBUF_DEFAULT_ALLOC]; //37 + char offsetFromUtc[FASTFETCH_STRBUF_DEFAULT_ALLOC]; + char timezoneName[FASTFETCH_STRBUF_DEFAULT_ALLOC]; } FFDateTimeResult; void ffPrintDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs) @@ -43,80 +45,50 @@ void ffPrintDateTimeFormat(struct tm* tm, const FFModuleArgs* moduleArgs) result.year = (uint16_t) (tm->tm_year + 1900); result.yearShort = (uint8_t) (result.year % 100); result.month = (uint8_t) (tm->tm_mon + 1); - - ffStrbufInitA(&result.monthPretty, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.monthPretty.length = (uint32_t) strftime(result.monthPretty.chars, ffStrbufGetFree(&result.monthPretty), "%m", tm); - - ffStrbufInitA(&result.monthName, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.monthName.length = (uint32_t) strftime(result.monthName.chars, ffStrbufGetFree(&result.monthName), "%B", tm); - - ffStrbufInitA(&result.monthNameShort, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.monthNameShort.length = (uint32_t) strftime(result.monthNameShort.chars, ffStrbufGetFree(&result.monthNameShort), "%b", tm); - + strftime(result.monthPretty, sizeof(result.monthPretty), "%m", tm); + strftime(result.monthName, sizeof(result.monthName), "%B", tm); + strftime(result.monthNameShort, sizeof(result.monthNameShort), "%b", tm); result.week = (uint8_t) (tm->tm_yday / 7 + 1); - - ffStrbufInitA(&result.weekday, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.weekday.length = (uint32_t) strftime(result.weekday.chars, ffStrbufGetFree(&result.weekday), "%A", tm); - - ffStrbufInitA(&result.weekdayShort, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.weekdayShort.length = (uint32_t) strftime(result.weekdayShort.chars, ffStrbufGetFree(&result.weekdayShort), "%a", tm); - + strftime(result.weekday, sizeof(result.weekday), "%A", tm); + strftime(result.weekdayShort, sizeof(result.weekdayShort), "%a", tm); result.dayInYear = (uint8_t) (tm->tm_yday + 1); result.dayInMonth = (uint8_t) tm->tm_mday; result.dayInWeek = tm->tm_wday == 0 ? 7 : (uint8_t) tm->tm_wday; - result.hour = (uint8_t) tm->tm_hour; - - ffStrbufInitA(&result.hourPretty, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.hourPretty.length = (uint32_t) strftime(result.hourPretty.chars, ffStrbufGetFree(&result.hourPretty), "%H", tm); - + strftime(result.hourPretty, sizeof(result.hourPretty), "%H", tm); result.hour12 = (uint8_t) (result.hour % 12); - - ffStrbufInitA(&result.hour12Pretty, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.hour12Pretty.length = (uint32_t) strftime(result.hour12Pretty.chars, ffStrbufGetFree(&result.hour12Pretty), "%I", tm); - + strftime(result.hour12Pretty, sizeof(result.hour12Pretty), "%I", tm); result.minute = (uint8_t) tm->tm_min; - - ffStrbufInitA(&result.minutePretty, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.minutePretty.length = (uint32_t) strftime(result.minutePretty.chars, ffStrbufGetFree(&result.minutePretty), "%M", tm); - + strftime(result.minutePretty, sizeof(result.minutePretty), "%M", tm); result.second = (uint8_t) tm->tm_sec; - - ffStrbufInitA(&result.secondPretty, FASTFETCH_STRBUF_DEFAULT_ALLOC); - result.secondPretty.length = (uint32_t) strftime(result.secondPretty.chars, ffStrbufGetFree(&result.secondPretty), "%S", tm); + strftime(result.secondPretty, sizeof(result.secondPretty), "%S", tm); + strftime(result.offsetFromUtc, sizeof(result.offsetFromUtc), "%z", tm); + strftime(result.timezoneName, sizeof(result.timezoneName), "%Z", tm); ffPrintFormat(FF_DATETIME_DISPLAY_NAME, 0, moduleArgs, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_UINT16, &result.year}, // 1 {FF_FORMAT_ARG_TYPE_UINT8, &result.yearShort}, // 2 {FF_FORMAT_ARG_TYPE_UINT8, &result.month}, // 3 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.monthPretty}, // 4 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.monthName}, // 5 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.monthNameShort}, // 6 + {FF_FORMAT_ARG_TYPE_STRING, result.monthPretty}, // 4 + {FF_FORMAT_ARG_TYPE_STRING, result.monthName}, // 5 + {FF_FORMAT_ARG_TYPE_STRING, result.monthNameShort}, // 6 {FF_FORMAT_ARG_TYPE_UINT8, &result.week}, // 7 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.weekday}, // 8 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.weekdayShort}, // 9 + {FF_FORMAT_ARG_TYPE_STRING, result.weekday}, // 8 + {FF_FORMAT_ARG_TYPE_STRING, result.weekdayShort}, // 9 {FF_FORMAT_ARG_TYPE_UINT16, &result.dayInYear}, // 10 {FF_FORMAT_ARG_TYPE_UINT8, &result.dayInMonth}, // 11 {FF_FORMAT_ARG_TYPE_UINT8, &result.dayInWeek}, // 12 {FF_FORMAT_ARG_TYPE_UINT8, &result.hour}, // 13 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.hourPretty}, // 14 + {FF_FORMAT_ARG_TYPE_STRING, result.hourPretty}, // 14 {FF_FORMAT_ARG_TYPE_UINT8, &result.hour12}, // 15 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.hour12Pretty}, // 16 + {FF_FORMAT_ARG_TYPE_STRING, result.hour12Pretty}, // 16 {FF_FORMAT_ARG_TYPE_UINT8, &result.minute}, // 17 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.minutePretty}, // 18 + {FF_FORMAT_ARG_TYPE_STRING, result.minutePretty}, // 18 {FF_FORMAT_ARG_TYPE_UINT8, &result.second}, // 19 - {FF_FORMAT_ARG_TYPE_STRBUF, &result.secondPretty} // 20 + {FF_FORMAT_ARG_TYPE_STRING, result.secondPretty}, // 20 + {FF_FORMAT_ARG_TYPE_STRING, result.offsetFromUtc}, // 21 + {FF_FORMAT_ARG_TYPE_STRING, result.timezoneName}, // 22 }); - - ffStrbufDestroy(&result.hour12Pretty); - ffStrbufDestroy(&result.hourPretty); - ffStrbufDestroy(&result.minutePretty); - ffStrbufDestroy(&result.monthName); - ffStrbufDestroy(&result.monthNameShort); - ffStrbufDestroy(&result.monthPretty); - ffStrbufDestroy(&result.secondPretty); - ffStrbufDestroy(&result.weekday); - ffStrbufDestroy(&result.weekdayShort); } void ffPrintDateTime(FFDateTimeOptions* options) @@ -205,7 +177,9 @@ void ffPrintDateTimeHelpFormat(void) "minute", "minute with leading zero", "second", - "second with leading zero" + "second with leading zero", + "offset from UTC in the ISO 8601 format", + "locale-dependent timezone name or abbreviation", }); } From aaa091f23b5d3d97082133eacdabbe2a5b61cd6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Jan 2024 15:22:26 +0800 Subject: [PATCH 4/6] Terminal (Linux): fix segfault --- src/detection/terminalshell/terminalshell_linux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 32ded8311b..1224e14ea1 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -312,7 +312,11 @@ static pid_t getTerminalInfo(FFTerminalResult* result, pid_t pid) static bool getTerminalInfoByPidEnv(FFTerminalResult* result, const char* pidEnv) { - pid_t pid = (pid_t) strtol(getenv(pidEnv), NULL, 10); + const char* envStr = getenv(pidEnv); + if (envStr == NULL) + return false; + + pid_t pid = (pid_t) strtol(envStr, NULL, 10); result->pid = (uint32_t) pid; char name[256]; if (getProcessNameAndPpid(pid, name, (pid_t*) &result->ppid, NULL) == NULL) From ee07755139d4a6912cdd77d18bc96f6e23a7c428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Jan 2024 18:45:56 +0800 Subject: [PATCH 5/6] Release: v2.7.1 --- CHANGELOG.md | 8 ++++++++ CMakeLists.txt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f9813b64c..8887e3c8f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# 2.7.1 + +Features: +* Config presets in app folder now work with symlinks + +Bugfixes: +* Fix a possible segfault when detecting terminal (Terminal, Linux) + # 2.7.0 Features: diff --git a/CMakeLists.txt b/CMakeLists.txt index 7889e3c428..bbe13ddc9a 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.7.0 + VERSION 2.7.1 LANGUAGES C DESCRIPTION "Fast neofetch-like system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" From efe42a2c7de018000653f4706e0bf9d04ef7ec70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 30 Jan 2024 18:54:26 +0800 Subject: [PATCH 6/6] GPU: fix a copy-paste error --- src/detection/gpu/gpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detection/gpu/gpu.c b/src/detection/gpu/gpu.c index 72b464ac27..3f65e17910 100644 --- a/src/detection/gpu/gpu.c +++ b/src/detection/gpu/gpu.c @@ -35,9 +35,9 @@ const char* ffGetGPUVendorString(unsigned vendorId) return FF_GPU_VENDOR_NAME_INTEL; else if(arrayContains((const unsigned[]) {0x0955, 0x10de, 0x12d2}, vendorId, 3)) return FF_GPU_VENDOR_NAME_NVIDIA; - else if(arrayContains((const unsigned[]) {0x5143}, vendorId, 3)) + else if(arrayContains((const unsigned[]) {0x5143}, vendorId, 1)) return FF_GPU_VENDOR_NAME_QUALCOMM; - else if(arrayContains((const unsigned[]) {0x14c3}, vendorId, 3)) + else if(arrayContains((const unsigned[]) {0x14c3}, vendorId, 1)) return FF_GPU_VENDOR_NAME_MTK; else if(arrayContains((const unsigned[]) {0x15ad}, vendorId, 1)) return FF_GPU_VENDOR_NAME_VMWARE;