From f0cee064bde3fb9d22923d43996f02d1f114c694 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Mon, 19 Sep 2022 23:16:43 +0200 Subject: [PATCH] Basic BSD support --- CMakeLists.txt | 1 - src/common/sysctl.c | 6 +++--- src/common/sysctl.h | 1 + src/detection/cpu/cpu_bsd.c | 20 +++++++++++++------- src/detection/gpu/gpu_linux.c | 6 ++++-- src/detection/memory/memory_bsd.c | 4 +++- src/modules/cpu.c | 2 +- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de4dca54e..ab859f304 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,7 +259,6 @@ if(LINUX OR BSD) src/detection/host/host_linux.c src/detection/os/os_linux.c src/detection/gpu/gpu_linux.c - src/detection/memory/memory_linux.c src/detection/battery/battery_linux.c src/detection/displayserver/linux/displayserver_linux.c src/detection/displayserver/linux/wayland.c diff --git a/src/common/sysctl.c b/src/common/sysctl.c index 526323458..30e92383a 100644 --- a/src/common/sysctl.c +++ b/src/common/sysctl.c @@ -5,13 +5,13 @@ void ffSysctlGetString(const char* propName, FFstrbuf* result) { size_t neededLength; - if(sysctlbyname(propName, NULL, &neededLength, NULL, 0) != 0 || neededLength == 0) + if(sysctlbyname(propName, NULL, &neededLength, NULL, 0) != 0 || neededLength == 1) //neededLength is 1 for empty strings, because of the null terminator return; - ffStrbufEnsureFree(result, (uint32_t) neededLength); + ffStrbufEnsureFree(result, (uint32_t) neededLength - 1); if(sysctlbyname(propName, result->chars + result->length, &neededLength, NULL, 0) == 0) - result->length += (uint32_t) neededLength; + result->length += (uint32_t) neededLength - 1; result->chars[result->length] = '\0'; } diff --git a/src/common/sysctl.h b/src/common/sysctl.h index ebaab050d..91e4ad8b6 100644 --- a/src/common/sysctl.h +++ b/src/common/sysctl.h @@ -4,6 +4,7 @@ #define FF_INCLUDED_common_sysctl #include "fastfetch.h" +#include #include void ffSysctlGetString(const char* propName, FFstrbuf* result); diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 40b9d806d..edd8f1803 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -1,13 +1,19 @@ #include "cpu.h" +#include "common/sysctl.h" void ffDetectCPUImpl(FFCPUResult* cpu) { - ffStrbufInit(&cpu->vendor); + ffStrbufInitA(&cpu->vendor, 0); + ffStrbufInit(&cpu->name); - cpu->coresPhysical = 1; - cpu->coresLogical = 1; - cpu->coresOnline = 1; - frequencyMin = 0.0; - frequencyMax = 0.0; - temperature = FF_CPU_TEMP_UNSET; + ffSysctlGetString("hw.model", &cpu->name); + + cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1); + cpu->coresLogical = cpu->coresPhysical; + cpu->coresOnline = cpu->coresPhysical; + + cpu->frequencyMin = ffSysctlGetInt("hw.clockrate", 0) / 1000.0; + cpu->frequencyMax = cpu->frequencyMin; + + cpu->temperature = FF_CPU_TEMP_UNSET; } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 3559f311b..cf8427025 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -234,9 +234,11 @@ static const char* pciDetectGPUs(const FFinstance* instance, FFlist* gpus) #endif -const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) +void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) { #ifdef FF_HAVE_LIBPCI - return pciDetectGPUs(instance, gpus); + pciDetectGPUs(instance, gpus); + #else + FF_UNUSED(gpus, instance); #endif } diff --git a/src/detection/memory/memory_bsd.c b/src/detection/memory/memory_bsd.c index bbff918b4..ab27e26a9 100644 --- a/src/detection/memory/memory_bsd.c +++ b/src/detection/memory/memory_bsd.c @@ -1,9 +1,11 @@ #include "memory.h" +#include "common/sysctl.h" void ffDetectMemoryImpl(FFMemoryResult* memory) { - memory->ram.bytesTotal = 0; + memory->ram.bytesTotal = (uint64_t) ffSysctlGetInt64("hw.physmem", 0); memory->ram.bytesUsed = 0; + memory->swap.bytesTotal = 0; memory->swap.bytesUsed = 0; } diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 6eb6293aa..773b79d55 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -13,7 +13,7 @@ void ffPrintCPU(FFinstance* instance) const FFCPUResult* cpu = ffDetectCPU(); - if(cpu->vendor.length == 0 && cpu->name.length == 0 && cpu->coresOnline == 0) + if(cpu->vendor.length == 0 && cpu->name.length == 0 && cpu->coresOnline <= 1) { ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "No CPU detected"); return;