From 90359d227e43e76c6717f78dd0e7276ba38693f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 28 Dec 2022 17:18:08 +0800 Subject: [PATCH] Global: don't require sysinfo.h globally ... which is Linux specific --- CMakeLists.txt | 6 ------ src/common/init.c | 4 ---- src/detection/cpu/cpu_linux.c | 10 +++------- src/detection/processes/processes.h | 2 +- src/detection/processes/processes_bsd.c | 4 +--- src/detection/processes/processes_linux.c | 15 +++++++-------- src/detection/processes/processes_windows.cpp | 6 ++---- src/detection/uptime/uptime.h | 2 +- src/detection/uptime/uptime_bsd.c | 3 +-- src/detection/uptime/uptime_linux.c | 12 ++++++------ src/detection/uptime/uptime_windows.c | 3 +-- src/fastfetch.h | 8 -------- src/modules/processes.c | 2 +- src/modules/uptime.c | 2 +- 14 files changed, 25 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 866e5d0aa..7f65fca70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -497,12 +497,6 @@ add_library(libfastfetch OBJECT target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) -CHECK_INCLUDE_FILE("sys/sysinfo.h" HAVE_SYSINFO_H) -if(HAVE_SYSINFO_H) - # needs to be public, because changes fastfech.h ABI - target_compile_definitions(libfastfetch PUBLIC FF_HAVE_SYSINFO_H) -endif() - CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX_H) if(HAVE_UTMPX_H) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_UTMPX_H) diff --git a/src/common/init.c b/src/common/init.c index 88ad09a66..d36c6ef5c 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -112,10 +112,6 @@ static void initState(FFstate* state) #endif uname(&state->utsname); - #if FF_HAVE_SYSINFO_H - sysinfo(&state->sysinfo); - #endif - initConfigDirs(state); } diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index ee68f1e6f..11b5ec965 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -3,6 +3,7 @@ #include "common/properties.h" #include "detection/temps/temps_linux.h" +#include #include #include @@ -99,13 +100,8 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu) cpu->coresPhysical = ffStrbufToUInt16(&physicalCoresBuffer, 1); - #ifdef FF_HAVE_SYSINFO_H - cpu->coresLogical = (uint16_t) get_nprocs_conf(); - cpu->coresOnline = (uint16_t) get_nprocs(); - #else - cpu->coresLogical = 1; - cpu->coresOnline = 1; - #endif + cpu->coresLogical = (uint16_t) get_nprocs_conf(); + cpu->coresOnline = (uint16_t) get_nprocs(); #define BP "/sys/devices/system/cpu/cpufreq/policy0/" if(ffFileExists(BP, S_IFDIR)) diff --git a/src/detection/processes/processes.h b/src/detection/processes/processes.h index bfc4bce6c..74b29e1bb 100644 --- a/src/detection/processes/processes.h +++ b/src/detection/processes/processes.h @@ -5,6 +5,6 @@ #include "fastfetch.h" -uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error); +uint32_t ffDetectProcesses(FFstrbuf* error); #endif diff --git a/src/detection/processes/processes_bsd.c b/src/detection/processes/processes_bsd.c index a09b05a96..36bb14773 100644 --- a/src/detection/processes/processes_bsd.c +++ b/src/detection/processes/processes_bsd.c @@ -6,10 +6,8 @@ #include #endif -uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error) +uint32_t ffDetectProcesses(FFstrbuf* error) { - FF_UNUSED(instance); - int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; size_t length; diff --git a/src/detection/processes/processes_linux.c b/src/detection/processes/processes_linux.c index da197b03e..91871f867 100644 --- a/src/detection/processes/processes_linux.c +++ b/src/detection/processes/processes_linux.c @@ -1,12 +1,11 @@ #include "processes.h" -uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error) +#include + +uint32_t ffDetectProcesses(FFstrbuf* error) { - #if FF_HAVE_SYSINFO_H - FF_UNUSED(error); - return (uint32_t) instance->state.sysinfo.procs; - #else - ffStrbufAppendS(error, "Unimplemented"); - return 0; - #endif + struct sysinfo info; + if(sysinfo(&info) != 0) + ffStrbufAppendS(error, "sysinfo() failed"); + return (uint32_t) info.procs; } diff --git a/src/detection/processes/processes_windows.cpp b/src/detection/processes/processes_windows.cpp index 860ee8998..69a494629 100644 --- a/src/detection/processes/processes_windows.cpp +++ b/src/detection/processes/processes_windows.cpp @@ -8,10 +8,8 @@ extern "C" { #include #include -uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error) +uint32_t ffDetectProcesses(FFstrbuf* error) { - FF_UNUSED(instance); - ULONG size = 0; if(NtQuerySystemInformation(SystemProcessInformation, nullptr, 0, &size) != STATUS_INFO_LENGTH_MISMATCH) { @@ -44,7 +42,7 @@ uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error) #include "util/windows/wmi.hpp" -uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error) +uint32_t ffDetectProcesses(FFstrbuf* error) { FFWmiQuery query(L"SELECT NumberOfProcesses FROM Win32_OperatingSystem", error); if(!query) diff --git a/src/detection/uptime/uptime.h b/src/detection/uptime/uptime.h index a44d4cecc..6a032b47c 100644 --- a/src/detection/uptime/uptime.h +++ b/src/detection/uptime/uptime.h @@ -5,6 +5,6 @@ #include "fastfetch.h" -uint64_t ffDetectUptime(const FFinstance* instance); +uint64_t ffDetectUptime(); #endif diff --git a/src/detection/uptime/uptime_bsd.c b/src/detection/uptime/uptime_bsd.c index e21eb4183..375065c35 100644 --- a/src/detection/uptime/uptime_bsd.c +++ b/src/detection/uptime/uptime_bsd.c @@ -4,9 +4,8 @@ #include #include -uint64_t ffDetectUptime(const FFinstance* instance) +uint64_t ffDetectUptime() { - FF_UNUSED(instance) struct timeval bootTime; size_t bootTimeSize = sizeof(bootTime); if(sysctl( diff --git a/src/detection/uptime/uptime_linux.c b/src/detection/uptime/uptime_linux.c index e58fa6505..cf4860771 100644 --- a/src/detection/uptime/uptime_linux.c +++ b/src/detection/uptime/uptime_linux.c @@ -1,11 +1,11 @@ #include "uptime.h" -uint64_t ffDetectUptime(const FFinstance* instance) +#include + +uint64_t ffDetectUptime() { - #if FF_HAVE_SYSINFO_H - return (uint64_t) instance->state.sysinfo.uptime; - #else - FF_UNUSED(instance) + struct sysinfo info; + if(sysinfo(&info) != 0) return 0; - #endif + return (uint32_t) info.uptime; } diff --git a/src/detection/uptime/uptime_windows.c b/src/detection/uptime/uptime_windows.c index 8909ad596..9f2dab02a 100644 --- a/src/detection/uptime/uptime_windows.c +++ b/src/detection/uptime/uptime_windows.c @@ -3,8 +3,7 @@ #define WIN32_LEAN_AND_MEAN #include -uint64_t ffDetectUptime(const FFinstance* instance) +uint64_t ffDetectUptime() { - FF_UNUSED(instance) return GetTickCount64() / 1000; } diff --git a/src/fastfetch.h b/src/fastfetch.h index a33dce50a..757e5f083 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -16,10 +16,6 @@ #include "util/windows/utsname.h" #endif -#if FF_HAVE_SYSINFO_H - #include -#endif - #include "util/FFstrbuf.h" #include "util/FFlist.h" @@ -212,10 +208,6 @@ typedef struct FFstate struct passwd* passwd; struct utsname utsname; - #if FF_HAVE_SYSINFO_H - struct sysinfo sysinfo; - #endif - FFlist configDirs; } FFstate; diff --git a/src/modules/processes.c b/src/modules/processes.c index fa71a7611..5157f79b6 100644 --- a/src/modules/processes.c +++ b/src/modules/processes.c @@ -9,7 +9,7 @@ void ffPrintProcesses(FFinstance* instance) { FFstrbuf error; ffStrbufInit(&error); - uint32_t numProcesses = ffDetectProcesses(instance, &error); + uint32_t numProcesses = ffDetectProcesses(&error); if(error.length > 0) { diff --git a/src/modules/uptime.c b/src/modules/uptime.c index cf371778d..48d2b4f4a 100644 --- a/src/modules/uptime.c +++ b/src/modules/uptime.c @@ -7,7 +7,7 @@ void ffPrintUptime(FFinstance* instance) { - uint64_t uptime = ffDetectUptime(instance); + uint64_t uptime = ffDetectUptime(); if(uptime == 0) {