From 71fbe043672de97200f91687ea4021eada6141af Mon Sep 17 00:00:00 2001 From: Yelninei Date: Mon, 19 May 2025 15:07:46 +0000 Subject: [PATCH] Start work on GNU --- CMakeLists.txt | 87 +++++++++++++++++++++++++++ src/common/processing_linux.c | 23 ++++++- src/detection/loadavg/loadavg_linux.c | 3 +- src/detection/localip/localip_linux.c | 6 +- src/detection/uptime/uptime_linux.c | 4 +- src/detection/version/version.c | 2 + src/options/general.h | 2 +- src/util/platform/FFPlatform_unix.c | 2 +- 8 files changed, 121 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6a49cdc7..649841e1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") set(SunOS TRUE CACHE BOOL "..." FORCE) elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku") set(Haiku TRUE CACHE BOOL "..." FORCE) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU") + set(GNU TRUE CACHE BOOL "..." FORCE) elseif(NOT APPLE AND NOT WIN32) message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") endif() @@ -1192,6 +1194,83 @@ elseif(Haiku) src/util/binary_linux.c src/util/haiku/version.cpp ) +elseif(GNU) + list(APPEND LIBFASTFETCH_SRC + src/common/dbus.c + src/common/io/io_unix.c + src/common/netif/netif_linux.c + src/common/networking/networking_linux.c + src/common/processing_linux.c + src/detection/battery/battery_nosupport.c + src/detection/bios/bios_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_linux.c + src/detection/cpucache/cpucache_nosupport.c + src/detection/cpuusage/cpuusage_linux.c + src/detection/cursor/cursor_linux.c + src/detection/bluetooth/bluetooth_linux.c + src/detection/bluetoothradio/bluetoothradio_linux.c + src/detection/disk/disk_linux.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/wlr-output-management-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/gpu/gpu_pci.c + src/detection/gtk_qt/gtk.c + src/detection/host/host_nosupport.c + src/detection/icons/icons_linux.c + src/detection/initsystem/initsystem_linux.c + src/detection/keyboard/keyboard_nosupport.c + src/detection/libc/libc_linux.c + src/detection/lm/lm_linux.c + src/detection/loadavg/loadavg_linux.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_linux.c + src/detection/mouse/mouse_nosupport.c + src/detection/netio/netio_nosupport.c + src/detection/opengl/opengl_linux.c + src/detection/os/os_linux.c + src/detection/packages/packages_linux.c + src/detection/poweradapter/poweradapter_nosupport.c + src/detection/processes/processes_linux.c + src/detection/gtk_qt/qt.c + src/detection/sound/sound_linux.c + src/detection/swap/swap_linux.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_linux.c + src/detection/users/users_linux.c + src/detection/wallpaper/wallpaper_linux.c + src/detection/wifi/wifi_linux.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 + ) endif() if(ENABLE_DIRECTX_HEADERS) @@ -1315,6 +1394,10 @@ elseif(NetBSD) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib") # ditto elseif(Haiku) target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) +elseif(GNU) + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE) + # On Hurd PATH_MAX is not defined. Set an arbitrary limit as workaround. + target_compile_definitions(libfastfetch PUBLIC PATH_MAX=4096) endif() if(FreeBSD OR OpenBSD OR NetBSD) @@ -1639,6 +1722,10 @@ elseif(SunOS) PRIVATE "nvpair" PRIVATE "devinfo" ) +elseif(GNU) + target_link_libraries(libfastfetch + PRIVATE "m" + ) elseif(ANDROID) CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) if(HAVE_LIBANDROID_WORDEXP_STATIC) diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 1fdfbae2a..c9a1dd31f 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -234,7 +234,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons assert(processName->length > 0); ffStrbufClear(exe); - #ifdef __linux__ + #if defined(__linux__) || defined(__GNU__) char filePath[64]; snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid); @@ -436,7 +436,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i if (pid <= 0) return "Invalid pid"; - #ifdef __linux__ + #if defined(__linux__) || defined(__GNU__) char procFilePath[64]; if (ppid) @@ -465,11 +465,30 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i } else { + #ifndef __GNU__ snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int)pid); ssize_t nRead = ffReadFileBuffer(procFilePath, name); if(nRead <= 0) return "ffReadFileBuffer(/proc/pid/comm, name) failed"; ffStrbufTrimRightSpace(name); + #else + // No /proc/1/comm on Hurd so read /proc/1/stat again + snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid); + char buf[PROC_FILE_BUFFSIZ]; + ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf); + if(nRead <= 8) + return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed"; + buf[nRead] = '\0'; + + ffStrbufEnsureFixedLengthFree(name, 255); + if( + sscanf(buf, "%*s (%255[^)]) %*c %*d %*d %*d %*d", name->chars) == 0 || //stat (comm) state ppid pgrp session tty + name->chars[0] == '\0' + ) + return "sscanf(stat) failed"; + + ffStrbufRecalculateLength(name); + #endif } #elif defined(__APPLE__) diff --git a/src/detection/loadavg/loadavg_linux.c b/src/detection/loadavg/loadavg_linux.c index 9e8b091c5..c75afb962 100644 --- a/src/detection/loadavg/loadavg_linux.c +++ b/src/detection/loadavg/loadavg_linux.c @@ -19,7 +19,7 @@ const char* ffDetectLoadavg(double result[3]) } #endif - + #ifndef __GNU__ // getloadavg requires higher ANDROID_API version struct sysinfo si; if (sysinfo(&si) < 0) @@ -27,5 +27,6 @@ const char* ffDetectLoadavg(double result[3]) for (int i = 0; i < 3; i++) result[i] = (double) si.loads[i] / (1 << SI_LOAD_SHIFT); + #endif return NULL; } diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index ad9645229..b52e28790 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -29,6 +29,7 @@ #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__) || defined(__HAIKU__) #include #include +#elif defined(__GNU__) #else #include #endif @@ -69,12 +70,14 @@ static const FFLocalIpNIFlag niFlagOptions[] = { #ifdef IFF_NOTRAILERS FF_LOCALIP_NIFLAG(NOTRAILERS), #endif -#ifdef __linux__ +#if defined( __linux__) || defined (__GNU__) FF_LOCALIP_NIFLAG(MASTER), FF_LOCALIP_NIFLAG(SLAVE), FF_LOCALIP_NIFLAG(PORTSEL), FF_LOCALIP_NIFLAG(AUTOMEDIA), FF_LOCALIP_NIFLAG(DYNAMIC), +#endif +#ifdef __linux__ FF_LOCALIP_NIFLAG(LOWER_UP), FF_LOCALIP_NIFLAG(DORMANT), FF_LOCALIP_NIFLAG(ECHO), @@ -562,6 +565,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) FF_DEBUG("No MAC address available for interface %s", adapter->mac->ifa_name); } } + #elif defined(__GNU__) #else (void) adapter; #endif diff --git a/src/detection/uptime/uptime_linux.c b/src/detection/uptime/uptime_linux.c index 44705a5fc..c1786a89b 100644 --- a/src/detection/uptime/uptime_linux.c +++ b/src/detection/uptime/uptime_linux.c @@ -26,13 +26,13 @@ const char* ffDetectUptime(FFUptimeResult* result) } #endif - + #ifndef __GNU__ struct timespec uptime; if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0) return "clock_gettime(CLOCK_BOOTTIME) failed"; result->uptime = (uint64_t) uptime.tv_sec * 1000 + (uint64_t) uptime.tv_nsec / 1000000; result->bootTime = ffTimeGetNow() - result->uptime; - + #endif return NULL; } diff --git a/src/detection/version/version.c b/src/detection/version/version.c index f47ffcaa1..7d278107e 100644 --- a/src/detection/version/version.c +++ b/src/detection/version/version.c @@ -54,6 +54,8 @@ #define FF_SYSNAME "NetBSD" #elif defined(__HAIKU__) #define FF_SYSNAME "Haiku" +#elif defined(__GNU__) + #define FF_SYSNAME "GNU" #else #define FF_SYSNAME "Unknown" #endif diff --git a/src/options/general.h b/src/options/general.h index 9e703a946..0edcfeb2d 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -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) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) + #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__) FFstrbuf playerName; FFDsForceDrmType dsForceDrm; #elif defined(_WIN32) diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index eb9ee450e..682c2e6f7 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -22,7 +22,7 @@ static void getExePath(FFPlatform* platform) { char exePath[PATH_MAX + 1]; - #ifdef __linux__ + #if defined(__linux__) || defined (__GNU__) ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1); if (exePathLen >= 0) exePath[exePathLen] = '\0';