OpenBSD: init platform support

This commit is contained in:
Carter Li
2024-10-04 15:58:17 +08:00
parent d06f9a1509
commit a32d9d788c
33 changed files with 459 additions and 55 deletions
+124 -29
View File
@@ -18,6 +18,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
set(FreeBSD TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
set(OpenBSD TRUE CACHE BOOL "..." FORCE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
set(SunOS TRUE CACHE BOOL "..." FORCE)
elseif(NOT APPLE AND NOT WIN32)
@@ -44,30 +46,30 @@ include(CheckIncludeFile)
include(CMakeDependentOption)
cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR WIN32 OR ANDROID OR SunOS" OFF)
cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD" OFF)
cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR WIN32 OR ANDROID OR SunOS" OFF)
cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD" OFF)
cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR SunOS" OFF)
cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_XFCONF "Enable libxfconf-0" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR APPLE OR WIN32 OR SunOS" OFF)
cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR APPLE OR SunOS" OFF)
cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR FreeBSD OR OpenBSD OR APPLE OR WIN32 OR SunOS" OFF)
cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR FreeBSD OR OpenBSD OR APPLE OR SunOS" OFF)
cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF)
cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF)
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR WIN32 OR SunOS" OFF)
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR WIN32 OR ANDROID OR SunOS" OFF)
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR WIN32 OR SunOS" OFF)
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR FreeBSD OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR WIN32 OR ANDROID OR SunOS" OFF)
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR SunOS" OFF)
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR OpenBSD OR SunOS" OFF)
cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID" OFF)
@@ -653,6 +655,85 @@ elseif(FreeBSD)
src/util/platform/FFPlatform_unix.c
src/util/binary_linux.c
)
elseif(OpenBSD)
list(APPEND LIBFASTFETCH_SRC
src/common/dbus.c
src/common/io/io_unix.c
src/common/netif/netif_bsd.c
src/common/networking_linux.c
src/common/processing_linux.c
src/common/sysctl.c
src/detection/battery/battery_nosupport.c
src/detection/bios/bios_nosupport.c
src/detection/bluetooth/bluetooth_nosupport.c
src/detection/bluetoothradio/bluetoothradio_nosupport.c
src/detection/board/board_nosupport.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/btrfs/btrfs_nosupport.c
src/detection/chassis/chassis_nosupport.c
src/detection/cpu/cpu_obsd.c
src/detection/cpucache/cpucache_nosupport.c
src/detection/cpuusage/cpuusage_bsd.c
src/detection/cursor/cursor_linux.c
src/detection/disk/disk_bsd.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_nosupport.c
src/detection/physicalmemory/physicalmemory_nosupport.c
src/detection/diskio/diskio_nosupport.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/drm.c
src/detection/displayserver/linux/wayland/wayland.c
src/detection/displayserver/linux/wayland/global-output.c
src/detection/displayserver/linux/wayland/zwlr-output.c
src/detection/displayserver/linux/wayland/kde-output.c
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
src/detection/displayserver/linux/wayland/kde-output-order-v1-protocol.c
src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
src/detection/displayserver/linux/wmde.c
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_nosupport.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_obsd.c
src/detection/lm/lm_nosupport.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/libc/libc_nosupport.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_linux.c
src/detection/memory/memory_obsd.c
src/detection/netio/netio_nosupport.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_obsd.c
src/detection/packages/packages_obsd.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_obsd.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_linux.c
src/detection/swap/swap_obsd.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/terminalshell/terminalshell_linux.c
src/detection/terminalsize/terminalsize_linux.c
src/detection/theme/theme_linux.c
src/detection/tpm/tpm_nosupport.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_nosupport.c
src/detection/wallpaper/wallpaper_linux.c
src/detection/wifi/wifi_nosupport.c
src/detection/wm/wm_nosupport.c
src/detection/de/de_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/camera/camera_nosupport.c
src/detection/zpool/zpool_nosupport.c
src/util/platform/FFPlatform_unix.c
src/util/binary_linux.c
)
elseif(APPLE)
list(APPEND LIBFASTFETCH_SRC
src/common/io/io_unix.c
@@ -945,13 +1026,16 @@ if(FreeBSD AND EXISTS "/usr/local/bin/objdump")
endif()
endif()
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__=1 _FILE_OFFSET_BITS=64)
if(WIN32)
target_compile_definitions(libfastfetch PUBLIC WIN32_LEAN_AND_MEAN=1)
if(LINUX)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__=1 _FILE_OFFSET_BITS=64)
elseif(WIN32)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN=1 _WIN32_WINNT=0x0A00)
elseif(APPLE)
target_compile_definitions(libfastfetch PUBLIC _DARWIN_C_SOURCE)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE)
elseif(OpenBSD)
target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE)
elseif(SunOS)
target_compile_definitions(libfastfetch PUBLIC __EXTENSIONS__ _POSIX_C_SOURCE=1)
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE)
endif()
if(HAVE_STATX)
@@ -1097,10 +1181,17 @@ ff_lib_enable(EGL
"egl"
"EGL"
)
ff_lib_enable(GLX
"glx"
"GLX"
)
if(NOT OpenBSD)
ff_lib_enable(GLX
"glx"
"GLX"
)
else()
ff_lib_enable(GLX
"gl"
"GL"
)
endif()
ff_lib_enable(OSMESA
"osmesa"
"OSMesa"
@@ -1194,7 +1285,6 @@ elseif(APPLE)
PRIVATE "-weak_framework Apple80211"
)
elseif(WIN32)
target_compile_definitions(libfastfetch PRIVATE -D_WIN32_WINNT=0x0A00)
target_link_libraries(libfastfetch
PRIVATE "dwmapi"
PRIVATE "gdi32"
@@ -1215,6 +1305,11 @@ elseif(FreeBSD)
PRIVATE "usbhid"
PRIVATE "geom"
)
elseif(OpenBSD)
target_link_libraries(libfastfetch
PRIVATE "m"
PRIVATE "kvm"
)
elseif(SunOS)
target_link_libraries(libfastfetch
PRIVATE "m"
+1 -1
View File
@@ -245,7 +245,7 @@ void ffListFeatures(void)
#if FF_HAVE_DDCUTIL
"libddcutil\n"
#endif
#if FF_HAVE_ELF || __sun || __FreeBSD__
#if FF_HAVE_ELF || __sun || __FreeBSD__ || __OpenBSD__
"libelf\n"
#endif
#if FF_HAVE_LIBZFS
+6
View File
@@ -191,14 +191,20 @@ const char* ffGetTerminalResponse(const char* request, int nParams, const char*
ssize_t nRead = read(ftty, buffer + bytesRead, sizeof(buffer) - bytesRead - 1);
if (nRead <= 0)
{
va_end(args);
return "read(STDIN_FILENO, buffer, sizeof(buffer) - 1) failed";
}
bytesRead += (size_t) nRead;
buffer[bytesRead] = '\0';
int ret = vsscanf(buffer, format, args);
if (ret <= 0)
{
va_end(args);
return "vsscanf(buffer, format, args) failed";
}
if (ret >= nParams)
break;
}
+33
View File
@@ -22,6 +22,10 @@
#include <libproc.h>
#elif defined(__sun)
#include <procfs.h>
#elif defined(__OpenBSD__)
#include <sys/param.h>
#include <sys/sysctl.h>
#include <kvm.h>
#endif
enum { FF_PIPE_BUFSIZ = 8192 };
@@ -259,6 +263,18 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
}
}
#elif defined(__OpenBSD__)
kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
int count = 0;
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
if (proc)
{
char** argv = kvm_getargv(kd, proc, 0);
if (argv) ffStrbufSetS(exe, argv[0]);
}
kvm_close(kd);
#endif
if(exe->length == 0)
@@ -373,6 +389,23 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
if (tty)
*tty = (int) proc.pr_ttydev;
#elif defined(__OpenBSD__)
kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
int count = 0;
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
if (proc)
{
ffStrbufSetS(name, proc->p_comm);
if (ppid)
*ppid = proc->p_ppid;
if (tty)
*tty = (int) proc->p_tdev;
}
kvm_close(kd);
if (!proc)
return "kvm_getprocs() failed";
#else
return "Unsupported platform";
+36
View File
@@ -2,6 +2,41 @@
#include <stdlib.h>
#ifdef __OpenBSD__
const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result)
{
size_t neededLength;
if (sysctl((int[]) {mib1, mib2}, 2, NULL, &neededLength, NULL, 0) != 0 || neededLength == 1) //neededLength is 1 for empty strings, because of the null terminator
return "sysctlbyname() failed";
ffStrbufEnsureFree(result, (uint32_t) neededLength - 1);
if (sysctl((int[]) {mib1, mib2}, 2, result->chars + result->length, &neededLength, NULL, 0) == 0)
result->length += (uint32_t) neededLength - 1;
result->chars[result->length] = '\0';
return NULL;
}
int ffSysctlGetInt(int mib1, int mib2, int defaultValue)
{
int result;
size_t neededLength = sizeof(result);
if (sysctl((int[]) {mib1, mib2}, 2, &result, &neededLength, NULL, 0) != 0)
return defaultValue;
return result;
}
int64_t ffSysctlGetInt64(int mib1, int mib2, int64_t defaultValue)
{
int64_t result;
size_t neededLength = sizeof(result);
if(sysctl((int[]) {mib1, mib2}, 2, &result, &neededLength, NULL, 0) != 0)
return defaultValue;
return result;
}
#else
const char* ffSysctlGetString(const char* propName, FFstrbuf* result)
{
size_t neededLength;
@@ -35,6 +70,7 @@ int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue)
return defaultValue;
return result;
}
#endif // OpenBSD
void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength)
{
+6
View File
@@ -6,7 +6,13 @@
#include <sys/types.h>
#include <sys/sysctl.h>
#ifdef __OpenBSD__
const char* ffSysctlGetString(int mib1, int mib2, FFstrbuf* result);
FF_C_NODISCARD int ffSysctlGetInt(int mib1, int mib2, int defaultValue);
FF_C_NODISCARD int64_t ffSysctlGetInt64(int mib1, int mib2, int64_t defaultValue);
#else
const char* ffSysctlGetString(const char* propName, FFstrbuf* result);
FF_C_NODISCARD int ffSysctlGetInt(const char* propName, int defaultValue);
FF_C_NODISCARD int64_t ffSysctlGetInt64(const char* propName, int64_t defaultValue);
#endif
FF_C_NODISCARD void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength);
+19
View File
@@ -0,0 +1,19 @@
#include "cpu.h"
#include "common/sysctl.h"
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
{
if (ffSysctlGetString(CTL_HW, HW_MODEL, &cpu->name))
return "sysctl(hw.model) failed";
cpu->coresPhysical = (uint16_t) ffSysctlGetInt(CTL_HW, HW_NCPU, 1);
cpu->coresLogical = cpu->coresPhysical;
cpu->coresOnline = (uint16_t) ffSysctlGetInt(CTL_HW, HW_NCPUONLINE, cpu->coresLogical);
ffCPUDetectSpeedByCpuid(cpu);
cpu->frequencyBase = (uint32_t) ffSysctlGetInt(CTL_HW, HW_CPUSPEED, 0);
cpu->temperature = FF_CPU_TEMP_UNSET; // HW_SENSORS?
return NULL;
}
+16
View File
@@ -6,18 +6,34 @@
#include <sys/resource.h>
#include <stdlib.h>
#ifdef __OpenBSD__
#include <sys/sched.h>
#endif
const char* ffGetCpuUsageInfo(FFlist* cpuTimes)
{
size_t neededLength = 0;
#ifdef __OpenBSD__
int ctls[] = {CTL_KERN, KERN_CPTIME};
if (sysctl(ctls, 2, NULL, &neededLength, NULL, 0) != 0)
return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed";
#else
if(sysctlbyname("kern.cp_times", NULL, &neededLength, NULL, 0) != 0)
return "sysctlbyname(kern.cp_times, NULL) failed";
#endif
uint32_t coreCount = (uint32_t) (neededLength / (CPUSTATES * sizeof(uint64_t)));
assert(coreCount > 0);
FF_AUTO_FREE uint64_t (*cpTimes)[CPUSTATES] = malloc(neededLength);
#ifdef __OpenBSD__
if (sysctl(ctls, 2, cpTimes, &neededLength, NULL, 0) != 0)
return "sysctl({CTL_KERN, KERN_CPTIME}, 2, NULL) failed";
#else
if(sysctlbyname("kern.cp_times", cpTimes, &neededLength, NULL, 0) != 0)
return "sysctlbyname(kern.cp_times, cpTime) failed";
#endif
for (uint32_t i = 0; i < coreCount; ++i)
{
+9
View File
@@ -92,6 +92,11 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk)
}, &attrBuf, sizeof(attrBuf), 0) == 0)
ffStrbufInitNS(&disk->name, attrBuf.nameRef.attr_length - 1 /* excluding '\0' */, attrBuf.nameSpace);
}
#else
static void detectFsInfo(struct statfs* fs, FFDisk* disk)
{
FF_UNUSED(fs, disk);
}
#endif
const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
@@ -143,6 +148,10 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
if(fs->f_flags & MNT_RDONLY)
disk->type |= FF_DISK_VOLUME_TYPE_READONLY_BIT;
#ifdef __OpenBSD__
#define st_birthtimespec __st_birthtim
#endif
struct stat st;
if(stat(fs->f_mntonname, &st) == 0 && st.st_birthtimespec.tv_sec > 0)
disk->createTime = (uint64_t)((st.st_birthtimespec.tv_sec * 1000) + (st.st_birthtimespec.tv_nsec / 1000000));
+26 -3
View File
@@ -12,6 +12,10 @@
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/user.h>
#elif defined(__OpenBSD__)
#include <sys/param.h>
#include <sys/sysctl.h>
#include <kvm.h>
#elif defined(__sun)
#include <procfs.h>
#endif
@@ -252,7 +256,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
{
uint32_t userId = getuid();
#ifdef __FreeBSD__
#if __FreeBSD__
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) userId};
size_t length = 0;
@@ -276,7 +280,26 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
if(result->dePrettyName.length > 0 && result->wmPrettyName.length > 0)
break;
}
#elif defined(__sun)
#elif __OpenBSD__
kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
int count = 0;
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, userId, sizeof(struct kinfo_proc), &count);
if (proc)
{
for (int i = 0; i < count; ++i)
{
if(result->dePrettyName.length == 0)
applyPrettyNameIfDE(result, proc->p_comm);
if(result->wmPrettyName.length == 0)
applyNameIfWM(result, proc->p_comm);
if(result->dePrettyName.length > 0 && result->wmPrettyName.length > 0)
break;
}
}
kvm_close(kd);
#elif __sun
FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc");
if(procdir == NULL)
return "opendir(\"/proc\") failed";
@@ -312,7 +335,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
break;
}
}
#else
#elif __linux__
FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc");
if(procdir == NULL)
return "opendir(\"/proc\") failed";
+4 -1
View File
@@ -17,11 +17,14 @@ const char* ffDetectDNS(FFDNSOptions* options, FFlist* results)
{
if (ffStrStartsWith(line, "nameserver"))
{
const char* nameserver = line + strlen("nameserver");
char* nameserver = line + strlen("nameserver");
while (*nameserver == ' ' || *nameserver == '\t')
nameserver++;
if (*nameserver == '\0') continue;
char* comment = strchr(nameserver, '#');
if (comment) *comment = '\0';
if ((ffStrContainsC(nameserver, ':') && !(options->showType & FF_DNS_TYPE_IPV6_BIT)) ||
(ffStrContainsC(nameserver, '.') && !(options->showType & FF_DNS_TYPE_IPV4_BIT)))
continue;
+19
View File
@@ -0,0 +1,19 @@
#include "host.h"
#include "common/sysctl.h"
#include "util/smbiosHelper.h"
const char* ffDetectHost(FFHostResult* host)
{
const char* error = NULL;
if ((error = ffSysctlGetString(CTL_HW, HW_PRODUCT, &host->name)))
return error;
ffCleanUpSmbiosValue(&host->name);
if (ffSysctlGetString(CTL_HW, HW_VENDOR, &host->vendor) == NULL)
ffCleanUpSmbiosValue(&host->vendor);
if (ffSysctlGetString(CTL_HW, HW_VERSION, &host->version) == NULL)
ffCleanUpSmbiosValue(&host->version);
if (ffSysctlGetString(CTL_HW, HW_SERIALNO, &host->serial) == NULL)
ffCleanUpSmbiosValue(&host->serial);
return NULL;
}
+4 -2
View File
@@ -2,10 +2,12 @@
#include <sys/sysctl.h>
#ifdef __FreeBSD__
#if __FreeBSD__ || __OpenBSD__
#include <sys/types.h>
#include <sys/resource.h>
#include <vm/vm_param.h>
#if __FreeBSD__
#include <vm/vm_param.h>
#endif
#endif
const char* ffDetectLoadavg(double result[3])
+3 -3
View File
@@ -17,7 +17,7 @@
#include <linux/sockios.h>
#endif
#if defined(__FreeBSD__) || defined(__APPLE__)
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#include <net/if_media.h>
#include <net/if_dl.h>
#else
@@ -143,7 +143,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
addNewIp(results, ifa->ifa_name, addressBuffer, AF_INET6, isDefaultRoute, !(options->showType & FF_LOCALIP_TYPE_ALL_IPS_BIT));
}
#if defined(__FreeBSD__) || defined(__APPLE__)
#if __FreeBSD__ || __OpenBSD__ || __APPLE__
else if (ifa->ifa_addr->sa_family == AF_LINK)
{
if (!(options->showType & FF_LOCALIP_TYPE_MAC_BIT))
@@ -199,7 +199,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
ifr.ifr_data = (void*) &edata;
if (ioctl(sockfd, SIOCETHTOOL, &ifr) == 0)
iface->speed = (edata.speed_hi << 16) | edata.speed; // ethtool_cmd_speed is not available on Android
#elif __FreeBSD__ || __APPLE__
#elif __FreeBSD__ || __APPLE__ || __OpenBSD__
struct ifmediareq ifmr = {};
strncpy(ifmr.ifm_name, iface->name.chars, IFNAMSIZ - 1);
if (ioctl(sockfd, SIOCGIFMEDIA, &ifmr) == 0 && (IFM_TYPE(ifmr.ifm_active) & IFM_ETHER))
+20
View File
@@ -0,0 +1,20 @@
#include "memory.h"
#include "common/sysctl.h"
#include <sys/vmmeter.h>
const char* ffDetectMemory(FFMemoryResult* ram)
{
size_t length = sizeof(ram->bytesTotal);
if (sysctl((int[]){ CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, NULL, 0) < 0)
return "Failed to read hw.physmem";
struct vmtotal vmtotal;
length = sizeof(vmtotal);
if (sysctl((int[]) {CTL_VM, VM_METER}, 2, &vmtotal, &length, NULL, 0) < 0)
return "sysctl(VM_METER) failed";
ram->bytesUsed = ram->bytesTotal - vmtotal.t_free * instance.state.platform.sysinfo.pageSize;
return NULL;
}
+8 -3
View File
@@ -14,7 +14,6 @@ void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglG
#endif // FF_HAVE_GL
#ifdef FF_HAVE_GLX
#include <GL/glx.h>
@@ -25,7 +24,7 @@ typedef struct GLXData
FF_LIBRARY_SYMBOL(glXQueryVersion)
FF_LIBRARY_SYMBOL(XOpenDisplay)
FF_LIBRARY_SYMBOL(glXChooseVisual)
FF_LIBRARY_SYMBOL(XCreatePixmap);
FF_LIBRARY_SYMBOL(XCreatePixmap)
FF_LIBRARY_SYMBOL(glXCreateGLXPixmap)
FF_LIBRARY_SYMBOL(glXCreateContext)
FF_LIBRARY_SYMBOL(glXMakeCurrent)
@@ -120,7 +119,13 @@ static const char* detectByGlx(FFOpenGLResult* result)
{
GLXData data;
FF_LIBRARY_LOAD(glx, "dlopen glx failed", "libGLX" FF_LIBRARY_EXTENSION, 1);
FF_LIBRARY_LOAD(glx, "dlopen glx failed",
#if !__OpenBSD__
"libGLX"
#else
"libGL"
#endif
FF_LIBRARY_EXTENSION, 1);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXGetProcAddress);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXQueryVersion);
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XOpenDisplay);
+7
View File
@@ -0,0 +1,7 @@
#include "os.h"
void ffDetectOSImpl(FFOSResult* os)
{
ffStrbufSetStatic(&os->name, "OpenBSD");
ffStrbufSet(&os->version, &instance.state.platform.sysinfo.release);
}
+1 -1
View File
@@ -18,7 +18,7 @@ static uint32_t getSQLite3Int(const char* dbPath, const char* query, const char*
return num_elements;
}
void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options)
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT))
{
+31
View File
@@ -0,0 +1,31 @@
#include "packages.h"
#include "common/io/io.h"
static uint32_t getNumElementsImpl(const char* dirname, unsigned char type)
{
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(dirname);
if(dirp == NULL)
return 0;
uint32_t num_elements = 0;
struct dirent *entry;
while((entry = readdir(dirp)) != NULL) {
if(entry->d_type == type)
++num_elements;
}
if(type == DT_DIR && num_elements >= 2)
num_elements -= 2; // accounting for . and ..
return num_elements;
}
void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options)
{
if (!(options->disabled & FF_PACKAGES_FLAG_PKG_BIT))
{
result->pkg = getNumElementsImpl(FASTFETCH_TARGET_DIR_ROOT "/var/db/pkg", DT_DIR);
}
}
+14
View File
@@ -0,0 +1,14 @@
#include "processes.h"
#include <sys/param.h>
#include <sys/sysctl.h>
#include <kvm.h>
const char* ffDetectProcesses(uint32_t* result)
{
kvm_t* kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
const void* ret = kvm_getprocs(kd, KERN_PROC_ALL, 0, 1, result);
kvm_close(kd);
if (!ret) return "kvm_getprocs() failed";
return NULL;
}
+30
View File
@@ -0,0 +1,30 @@
#include "swap.h"
#include "util/mallocHelper.h"
#include <sys/types.h>
#include <sys/swap.h>
#include <sys/param.h>
#include <unistd.h>
const char* ffDetectSwap(FFSwapResult* swap)
{
int nswap = swapctl(SWAP_NSWAP, 0, 0);
if (nswap < 0) return "swapctl(SWAP_NSWAP) failed";
if (nswap == 0) NULL;
struct swapent* swdev = malloc((uint32_t) nswap * sizeof(*swdev));
if (swapctl(SWAP_STATS, swdev, nswap) < 0)
return "swapctl(SWAP_STATS) failed";
for (int i = 0; i < nswap; i++)
{
if (swdev[i].se_flags & SWF_ENABLE)
{
swap->bytesUsed += (uint64_t) swdev[i].se_inuse * DEV_BSIZE;
swap->bytesTotal += (uint64_t) swdev[i].se_nblks * DEV_BSIZE;
}
}
return NULL;
}
+18 -2
View File
@@ -8,6 +8,8 @@
#include <ctype.h>
#ifdef __FreeBSD__
#include <paths.h>
#elif __OpenBSD__
#define _PATH_LOCALBASE "/usr/local"
#endif
#ifdef _WIN32
@@ -119,6 +121,19 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version)
{
#if __OpenBSD__
if(ffProcessAppendStdOut(version, (char* const[]) {
exe->chars,
"-c",
"echo $KSH_VERSION",
NULL
}) != NULL)
return false;
// @(#)PD KSH v5.2.14 99/07/13.2
ffStrbufSubstrAfterFirstC(version, 'v');
ffStrbufSubstrBeforeFirstC(version, ' ');
#else
if(ffProcessAppendStdErr(version, (char* const[]) {
exe->chars,
"--version",
@@ -129,6 +144,7 @@ static bool getShellVersionKsh(FFstrbuf* exe, FFstrbuf* version)
// version sh (AT&T Research) 93u+ 2012-08-01
ffStrbufSubstrAfterLastC(version, ')');
ffStrbufTrim(version, ' ');
#endif
return true;
}
@@ -559,7 +575,7 @@ static bool getTerminalVersionZed(FFstrbuf* exe, FFstrbuf* version)
#ifndef _WIN32
static bool getTerminalVersionKitty(FFstrbuf* exe, FFstrbuf* version)
{
#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
char buffer[1024] = {};
if (
#ifdef __linux__
@@ -662,7 +678,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun)
if(ffStrbufStartsWithIgnCaseS(processName, "gnome-terminal"))
return getTerminalVersionGnome(exe, version);
+7
View File
@@ -0,0 +1,7 @@
#include "fastfetch.h"
#include "users.h"
const char* ffDetectUsers(FFUsersOptions* options, FFlist* users)
{
return "Not supported on this platform";
}
+2
View File
@@ -33,6 +33,8 @@
#define FF_SYSNAME "WIN32"
#elif defined(__sun)
#define FF_SYSNAME "SunOS"
#elif defined(__OpenBSD__)
#define FF_SYSNAME "OpenBSD"
#else
#define FF_SYSNAME "unknown"
#endif
+1
View File
@@ -3088,6 +3088,7 @@ static const FFlogo O[] = {
FF_COLOR_FG_WHITE,
FF_COLOR_FG_CYAN,
FF_COLOR_FG_RED,
FF_COLOR_FG_LIGHT_BLACK,
},
.colorKeys = FF_COLOR_FG_YELLOW,
.colorTitle = FF_COLOR_FG_WHITE,
+1 -1
View File
@@ -492,7 +492,7 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options)
ffOptionInitModuleArg(&options->moduleArgs, "󰩟");
options->showType = FF_LOCALIP_TYPE_IPV4_BIT | FF_LOCALIP_TYPE_PREFIX_LEN_BIT
#ifndef __ANDROID__
#if !__ANDROID__ /*Permission denied*/ && !__OpenBSD__ /*Report invalid argument for some reason*/
| FF_LOCALIP_TYPE_DEFAULT_ROUTE_ONLY_BIT
#endif
;
+1 -1
View File
@@ -10,7 +10,7 @@
void ffPrintMemory(FFMemoryOptions* options)
{
FFMemoryResult storage;
FFMemoryResult storage = {};
const char* error = ffDetectMemory(&storage);
if(error)
+2
View File
@@ -230,6 +230,8 @@ void ffInitOSOptions(FFOSOptions* options)
""
#elif __sun
""
#elif __OpenBSD__
""
#else
"?"
#endif
+1 -1
View File
@@ -10,7 +10,7 @@
void ffPrintSwap(FFSwapOptions* options)
{
FFSwapResult storage;
FFSwapResult storage = {};
const char* error = ffDetectSwap(&storage);
if(error)
+2 -2
View File
@@ -39,7 +39,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va
else if (ffStrEqualsIgnCase(key, "detectVersion"))
options->detectVersion = yyjson_get_bool(val);
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__)
else if (ffStrEqualsIgnCase(key, "escapeBedrock"))
options->escapeBedrock = yyjson_get_bool(val);
else if (ffStrEqualsIgnCase(key, "playerName"))
@@ -84,7 +84,7 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key
else if(ffStrEqualsIgnCase(key, "--detect-version"))
options->detectVersion = ffOptionParseBoolean(value);
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__)
else if(ffStrEqualsIgnCase(key, "--escape-bedrock"))
options->escapeBedrock = ffOptionParseBoolean(value);
else if(ffStrEqualsIgnCase(key, "--player-name"))
+1 -1
View File
@@ -16,7 +16,7 @@ typedef struct FFOptionsGeneral
bool detectVersion;
// Module options that cannot be put in module option structure
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__)
FFstrbuf playerName;
bool escapeBedrock;
FFDsForceDrmType dsForceDrm;
+1 -1
View File
@@ -1,6 +1,6 @@
#include "binary.h"
#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__)
#if defined(FF_HAVE_ELF) || defined(__sun) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include "common/io/io.h"
#include "common/library.h"
+5 -3
View File
@@ -12,7 +12,7 @@
#ifdef __APPLE__
#include <libproc.h>
#include <sys/sysctl.h>
#elif defined(__FreeBSD__)
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h>
#endif
@@ -34,7 +34,9 @@ static void getExePath(FFPlatform* platform)
exePathLen = 0;
else
exePathLen--; // remove terminating NUL
#else
#elif defined(__OpenBSD__)
size_t exePathLen = 0;
#elif defined(__sun)
ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1);
exePath[exePathLen] = '\0';
#endif
@@ -177,7 +179,7 @@ static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts)
ffStrbufAppendS(&info->architecture, uts->machine);
ffStrbufInit(&info->displayVersion);
#if defined(__FreeBSD__) || defined(__APPLE__)
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
size_t length = sizeof(info->pageSize);
sysctl((int[]){ CTL_HW, HW_PAGESIZE }, 2, &info->pageSize, &length, NULL, 0);
#else