SunOS: support CPU & packages detection

This commit is contained in:
Carter Li
2024-06-17 01:01:21 +08:00
parent d727547b1c
commit 1841e1a99d
3 changed files with 56 additions and 2 deletions
+3 -2
View File
@@ -748,7 +748,7 @@ elseif(SunOS)
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_nosupport.c
src/detection/cpu/cpu_sunos.c
src/detection/cpucache/cpucache_nosupport.c
src/detection/cpuusage/cpuusage_nosupport.c
src/detection/cursor/cursor_linux.c
@@ -786,7 +786,7 @@ elseif(SunOS)
src/detection/netio/netio_nosupport.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_sunos.c
src/detection/packages/packages_nosupport.c
src/detection/packages/packages_sunos.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_linux.c
src/detection/gtk_qt/qt.c
@@ -1128,6 +1128,7 @@ elseif(SunOS)
target_link_libraries(libfastfetch
PRIVATE "m"
PRIVATE "socket"
PRIVATE "kstat"
)
elseif(ANDROID)
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
+38
View File
@@ -0,0 +1,38 @@
#include "cpu.h"
#include <kstat.h>
const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFCPUOptions* options, FFCPUResult* cpu)
{
kstat_ctl_t* kc = kstat_open();
if (!kc)
return "kstat_open() failed";
kstat_t* ks = kstat_lookup(kc, "cpu_info", -1, NULL);
if (!ks)
return "kstat_lookup() failed";
if (ks->ks_type != KSTAT_TYPE_NAMED)
return "Invalid ks_type found";
if (kstat_read(kc, ks, NULL) < 0)
return "kstat_read() failed";
{
kstat_named_t* kn = kstat_data_lookup(ks, "brand");
ffStrbufSetNS(&cpu->name, KSTAT_NAMED_STR_BUFLEN(kn), KSTAT_NAMED_STR_PTR(kn));
}
{
kstat_named_t* kn = kstat_data_lookup(ks, "vendor_id");
ffStrbufSetNS(&cpu->vendor, KSTAT_NAMED_STR_BUFLEN(kn), KSTAT_NAMED_STR_PTR(kn));
}
{
kstat_named_t* kn = kstat_data_lookup(ks, "clock_MHz");
cpu->frequencyBase = kn->value.i32 / 1000.;
}
cpu->coresOnline = 1;
while ((ks = kstat_lookup(kc, "cpu_info", ks->ks_instance + 1, NULL)))
cpu->coresOnline++;
return NULL;
}
+15
View File
@@ -0,0 +1,15 @@
#include "packages.h"
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT))
{
yyjson_doc* doc = yyjson_read_file(FASTFETCH_TARGET_DIR_ROOT "/var/pkg/state/installed/catalog.attrs", YYJSON_READ_NOFLAG, NULL, NULL);
if (doc)
{
yyjson_val* packageCount = yyjson_obj_get(yyjson_doc_get_root(doc), "package-count");
if (packageCount)
result->pkg = (uint32_t) yyjson_get_uint(packageCount);
}
}
}