Skip to content

Commit 99f6b7a

Browse files
authored
Merge branch 'fastfetch-cli:dev' into fix-packages-warning
2 parents a2b5ea8 + 2edc41d commit 99f6b7a

14 files changed

Lines changed: 176 additions & 120 deletions

File tree

.github/workflows/build-openbsd-amd64.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
architecture: x86-64
2121
cpu_count: 4
2222
shell: bash
23-
version: '7.8'
23+
version: '7.9'
2424
environment_variables: 'CMAKE_BUILD_TYPE'
2525
run: |
2626
uname -a
2727
sudo pkg_add -u
28-
sudo pkg_add -r llvm-21.1.2p0 cmake git wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 imagemagick chafa lua-5.4.7 # pkg-config is preinstalled
28+
sudo pkg_add -r llvm-21.1.8p4 cmake git wayland vulkan-headers vulkan-loader glib2 dconf dbus sqlite3 imagemagick chafa lua-5.4.8p0 # pkg-config is preinstalled
2929
CC=clang-21 cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DENABLE_EMBEDDED_PCIIDS=On -DENABLE_EMBEDDED_AMDGPUIDS=On .
3030
cmake --build . --target package --verbose -j4
3131
./fastfetch --list-features

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
build/
2-
.vs/
3-
.vscode/
4-
.cache/
5-
.kdev4/
1+
/build/
2+
/build_*/
3+
/build-*/
4+
/.vs/
5+
/.vscode/
6+
/.cache/
7+
/.kdev4/
68
.DS_Store
79
cscope.*
810
tags

src/common/attributes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
#define FF_A_PACKED __attribute__((__packed__))
1818
#define FF_A_WEAK_IMPORT __attribute__((__weak_import__))
1919
#define FF_A_ALWAYS_INLINE __attribute__((__always_inline__))
20+
#define FF_A_COLD __attribute__((__cold__))

src/common/impl/FFPlatform_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void getExePath(FFPlatform* platform) {
3030
char exePath[PATH_MAX];
3131
#if defined(__linux__) || defined(__GNU__)
3232
ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
33-
if (exePathLen >= 0) {
33+
if (exePathLen > 0) {
3434
exePath[exePathLen] = '\0';
3535
}
3636
#elif defined(__APPLE__)
@@ -128,7 +128,7 @@ static void getExePath(FFPlatform* platform) {
128128
}
129129
#elif defined(__sun)
130130
ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1);
131-
if (exePathLen >= 0) {
131+
if (exePathLen > 0) {
132132
exePath[exePathLen] = '\0';
133133
}
134134
#elif defined(__HAIKU__)

src/common/impl/init.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,30 @@ static void defaultConfig(void) {
4646
ffOptionsInitDisplay(&instance.config.display);
4747
}
4848

49+
#ifdef _WIN32
50+
static volatile UINT oldCp = CP_UTF8;
51+
void resetConsoleCP(void) {
52+
if (oldCp != CP_UTF8) {
53+
SetConsoleOutputCP(oldCp);
54+
}
55+
}
56+
#endif
57+
4958
void ffInitInstance(void) {
5059
#ifdef _WIN32
5160
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?source=recommendat>
5261
setlocale(LC_ALL, ".UTF8");
62+
63+
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
64+
DWORD mode = 0;
65+
if (GetConsoleMode(hStdout, &mode)) {
66+
SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
67+
oldCp = GetConsoleOutputCP();
68+
if (oldCp != CP_UTF8) {
69+
SetConsoleOutputCP(CP_UTF8);
70+
atexit(resetConsoleCP);
71+
}
72+
}
5373
#else
5474
// Never use `setlocale(LC_ALL, "")`
5575
setlocale(LC_TIME, "");
@@ -61,9 +81,6 @@ void ffInitInstance(void) {
6181

6282
static volatile bool ffDisableLinewrap = false;
6383
static volatile bool ffHideCursor = false;
64-
#ifdef _WIN32
65-
static volatile UINT oldCp = CP_UTF8;
66-
#endif
6784

6885
static void resetConsole(void) {
6986
if (ffDisableLinewrap) {
@@ -80,10 +97,6 @@ static void resetConsole(void) {
8097

8198
#if defined(_WIN32)
8299
fflush(stdout);
83-
84-
if (oldCp != CP_UTF8) {
85-
SetConsoleOutputCP(oldCp);
86-
}
87100
#endif
88101
}
89102

@@ -111,15 +124,6 @@ void ffStart(void) {
111124
setvbuf(stdout, NULL, _IOFBF, 4096);
112125
}
113126
SetConsoleCtrlHandler(consoleHandler, TRUE);
114-
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
115-
DWORD mode = 0;
116-
if (GetConsoleMode(hStdout, &mode)) {
117-
SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
118-
oldCp = GetConsoleOutputCP();
119-
if (oldCp != CP_UTF8) {
120-
SetConsoleOutputCP(CP_UTF8);
121-
}
122-
}
123127
#else
124128
if (instance.config.display.noBuffer) {
125129
setvbuf(stdout, NULL, _IONBF, 0);

src/common/impl/processing_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
269269
}
270270
}
271271

272-
if (exePath->length == 0) {
272+
if (exePath->length == 0 && access(filePath, X_OK) == 0) {
273273
ffStrbufSetS(exePath, filePath);
274274
}
275275
}

src/detection/cpu/cpu_linux.c

Lines changed: 35 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -619,19 +619,14 @@ static const char* parseCpuInfo(
619619
return NULL;
620620
}
621621

622-
static uint32_t getFrequency(FFstrbuf* basePath, const char* cpuinfoFileName, const char* scalingFileName, FFstrbuf* buffer) {
623-
uint32_t baseLen = basePath->length;
624-
ffStrbufAppendS(basePath, cpuinfoFileName);
625-
bool ok = ffReadFileBuffer(basePath->chars, buffer);
626-
ffStrbufSubstrBefore(basePath, baseLen);
622+
static uint32_t getFrequency(int policyFd, const char* cpuinfoFileName, const char* scalingFileName, FFstrbuf* buffer) {
623+
bool ok = ffReadFileBufferRelative(policyFd, cpuinfoFileName, buffer);
627624
if (ok) {
628625
return (uint32_t) (ffStrbufToUInt(buffer, 0) / 1000);
629626
}
630627

631628
if (scalingFileName) {
632-
ffStrbufAppendS(basePath, scalingFileName);
633-
ok = ffReadFileBuffer(basePath->chars, buffer);
634-
ffStrbufSubstrBefore(basePath, baseLen);
629+
ok = ffReadFileBufferRelative(policyFd, scalingFileName, buffer);
635630
if (ok) {
636631
return (uint32_t) (ffStrbufToUInt(buffer, 0) / 1000);
637632
}
@@ -640,55 +635,38 @@ static uint32_t getFrequency(FFstrbuf* basePath, const char* cpuinfoFileName, co
640635
return 0;
641636
}
642637

643-
static uint8_t getNumCores(FFstrbuf* basePath, FFstrbuf* buffer) {
644-
uint32_t baseLen = basePath->length;
645-
ffStrbufAppendS(basePath, "/affected_cpus");
646-
bool ok = ffReadFileBuffer(basePath->chars, buffer);
647-
ffStrbufSubstrBefore(basePath, baseLen);
648-
if (ok) {
649-
return (uint8_t) (ffStrbufCountC(buffer, ' ') + 1);
650-
}
651-
652-
ffStrbufAppendS(basePath, "/related_cpus");
653-
ok = ffReadFileBuffer(basePath->chars, buffer);
654-
ffStrbufSubstrBefore(basePath, baseLen);
655-
if (ok) {
656-
return (uint8_t) (ffStrbufCountC(buffer, ' ') + 1);
657-
}
658-
659-
return 0;
660-
}
661-
662638
static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options) {
663-
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/devices/system/cpu/cpufreq/");
664-
FF_AUTO_CLOSE_DIR DIR* dir = opendir(path.chars);
639+
const char* basePath = "/sys/devices/system/cpu/cpufreq/";
640+
FF_AUTO_CLOSE_DIR DIR* dir = opendir(basePath);
665641
if (!dir) {
666642
return false;
667643
}
644+
int freqFd = dirfd(dir);
668645

669646
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
670-
uint32_t baseLen = path.length;
671647

672648
struct dirent* entry;
673649
while ((entry = readdir(dir)) != NULL) {
674650
if (ffStrStartsWith(entry->d_name, "policy") && ffCharIsDigit(entry->d_name[strlen("policy")])) {
675-
ffStrbufAppendS(&path, entry->d_name);
651+
FF_AUTO_CLOSE_FD int policyFd = openat(freqFd, entry->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_PATH);
652+
if (policyFd < 0) {
653+
continue;
654+
}
676655

677-
uint32_t fmax = getFrequency(&path, "/cpuinfo_max_freq", "/scaling_max_freq", &buffer);
656+
uint32_t fmax = getFrequency(policyFd, "cpuinfo_max_freq", "scaling_max_freq", &buffer);
678657
if (fmax == 0) {
679658
continue;
680659
}
681660

682661
if (cpu->frequencyMax >= fmax) {
683662
if (!options->showPeCoreCount) {
684-
ffStrbufSubstrBefore(&path, baseLen);
685663
continue;
686664
}
687665
} else {
688666
cpu->frequencyMax = fmax;
689667
}
690668

691-
uint32_t fbase = getFrequency(&path, "/base_frequency", NULL, &buffer);
669+
uint32_t fbase = getFrequency(policyFd, "base_frequency", NULL, &buffer);
692670
if (fbase > 0) {
693671
cpu->frequencyBase = cpu->frequencyBase > fbase ? cpu->frequencyBase : fbase;
694672
}
@@ -702,9 +680,10 @@ static bool detectFrequency(FFCPUResult* cpu, const FFCPUOptions* options) {
702680
if (cpu->coreTypes[ifreq].freq == 0) {
703681
cpu->coreTypes[ifreq].freq = freq;
704682
}
705-
cpu->coreTypes[ifreq].count += getNumCores(&path, &buffer);
683+
if (ffReadFileBufferRelative(policyFd, "affected_cpus", &buffer)) {
684+
cpu->coreTypes[ifreq].count += ffStrbufCountC(&buffer, ' ') + 1;
685+
}
706686
}
707-
ffStrbufSubstrBefore(&path, baseLen);
708687
}
709688
}
710689
return true;
@@ -773,6 +752,7 @@ static const char* detectPhysicalCores(FFCPUResult* cpu) {
773752

774753
FF_AUTO_CLOSE_DIR DIR* dir = fdopendir(dfd);
775754
if (!dir) {
755+
close(dfd);
776756
return "fdopendir(dfd) failed";
777757
}
778758

@@ -785,7 +765,7 @@ static const char* detectPhysicalCores(FFCPUResult* cpu) {
785765
continue;
786766
}
787767

788-
FF_AUTO_CLOSE_FD int cpuxfd = openat(dirfd(dir), entry->d_name, O_RDONLY | O_DIRECTORY);
768+
FF_AUTO_CLOSE_FD int cpuxfd = openat(dirfd(dir), entry->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
789769
if (cpuxfd < 0) {
790770
continue;
791771
}
@@ -801,42 +781,36 @@ static const char* detectPhysicalCores(FFCPUResult* cpu) {
801781
unsigned long long id = strtoul(buf, NULL, 10);
802782
if (__builtin_expect(id > 64, false)) { // Do 129-socket boards exist?
803783
pkgHigh |= 1ULL << (id - 64);
804-
} else {
784+
} else if (__builtin_expect(id <= 64, true)) {
805785
pkgLow |= 1ULL << id;
806786
}
807787
}
808788

809789
// Check if the directory contains a file named "topology/core_cpus_list"
810-
// that lists the physical cores in the package.
790+
// that lists the logical cores in the same physical core.
811791

812792
len = ffReadFileDataRelative(cpuxfd, "topology/core_cpus_list", sizeof(buf) - 1, buf);
813793
if (len > 0) {
814-
buf[len] = '\0'; // low-high or low
815-
816-
for (const char* p = buf; *p;) {
817-
char* pend;
818-
uint32_t coreId = (uint32_t) strtoul(p, &pend, 10);
819-
if (pend == p) {
820-
break;
821-
}
794+
buf[len] = '\0'; // low[-high, low-high, ...]
822795

823-
bool found = false;
824-
FF_LIST_FOR_EACH (uint32_t, id, cpuList) {
825-
if (*id == coreId) {
826-
// This core is already counted
827-
found = true;
828-
break;
829-
}
830-
}
831-
if (!found) {
832-
*FF_LIST_ADD(uint32_t, cpuList) = coreId;
833-
}
796+
char* pend;
797+
// We assume that the different physical cores exposes different logical core ids,
798+
// so that the first `low` is always different between different physical cores.
799+
uint32_t coreId = (uint32_t) strtoul(buf, &pend, 10);
800+
if (pend == buf) {
801+
break;
802+
}
834803

835-
p = strchr(pend, ',');
836-
if (!p) {
804+
bool found = false;
805+
FF_LIST_FOR_EACH (uint32_t, id, cpuList) {
806+
if (*id == coreId) {
807+
// This core is already counted
808+
found = true;
837809
break;
838810
}
839-
++p;
811+
}
812+
if (!found) {
813+
*FF_LIST_ADD(uint32_t, cpuList) = coreId;
840814
}
841815
}
842816
}

0 commit comments

Comments
 (0)