diff --git a/src/common/impl/binary_apple.c b/src/common/impl/binary_apple.c index c25df7a92..dd35a5ae7 100644 --- a/src/common/impl/binary_apple.c +++ b/src/common/impl/binary_apple.c @@ -1,7 +1,9 @@ #include "common/binary.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" +#include #include #include #include @@ -108,6 +110,7 @@ static const char* dumpMachHeader(const FFMemoryMapping* mapping, off_t offset, if (is_64) { const struct mach_header_64* header = readData(mapping, sizeof(struct mach_header_64), offset); if (!header) { + FF_DEBUG("Failed to read the 64-bit mach header at offset %lld", (long long) offset); return "read mach header failed"; } @@ -116,6 +119,7 @@ static const char* dumpMachHeader(const FFMemoryMapping* mapping, off_t offset, } else { const struct mach_header* header = readData(mapping, sizeof(struct mach_header), offset); if (!header) { + FF_DEBUG("Failed to read the mach header at offset %lld", (long long) offset); return "read mach header failed"; } @@ -200,6 +204,7 @@ static const char* dumpMachHeader(const FFMemoryMapping* mapping, off_t offset, static const char* dumpFatHeader(const FFMemoryMapping* mapping, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength) { const struct fat_header* headerRaw = readData(mapping, sizeof(struct fat_header), 0); if (!headerRaw) { + FF_DEBUG("Failed to read the fat header"); return "read fat header failed"; } @@ -251,6 +256,7 @@ static const char* dumpFatHeader(const FFMemoryMapping* mapping, bool (*cb)(cons return dumpMachHeader(mapping, machHeaderOffset, *magic == MH_MAGIC_64, cb, userdata, minLength); } } + FF_DEBUG("No supported Mach-O slice was found in the fat binary"); return "Unsupported fat header"; } @@ -265,11 +271,13 @@ static const char* dumpFatHeader(const FFMemoryMapping* mapping, bool (*cb)(cons const char* ffBinaryExtractStrings(const char* machoFile, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength) { FF_AUTO_CLOSE_FD int fd = open(machoFile, O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(\"%s\") failed: %s", machoFile, strerror(errno)); return "File could not be opened"; } struct stat st; if (fstat(fd, &st) != 0 || st.st_size <= 0) { + FF_DEBUG("fstat(\"%s\") failed or the file is empty", machoFile); return "Failed to stat file"; } @@ -278,12 +286,14 @@ const char* ffBinaryExtractStrings(const char* machoFile, bool (*cb)(const char* .length = (size_t) st.st_size, }; if (mapping.data == MAP_FAILED) { + FF_DEBUG("mmap(\"%s\", %lld bytes) failed: %s", machoFile, (long long) st.st_size, strerror(errno)); return "mmap failed"; } // Read the magic number to determine the type of binary const uint32_t* magic = readData(&mapping, sizeof(uint32_t), 0); if (!magic) { + FF_DEBUG("Failed to read the magic number"); return "read magic number failed"; } @@ -291,6 +301,7 @@ const char* ffBinaryExtractStrings(const char* machoFile, bool (*cb)(const char* // MH_CIGAM and MH_CIGAM_64 seem to be no longer used, as `swap_mach_header` is marked as deprecated. // However FAT_CIGAM and FAT_CIGAM_64 are still used (/usr/bin/vim). if (*magic != MH_MAGIC && *magic != MH_MAGIC_64 && *magic != FAT_CIGAM && *magic != FAT_CIGAM_64 && *magic != FAT_MAGIC && *magic != FAT_MAGIC_64) { + FF_DEBUG("Unsupported magic number 0x%08x", (unsigned) *magic); return "Unsupported format or big endian mach-o file"; } diff --git a/src/common/impl/binary_linux.c b/src/common/impl/binary_linux.c index 2d8d50b19..c9316ecc9 100644 --- a/src/common/impl/binary_linux.c +++ b/src/common/impl/binary_linux.c @@ -1,4 +1,5 @@ #include "common/binary.h" +#include "common/debug.h" #if defined(FF_HAVE_ELF) || defined(__sun) || (defined(__FreeBSD__) && !defined(__DragonFly__)) || defined(__OpenBSD__) || defined(__NetBSD__) @@ -43,6 +44,7 @@ const char* ffBinaryExtractStrings(const char* elfFile, bool (*cb)(const char* s FF_LIBRARY_LOAD_MESSAGE(libelf, "libelf" FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libelf, elfData, elf_version) if (elfData.ffelf_version(EV_CURRENT) == EV_NONE) { + FF_DEBUG("elf_version() failed"); return "elf_version() failed"; } @@ -60,23 +62,27 @@ const char* ffBinaryExtractStrings(const char* elfFile, bool (*cb)(const char* s } if (elfData.ffelf_end == nullptr) { + FF_DEBUG("load libelf failed"); return "load libelf failed"; } // Open the ELF file FF_AUTO_CLOSE_FD int fd = open(elfFile, O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(%s) failed: %s", elfFile, strerror(errno)); return "open() failed"; } Elf* elf = elfData.ffelf_begin(fd, ELF_C_READ, nullptr); if (elf == nullptr) { + FF_DEBUG("elf_begin() failed"); return "elf_begin() failed"; } // Get the section header string table index size_t shstrndx = 0; if (elfData.ffelf_getshdrstrndx(elf, &shstrndx) < 0) { + FF_DEBUG("elf_getshdrstrndx() failed"); elfData.ffelf_end(elf); return "elf_getshdrstrndx() failed"; } @@ -141,6 +147,7 @@ const char* ffBinaryExtractStrings(const char* elfFile, bool (*cb)(const char* s */ const char* ffBinaryExtractStrings(const char* file, bool (*cb)(const char* str, uint32_t len, void* userdata), void* userdata, uint32_t minLength) { FF_UNUSED(file, cb, userdata, minLength); + FF_DEBUG("Fastfetch was built without libelf support"); return "Fastfetch was built without libelf support"; } diff --git a/src/common/impl/networking_linux.c b/src/common/impl/networking_linux.c index f1ee80b33..04794483c 100644 --- a/src/common/impl/networking_linux.c +++ b/src/common/impl/networking_linux.c @@ -146,6 +146,7 @@ static const char* tryNonThreadingFastPath(FFNetworkingState* state) { #endif #else FF_UNUSED(state); + FF_DEBUG("TFO support is not available"); return "TFO support is not available"; #endif } @@ -593,6 +594,7 @@ const char* ffNetworkingRecvHttpResponse(FFNetworkingState* state, FFstrbuf* buf } if (chunked && !ffNetworkingDecodeChunked(buffer, &headerEnd)) { + FF_DEBUG("Failed to decode chunked response"); return "Failed to decode chunked response"; } diff --git a/src/common/impl/processing_linux.c b/src/common/impl/processing_linux.c index 604094df3..659cb5dc6 100644 --- a/src/common/impl/processing_linux.c +++ b/src/common/impl/processing_linux.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "common/debug.h" #include "common/processing.h" #include "common/io.h" #include "common/strutil.h" @@ -59,6 +60,7 @@ static inline int ffPipe2(int* fds, int flags) { const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinFd, FFProcessHandle* outHandle) { int pipes[2]; if (ffPipe2(pipes, O_CLOEXEC) == -1) { + FF_DEBUG("pipe() failed: %s", strerror(errno)); return "pipe() failed"; } @@ -123,6 +125,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinF posix_spawn_file_actions_destroy(&file_actions); if (ret != 0) { + FF_DEBUG("posix_spawnp() failed: %s", strerror(ret)); close(pipes[0]); close(pipes[1]); if (ret == ENOENT) { @@ -136,6 +139,7 @@ const char* ffProcessSpawn(char* const argv[], bool useStdErr, FFNativeFD stdinF // https://github.com/termux/termux-packages/issues/25369 childPid = fork(); if (childPid == -1) { + FF_DEBUG("fork() failed: %s", strerror(errno)); close(pipes[0]); close(pipes[1]); return "fork() failed"; @@ -177,6 +181,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { struct pollfd pollfd = { childPipeFd, POLLIN, 0 }; int pollret = poll(&pollfd, 1, timeout); if (pollret == 0) { + FF_DEBUG("poll(&pollfd, 1, timeout) timeout (try increasing --processing-timeout)"); kill(childPid, SIGTERM); waitpid(childPid, nullptr, 0); return "poll(&pollfd, 1, timeout) timeout (try increasing --processing-timeout)"; @@ -199,6 +204,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { return "child process exited abnormally"; } if (WEXITSTATUS(stat_loc) == 127) { + FF_DEBUG("command not found"); return "command not found"; } // We only handle 127 as an error. See `getTerminalVersionUrxvt` in `terminalshell.c` @@ -210,6 +216,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) { } } + FF_DEBUG("read(childPipeFd, str, FF_PIPE_BUFSIZ) failed: %s", strerror(errno)); return "read(childPipeFd, str, FF_PIPE_BUFSIZ) failed"; } @@ -475,6 +482,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, int32_t* tty) { if (pid <= 0) { + FF_DEBUG("Invalid pid"); return "Invalid pid"; } @@ -489,6 +497,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i char buf[PROC_FILE_BUFFSIZ]; ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf); if (nRead <= 8) { + FF_DEBUG("ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed"); return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed"; } buf[nRead] = '\0'; // pid (comm) state ppid pgrp session tty @@ -499,16 +508,19 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i // comm in `/proc/pid/stat` is not encoded, and may contain ' ', ')' or even `\n` const char* start = memchr(buf, '(', (size_t) nRead); if (!start) { + FF_DEBUG("memchr(stat, '(') failed"); return "memchr(stat, '(') failed"; } start++; const char* end = memrchr(start, ')', (size_t) nRead - (size_t) (start - buf)); if (!end) { + FF_DEBUG("memrchr(stat, ')') failed"); return "memrchr(stat, ')') failed"; } ffStrbufSetNS(name, (uint32_t) (end - start), start); ffStrbufTrimRightSpace(name); if (name->chars[0] == '\0') { + FF_DEBUG("process name is empty"); return "process name is empty"; } pState = end + 2; // skip ") " @@ -520,6 +532,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i { int ppid_, tty_; if (sscanf(pState + 2, "%d %*d %*d %d", &ppid_, &tty_) < 2) { + FF_DEBUG("sscanf(stat) failed"); return "sscanf(stat) failed"; } @@ -536,6 +549,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int) pid); ssize_t nRead = ffReadFileBuffer(procFilePath, name); if (nRead <= 0) { + FF_DEBUG("ffReadFileBuffer(/proc/pid/comm, name) failed"); return "ffReadFileBuffer(/proc/pid/comm, name) failed"; } ffStrbufTrimRightSpace(name); @@ -548,6 +562,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i size_t size = sizeof(proc); if (sysctl( (int[]) { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid }, 4, &proc, &size, nullptr, 0)) { + FF_DEBUG("sysctl(KERN_PROC_PID) failed: %s", strerror(errno)); return "sysctl(KERN_PROC_PID) failed"; } @@ -574,6 +589,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i size_t size = sizeof(proc); if (sysctl( (int[]) { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid }, 4, &proc, &size, nullptr, 0)) { + FF_DEBUG("sysctl(KERN_PROC_PID) failed: %s", strerror(errno)); return "sysctl(KERN_PROC_PID) failed"; } @@ -600,6 +616,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i size_t size = sizeof(proc); if (sysctl( (int[]) { CTL_KERN, KERN_PROC2, KERN_PROC_PID, pid, sizeof(proc), 1 }, 6, &proc, &size, nullptr, 0) != 0) { + FF_DEBUG("sysctl(KERN_PROC_PID) failed: %s", strerror(errno)); return "sysctl(KERN_PROC_PID) failed"; } @@ -625,6 +642,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i snprintf(path, sizeof(path), "/proc/%d/psinfo", (int) pid); psinfo_t proc; if (ffReadFileData(path, sizeof(proc), &proc) != sizeof(proc)) { + FF_DEBUG("ffReadFileData(psinfo) failed"); return "ffReadFileData(psinfo) failed"; } @@ -650,6 +668,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i *tty = (int) proc.p_tdev; } } else { + FF_DEBUG("sysctl(KERN_PROC_PID) failed: %s", strerror(errno)); return "sysctl(KERN_PROC_PID) failed"; } @@ -667,6 +686,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i #else + FF_DEBUG("Unsupported platform"); return "Unsupported platform"; #endif diff --git a/src/detection/battery/battery_android.c b/src/detection/battery/battery_android.c index b812c45f4..1da91bfcf 100644 --- a/src/detection/battery/battery_android.c +++ b/src/detection/battery/battery_android.c @@ -360,6 +360,7 @@ static bool detectStatusFromProperty(uint64_t* status) { // back as it came and the caller decides what that is worth. The unit is milliseconds. static const char* getTimeRemaining(FFBinder* binder, uint32_t handle, int32_t transaction, int64_t* milliseconds) { if (transaction == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("computeBatteryTimeRemaining is unresolved in the jar (transaction %d)", (int) transaction); return "The battery stats service does not declare computeBatteryTimeRemaining"; } @@ -540,6 +541,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) { return error; } if (transaction == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("getProperty is unresolved in the jar (transaction %d)", (int) transaction); return "The battery service does not declare getProperty"; } diff --git a/src/detection/battery/battery_apple.c b/src/detection/battery/battery_apple.c index fb6030391..c231790df 100644 --- a/src/detection/battery/battery_apple.c +++ b/src/detection/battery/battery_apple.c @@ -1,5 +1,6 @@ #include "fastfetch.h" #include "battery.h" +#include "common/debug.h" #include "common/apple/cf_helpers.h" #include "common/apple/smc_temps.h" @@ -9,6 +10,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) { FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = IO_OBJECT_NULL; if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("AppleSmartBattery"), &iterator) != kIOReturnSuccess) { + FF_DEBUG("IOServiceGetMatchingServices() failed"); return "IOServiceGetMatchingServices() failed"; } diff --git a/src/detection/battery/battery_bsd.c b/src/detection/battery/battery_bsd.c index cff41d5a6..517899df2 100644 --- a/src/detection/battery/battery_bsd.c +++ b/src/detection/battery/battery_bsd.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/io.h" #include "battery.h" @@ -6,6 +7,8 @@ #include #include #include +#include +#include #include const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* results) { @@ -14,6 +17,7 @@ const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* int units = ffSysctlGetInt("hw.acpi.battery.units", -100); if (units < 0) { + FF_DEBUG("sysctlbyname(\"hw.acpi.battery.units\") failed: %s", strerror(errno)); return "sysctlbyname(\"hw.acpi.battery.units\") failed"; } @@ -23,6 +27,7 @@ const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* FF_AUTO_CLOSE_FD int acpifd = open("/dev/acpi", O_RDONLY | O_CLOEXEC); if (acpifd < 0) { + FF_DEBUG("open(\"/dev/acpi\", O_RDONLY | O_CLOEXEC) failed: %s", strerror(errno)); return "open(\"/dev/acpi\", O_RDONLY | O_CLOEXEC) failed"; } diff --git a/src/detection/battery/battery_haiku.c b/src/detection/battery/battery_haiku.c index 523d33d93..12d84b659 100644 --- a/src/detection/battery/battery_haiku.c +++ b/src/detection/battery/battery_haiku.c @@ -1,23 +1,28 @@ #include "fastfetch.h" #include "battery.h" +#include "common/debug.h" #include "common/io.h" #include #include #include +#include const char* parseBattery(int dfd, const char* battId, FFlist* results) { FF_AUTO_CLOSE_FD int fd = openat(dfd, battId, O_RDWR); if (fd < 0) { + FF_DEBUG("openat(%s) failed: %s", battId, strerror(errno)); return "openat() failed"; } acpi_battery_info basic = {}; if (ioctl(fd, GET_BATTERY_INFO, &basic, sizeof(basic)) != 0) { + FF_DEBUG("ioctl(GET_BATTERY_INFO) failed"); return "ioctl(GET_BATTERY_INFO) failed"; } acpi_extended_battery_info extended = {}; if (ioctl(fd, GET_EXTENDED_BATTERY_INFO, &extended, sizeof(extended)) != 0) { + FF_DEBUG("ioctl(GET_EXTENDED_BATTERY_INFO) failed"); return "ioctl(GET_EXTENDED_BATTERY_INFO) failed"; } @@ -56,6 +61,7 @@ const char* parseBattery(int dfd, const char* battId, FFlist* results) { const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* results) { FF_AUTO_CLOSE_DIR DIR* dir = opendir("/dev/power/acpi_battery/"); if (!dir) { + FF_DEBUG("opendir(\"/dev/power/acpi_battery/\") failed: %s", strerror(errno)); return "opendir(/dev/power/acpi_battery) failed"; } diff --git a/src/detection/battery/battery_linux.c b/src/detection/battery/battery_linux.c index 0362cbcd1..4c0c6093d 100644 --- a/src/detection/battery/battery_linux.c +++ b/src/detection/battery/battery_linux.c @@ -6,6 +6,7 @@ #include #include #include +#include // https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power @@ -176,6 +177,7 @@ static bool parseBattery(int dfd, const char* id, FFBatteryOptions* options, FFl const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/power_supply/"); if (dirp == nullptr) { + FF_DEBUG("opendir(\"/sys/class/power_supply/\") failed: %s", strerror(errno)); return "opendir(\"/sys/class/power_supply/\") == nullptr"; } diff --git a/src/detection/battery/battery_nbsd.c b/src/detection/battery/battery_nbsd.c index eaf1fc715..0d88ec118 100644 --- a/src/detection/battery/battery_nbsd.c +++ b/src/detection/battery/battery_nbsd.c @@ -1,4 +1,5 @@ #include "battery.h" +#include "common/debug.h" #include "common/io.h" #include "common/FFstrbuf.h" #include "common/strutil.h" @@ -17,11 +18,13 @@ const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* results) { FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(_PATH_SYSMON) failed: %s", strerror(errno)); return "open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed"; } prop_dictionary_t root = nullptr; if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0) { + FF_DEBUG("prop_dictionary_recv_ioctl(ENVSYS_GETDICTIONARY) failed"); return "prop_dictionary_recv_ioctl(ENVSYS_GETDICTIONARY) failed"; } diff --git a/src/detection/battery/battery_obsd.c b/src/detection/battery/battery_obsd.c index c5c6c3c39..f3cd9d69c 100644 --- a/src/detection/battery/battery_obsd.c +++ b/src/detection/battery/battery_obsd.c @@ -1,6 +1,8 @@ #include "battery.h" +#include "common/debug.h" #include "common/io.h" +#include #include #include #include @@ -10,12 +12,14 @@ const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* FF_AUTO_CLOSE_FD int devfd = open("/dev/apm", O_RDONLY | O_CLOEXEC); if (devfd < 0) { + FF_DEBUG("open(\"/dev/apm\") failed: %s", strerror(errno)); return "open(dev/apm, O_RDONLY | O_CLOEXEC) failed"; } struct apm_power_info info = {}; if (ioctl(devfd, APM_IOC_GETPOWER, &info) < 0) { + FF_DEBUG("ioctl(APM_IOC_GETPOWER) failed: %s", strerror(errno)); return "ioctl(APM_IOC_GETPOWER) failed"; } diff --git a/src/detection/battery/battery_sunos.c b/src/detection/battery/battery_sunos.c index e31b7bb9f..8f8a42440 100644 --- a/src/detection/battery/battery_sunos.c +++ b/src/detection/battery/battery_sunos.c @@ -1,4 +1,5 @@ #include "battery.h" +#include "common/debug.h" #include @@ -50,6 +51,7 @@ const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* // https://github.com/illumos/illumos-gate/blob/master/usr/src/cmd/powertop/common/battery.c [[gnu::cleanup(kstatFreeWrap)]] kstat_ctl_t* kc = kstat_open(); if (!kc) { + FF_DEBUG("kstat_open() failed"); return "kstat_open() failed"; } @@ -75,6 +77,7 @@ const char* ffDetectBattery([[maybe_unused]] FFBatteryOptions* options, FFlist* if (!getUint32(bif, "bif_last_cap", &lastCapacity) || !getUint32(bst, "bst_rem_cap", &remainingCapacity) || !getUint32(bst, "bst_state", &state)) { + FF_DEBUG("kstat_data_lookup() failed for bif_last_cap, bst_rem_cap or bst_state"); return "kstat_data_lookup() failed"; } diff --git a/src/detection/bios/bios_apple.c b/src/detection/bios/bios_apple.c index c9a6759b6..c044cddbf 100644 --- a/src/detection/bios/bios_apple.c +++ b/src/detection/bios/bios_apple.c @@ -1,5 +1,6 @@ #include "bios.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" #include @@ -10,11 +11,13 @@ const char* ffDetectBios(FFBiosResult* bios) { // For Intel FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t deviceRom = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/rom"); if (!deviceRom) { + FF_DEBUG("IODeviceTree:/rom not found"); return "IODeviceTree:/rom not found"; } FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef deviceRomProps = nullptr; if (IORegistryEntryCreateCFProperties(deviceRom, &deviceRomProps, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { + FF_DEBUG("IORegistryEntryCreateCFProperties(deviceRom) failed"); return "IORegistryEntryCreateCFProperties(deviceRom) failed"; } @@ -28,6 +31,7 @@ const char* ffDetectBios(FFBiosResult* bios) { // For arm64 FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t device = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/"); if (!device) { + FF_DEBUG("IODeviceTree:/ not found"); return "IODeviceTree:/ not found"; } diff --git a/src/detection/bluetooth/bluetooth_bsd.c b/src/detection/bluetooth/bluetooth_bsd.c index 9b7b03343..911d333ad 100644 --- a/src/detection/bluetooth/bluetooth_bsd.c +++ b/src/detection/bluetooth/bluetooth_bsd.c @@ -1,4 +1,5 @@ #include "bluetooth.h" +#include "common/debug.h" #define L2CAP_SOCKET_CHECKED #include @@ -31,6 +32,7 @@ const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FF // struct hostent* ent = bt_gethostent(); if (bt_devenum((void*) enumDev, devices) < 0) { + FF_DEBUG("bt_devenum() failed"); return "bt_devenum() failed"; } diff --git a/src/detection/bluetooth/bluetooth_linux.c b/src/detection/bluetooth/bluetooth_linux.c index 78187822a..65528a4bd 100644 --- a/src/detection/bluetooth/bluetooth_linux.c +++ b/src/detection/bluetooth/bluetooth_linux.c @@ -1,4 +1,5 @@ #include "bluetooth.h" +#include "common/debug.h" #include "common/percent.h" #include "common/strutil.h" @@ -304,11 +305,13 @@ static const char* detectBluetooth(FFBluetoothOptions* options, FFlist* devices, DBusMessage* managedObjects = ffDBusGetMethodReply(&dbus, "org.bluez", "/", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", nullptr, nullptr); if (!managedObjects) { + FF_DEBUG("Failed to call GetManagedObjects"); return "Failed to call GetManagedObjects"; } DBusMessageIter rootIter; if (!dbus.lib->ffdbus_message_iter_init(managedObjects, &rootIter)) { + FF_DEBUG("Failed to get root iterator of GetManagedObjects"); dbus.lib->ffdbus_message_unref(managedObjects); return "Failed to get root iterator of GetManagedObjects"; } @@ -351,6 +354,7 @@ const char* ffDetectBluetooth(FFBluetoothOptions* options, FFlist* devices /* FF return detectBluetooth(options, devices, connectedCount); #else FF_UNUSED(options, devices); + FF_DEBUG("Fastfetch was compiled without DBus support"); return "Fastfetch was compiled without DBus support"; #endif } diff --git a/src/detection/bluetoothradio/bluetoothradio_linux.c b/src/detection/bluetoothradio/bluetoothradio_linux.c index c3a33a9cc..656a2ceae 100644 --- a/src/detection/bluetoothradio/bluetoothradio_linux.c +++ b/src/detection/bluetoothradio/bluetoothradio_linux.c @@ -1,4 +1,5 @@ #include "bluetoothradio.h" +#include "common/debug.h" #include "common/strutil.h" #ifdef FF_HAVE_DBUS @@ -36,6 +37,7 @@ array [ static const char* detectBluetoothProperty(FFBluetoothRadioResult* device, FFDBusData* dbus, DBusMessageIter* iter) { if (dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY) { + FF_DEBUG("Expected dict entry"); return "Expected dict entry"; } @@ -43,6 +45,7 @@ static const char* detectBluetoothProperty(FFBluetoothRadioResult* device, FFDBu dbus->lib->ffdbus_message_iter_recurse(iter, &dictIter); if (dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING) { + FF_DEBUG("Expected dict entry key to be a string"); return "Expected dict entry key to be a string"; } @@ -82,17 +85,20 @@ static const char* detectBluetoothRoot(FFBluetoothRadioResult* device, const cha DBusMessage* properties = ffDBusGetMethodReply(dbus, "org.bluez", objPath, "org.freedesktop.DBus.Properties", "GetAll", "org.bluez.Adapter1", nullptr); if (!properties) { + FF_DEBUG("Failed to call org.freedesktop.DBus.Properties.GetAll"); return "Failed to call org.freedesktop.DBus.Properties.GetAll"; } DBusMessageIter rootIter; if (!dbus->lib->ffdbus_message_iter_init(properties, &rootIter)) { dbus->lib->ffdbus_message_unref(properties); + FF_DEBUG("Failed to get root iterator of org.freedesktop.DBus.Properties.GetAll"); return "Failed to get root iterator of org.freedesktop.DBus.Properties.GetAll"; } if (dbus->lib->ffdbus_message_iter_get_arg_type(&rootIter) != DBUS_TYPE_ARRAY) { dbus->lib->ffdbus_message_unref(properties); + FF_DEBUG("Expected array"); return "Expected array"; } @@ -110,6 +116,7 @@ static const char* detectBluetoothRoot(FFBluetoothRadioResult* device, const cha static const char* detectBluetooth(FFlist* devices) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/bluetooth"); if (dirp == nullptr) { + FF_DEBUG("opendir(\"/sys/class/bluetooth\") failed: %s", strerror(errno)); return "Failed to open /sys/class/bluetooth"; } @@ -148,6 +155,7 @@ const char* ffDetectBluetoothRadio(FFlist* devices /* FFBluetoothRadioResult */) return detectBluetooth(devices); #else FF_UNUSED(devices) + FF_DEBUG("Fastfetch was compiled without DBus support"); return "Fastfetch was compiled without DBus support"; #endif } diff --git a/src/detection/board/board_apple.c b/src/detection/board/board_apple.c index f3b39538d..18396acb8 100644 --- a/src/detection/board/board_apple.c +++ b/src/detection/board/board_apple.c @@ -1,10 +1,12 @@ #include "board.h" +#include "common/debug.h" #include "common/apple/cf_helpers.h" const char* ffDetectBoard(FFBoardResult* result) { FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t service = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice")); if (!service) { + FF_DEBUG("No IOPlatformExpertDevice found"); return "No IOPlatformExpertDevice found"; } diff --git a/src/detection/bootmgr/bootmgr_apple.c b/src/detection/bootmgr/bootmgr_apple.c index 59aaa7831..beb6019c6 100644 --- a/src/detection/bootmgr/bootmgr_apple.c +++ b/src/detection/bootmgr/bootmgr_apple.c @@ -1,5 +1,6 @@ #include "bootmgr.h" #include "common/io.h" +#include "common/debug.h" #include "common/apple/cf_helpers.h" #include @@ -8,15 +9,18 @@ static const char* detectSecureBoot(bool* result) { #if __aarch64__ FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/chosen"); if (!entryDevice) { + FF_DEBUG("IORegistryEntryFromPath(\"IODeviceTree:/chosen\") failed"); return "IORegistryEntryFromPath() failed"; } FF_CFTYPE_AUTO_RELEASE CFTypeRef prop = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("secure-boot"), kCFAllocatorDefault, kNilOptions); if (!prop) { + FF_DEBUG("IORegistryEntryCreateCFProperty(\"secure-boot\") failed"); return "IORegistryEntryCreateCFProperty() failed"; } if (CFGetTypeID(prop) != CFDataGetTypeID() || CFDataGetLength((CFDataRef) prop) == 0) { + FF_DEBUG("Invalid secure-boot property"); return "Invalid secure-boot property"; } @@ -24,15 +28,18 @@ static const char* detectSecureBoot(bool* result) { #else FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/options"); if (!entryDevice) { + FF_DEBUG("IORegistryEntryFromPath(\"IODeviceTree:/options\") failed"); return "IORegistryEntryFromPath() failed"; } FF_CFTYPE_AUTO_RELEASE CFTypeRef prop = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("94b73556-2197-4702-82a8-3e1337dafbfb:AppleSecureBootPolicy"), kCFAllocatorDefault, 0); if (!prop) { + FF_DEBUG("IORegistryEntryCreateCFProperty(AppleSecureBootPolicy) failed"); return "IORegistryEntryCreateCFProperty() failed"; } if (CFGetTypeID(prop) != CFDataGetTypeID() || CFDataGetLength((CFDataRef) prop) == 0) { + FF_DEBUG("Invalid secure-boot property"); return "Invalid secure-boot property"; } diff --git a/src/detection/bootmgr/bootmgr_bsd.c b/src/detection/bootmgr/bootmgr_bsd.c index 93983ab37..cdefdab56 100644 --- a/src/detection/bootmgr/bootmgr_bsd.c +++ b/src/detection/bootmgr/bootmgr_bsd.c @@ -1,5 +1,6 @@ #include "bootmgr.h" #include "efi_helper.h" +#include "common/debug.h" #include "common/io.h" #ifdef __OpenBSD__ @@ -22,6 +23,7 @@ typedef uint16_t efi_char; const char* ffDetectBootmgr(FFBootmgrResult* result) { FF_AUTO_CLOSE_FD int efifd = open("/dev/efi", O_RDWR | O_CLOEXEC); if (efifd < 0) { + FF_DEBUG("open(\"/dev/efi\") failed: %s", strerror(errno)); return "open(/dev/efi) failed"; } @@ -35,6 +37,7 @@ const char* ffDetectBootmgr(FFBootmgrResult* result) { ioc.name = (efi_char[]) { 'B', 'o', 'o', 't', 'C', 'u', 'r', 'r', 'e', 'n', 't', '\0' }; ioc.namesize = sizeof("BootCurrent") * 2; if (ioctl(efifd, EFIIOC_VAR_GET, &ioc) < 0 || ioc.datasize != 2) { + FF_DEBUG("ioctl(EFIIOC_VAR_GET, BootCurrent) failed"); return "ioctl(EFIIOC_VAR_GET, BootCurrent) failed"; } @@ -46,6 +49,7 @@ const char* ffDetectBootmgr(FFBootmgrResult* result) { ioc.name = (efi_char[]) { 'B', 'o', 'o', 't', hex[0], hex[1], hex[2], hex[3], '\0' }; ioc.namesize = sizeof("Boot####") * 2; if (ioctl(efifd, EFIIOC_VAR_GET, &ioc) < 0 || ioc.datasize == sizeof(buffer)) { + FF_DEBUG("ioctl(EFIIOC_VAR_GET, Boot####) failed"); return "ioctl(EFIIOC_VAR_GET, Boot####) failed"; } diff --git a/src/detection/bootmgr/bootmgr_linux.c b/src/detection/bootmgr/bootmgr_linux.c index 25934a033..226c53d28 100644 --- a/src/detection/bootmgr/bootmgr_linux.c +++ b/src/detection/bootmgr/bootmgr_linux.c @@ -1,4 +1,5 @@ #include "bootmgr.h" +#include "common/debug.h" #include "common/io.h" #include "efi_helper.h" @@ -11,6 +12,7 @@ const char* ffDetectBootmgr(FFBootmgrResult* result) { alignas(uint16_t) uint8_t buffer[2048]; if (ffReadFileData(FF_EFIVARS_PATH_PREFIX "BootCurrent-" FF_EFI_GLOBAL_GUID, sizeof(buffer), buffer) != 6) { + FF_DEBUG("Failed to read efivar: BootCurrent"); return "Failed to read efivar: BootCurrent"; } @@ -20,6 +22,7 @@ const char* ffDetectBootmgr(FFBootmgrResult* result) { ssize_t size = ffReadFileData((const char*) buffer, sizeof(buffer), buffer); if (size < 5 + (int) sizeof(FFEfiLoadOption) || size == (ssize_t) sizeof(buffer)) { + FF_DEBUG("Failed to read efivar: Boot####"); return "Failed to read efivar: Boot####"; } diff --git a/src/detection/brightness/brightness_apple.c b/src/detection/brightness/brightness_apple.c index 14f490067..f1f27d0b7 100644 --- a/src/detection/brightness/brightness_apple.c +++ b/src/detection/brightness/brightness_apple.c @@ -1,6 +1,7 @@ #include "brightness.h" #include "detection/displayserver/displayserver.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" #include "common/edidHelper.h" #include "common/time.h" @@ -28,6 +29,7 @@ typedef CFTypeRef IOAVServiceRef; // Works for internal display static const char* detectWithDisplayServices(const FFDisplayServerResult* displayServer, FFlist* result) { if (DisplayServicesGetBrightness == nullptr) { + FF_DEBUG("DisplayServices function DisplayServicesGetBrightness is not available"); return "DisplayServices function DisplayServicesGetBrightness is not available"; } @@ -53,11 +55,13 @@ static const char* detectWithDisplayServices(const FFDisplayServerResult* displa // Works for Apple Silicon and USB-C adapter connection ( but not HTMI ) static const char* detectWithDdcci([[maybe_unused]] const FFDisplayServerResult* displayServer, FFBrightnessOptions* options, FFlist* result) { if (!IOAVServiceCreate || !IOAVServiceReadI2C || !IOAVServiceWriteI2C) { + FF_DEBUG("IOAVService is not available"); return "IOAVService is not available"; } FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = IO_OBJECT_NULL; if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("DCPAVServiceProxy"), &iterator) != kIOReturnSuccess) { + FF_DEBUG("IOServiceGetMatchingServices() failed"); return "IOServiceGetMatchingServices() failed"; } @@ -154,10 +158,12 @@ static IOOptionBits getSupportedTransactionType(void) { static const char* detectWithDdcci(const FFDisplayServerResult* displayServer, FFBrightnessOptions* options, FFlist* result) { if (!CGSServiceForDisplayNumber) { + FF_DEBUG("CGSServiceForDisplayNumber is not available"); return "CGSServiceForDisplayNumber is not available"; } IOOptionBits transactionType = getSupportedTransactionType(); if (transactionType == kIOI2CNoTransactionType) { + FF_DEBUG("No supported IOI2C transaction type found"); return "No supported IOI2C transaction type found"; } diff --git a/src/detection/brightness/brightness_linux.c b/src/detection/brightness/brightness_linux.c index 46769a6a9..cdc4b531c 100644 --- a/src/detection/brightness/brightness_linux.c +++ b/src/detection/brightness/brightness_linux.c @@ -206,8 +206,7 @@ FF_AUTO_CLOSE_FD int fd = open(path, O_RDWR | O_CLOEXEC); if (fd < 0) { - int error = errno; - FF_DEBUG("Brightness DDC/CI: failed to open cached bus %d (errno=%d: %s)", device, error, strerror(error)); + FF_DEBUG("Brightness DDC/CI: failed to open cached bus %d (errno=%d: %s)", device, errno, strerror(errno)); continue; } @@ -281,6 +280,7 @@ static const char* detectWithBacklight(FFlist* result) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir(backlightDirPath); if (dirp == nullptr) { + FF_DEBUG("opendir(\"%s\") failed: %s", backlightDirPath, strerror(errno)); return "Failed to open `/sys/class/backlight/`"; } diff --git a/src/detection/brightness/brightness_obsd.c b/src/detection/brightness/brightness_obsd.c index 2c9847c66..5cbafe344 100644 --- a/src/detection/brightness/brightness_obsd.c +++ b/src/detection/brightness/brightness_obsd.c @@ -1,4 +1,5 @@ #include "brightness.h" +#include "common/debug.h" #include "common/io.h" #include @@ -15,6 +16,7 @@ const char* ffDetectBrightness([[maybe_unused]] FFBrightnessOptions* options, FF if (devfd < 0) { if (errno == EACCES && i == '0') { + FF_DEBUG("open(%s) failed: %s", path, strerror(errno)); return "Permission denied when opening tty device"; } if (errno == ENOENT) { diff --git a/src/detection/btrfs/btrfs_linux.c b/src/detection/btrfs/btrfs_linux.c index 077b1d5dc..b88af815a 100644 --- a/src/detection/btrfs/btrfs_linux.c +++ b/src/detection/btrfs/btrfs_linux.c @@ -1,5 +1,6 @@ #include "btrfs.h" +#include "common/debug.h" #include "common/io.h" #include @@ -8,11 +9,13 @@ enum { uuidLen = (uint32_t) __builtin_strlen("00000000-0000-0000-0000-0000000000 static const char* enumerateDevices(FFBtrfsResult* item, int dfd, FFstrbuf* buffer) { int subfd = openat(dfd, "devices", O_RDONLY | O_CLOEXEC | O_DIRECTORY); if (subfd < 0) { + FF_DEBUG("openat(\"devices\") failed: %s", strerror(errno)); return "openat(\"/sys/fs/btrfs/UUID/devices\") == -1"; } FF_AUTO_CLOSE_DIR DIR* dirp = fdopendir(subfd); if (dirp == nullptr) { + FF_DEBUG("fdopendir(\"devices\") failed: %s", strerror(errno)); close(subfd); return "fdopendir(\"/sys/fs/btrfs/UUID/devices\") == nullptr"; } @@ -42,11 +45,13 @@ static const char* enumerateDevices(FFBtrfsResult* item, int dfd, FFstrbuf* buff static const char* enumerateFeatures(FFBtrfsResult* item, int dfd) { int subfd = openat(dfd, "features", O_RDONLY | O_CLOEXEC | O_DIRECTORY); if (subfd < 0) { + FF_DEBUG("openat(\"features\") failed: %s", strerror(errno)); return "openat(\"/sys/fs/btrfs/UUID/features\") == -1"; } FF_AUTO_CLOSE_DIR DIR* dirp = fdopendir(subfd); if (dirp == nullptr) { + FF_DEBUG("fdopendir(\"features\") failed: %s", strerror(errno)); return "fdopendir(\"/sys/fs/btrfs/UUID/features\") == nullptr"; } @@ -67,12 +72,14 @@ static const char* enumerateFeatures(FFBtrfsResult* item, int dfd) { static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buffer) { FF_AUTO_CLOSE_FD int subfd = openat(dfd, "allocation", O_RDONLY | O_CLOEXEC | O_PATH | O_DIRECTORY); if (subfd < 0) { + FF_DEBUG("openat(\"allocation\") failed: %s", strerror(errno)); return "openat(\"/sys/fs/btrfs/UUID/allocation\") == -1"; } if (ffReadFileBufferRelative(subfd, "global_rsv_size", buffer)) { item->globalReservationTotal = ffStrbufToUInt(buffer, 0); } else { + FF_DEBUG("ffReadFileBuffer(\"global_rsv_size\") failed"); return "ffReadFileBuffer(\"/sys/fs/btrfs/UUID/allocation/global_rsv_size\") == nullptr"; } @@ -124,6 +131,7 @@ static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buff const char* ffDetectBtrfs(FFlist* result) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/fs/btrfs/"); if (dirp == nullptr) { + FF_DEBUG("opendir(\"/sys/fs/btrfs\") failed: %s", strerror(errno)); return "opendir(\"/sys/fs/btrfs\") == nullptr"; } diff --git a/src/detection/camera/camera_android.c b/src/detection/camera/camera_android.c index abdbe3d9d..3a0d8a209 100644 --- a/src/detection/camera/camera_android.c +++ b/src/detection/camera/camera_android.c @@ -1,4 +1,5 @@ #include "camera.h" +#include "common/debug.h" #include #include @@ -48,11 +49,13 @@ const char* ffDetectCamera(FFlist* result) { // API 24, so linking it unconditionally in CMakeLists.txt is fine on every supported device. ACameraManager* manager = ACameraManager_create(); if (!manager) { + FF_DEBUG("ACameraManager_create() failed"); return "ACameraManager_create() failed"; } ACameraIdList* idList = nullptr; if (ACameraManager_getCameraIdList(manager, &idList) != ACAMERA_OK || !idList) { + FF_DEBUG("ACameraManager_getCameraIdList() failed"); ACameraManager_delete(manager); return "ACameraManager_getCameraIdList() failed"; } diff --git a/src/detection/camera/camera_linux.c b/src/detection/camera/camera_linux.c index 2fc8b129c..040c252c7 100644 --- a/src/detection/camera/camera_linux.c +++ b/src/detection/camera/camera_linux.c @@ -1,8 +1,10 @@ #include "camera.h" +#include "common/debug.h" #include "common/io.h" #include #include +#include #include #if FF_HAVE_LINUX_VIDEODEV2 @@ -26,6 +28,7 @@ const char* ffDetectCamera(FFlist* result) { if (errno == ENXIO) { continue; } + FF_DEBUG("Failed to open /dev/videoN: %s", strerror(errno)); return "Failed to open /dev/videoN"; } diff --git a/src/detection/chassis/chassis_apple.c b/src/detection/chassis/chassis_apple.c index b5a041dcf..b24a630c7 100644 --- a/src/detection/chassis/chassis_apple.c +++ b/src/detection/chassis/chassis_apple.c @@ -1,4 +1,5 @@ #include "chassis.h" +#include "common/debug.h" #include "detection/host/host.h" const char* ffDetectChassis(FFChassisResult* result) { @@ -11,7 +12,9 @@ const char* ffDetectChassis(FFChassisResult* result) { .uuid = ffStrbufCreate(), .vendor = ffStrbufCreate(), }; - if (ffDetectHost(&host) != nullptr) { + const char* hostError = ffDetectHost(&host); + if (hostError != nullptr) { + FF_DEBUG("ffDetectHost() failed: %s", hostError); return "Failed to detect host"; } diff --git a/src/detection/codec/codec_android.c b/src/detection/codec/codec_android.c index d4b465ec6..84a63a81a 100644 --- a/src/detection/codec/codec_android.c +++ b/src/detection/codec/codec_android.c @@ -1,6 +1,7 @@ #include "codec.h" #include "common/android/api.h" +#include "common/debug.h" #include "common/strutil.h" #include @@ -99,5 +100,6 @@ const char* ffDetectCodecNative(FFCodecOptions* options, FFlist* result /*list o // Reading the codec name is the only way to tell a hardware codec from a software one. Without // it there is nothing to report, and listing the codecs as if they were accelerated would be a // guess, so say why instead. + FF_DEBUG("AMediaCodec_getName() requires Android 9 (API 28)"); return "AMediaCodec_getName() requires Android 9 (API 28)"; } diff --git a/src/detection/codec/codec_linux.c b/src/detection/codec/codec_linux.c index f058744bb..2f67f4115 100644 --- a/src/detection/codec/codec_linux.c +++ b/src/detection/codec/codec_linux.c @@ -6,6 +6,7 @@ #if FF_HAVE_VA || FF_HAVE_VDPAU + #include "common/debug.h" #include "common/library.h" #include "common/mallocHelper.h" #include "common/strutil.h" @@ -14,6 +15,7 @@ #if FF_HAVE_VA #include + #include #include typedef struct FFVAData { @@ -227,6 +229,7 @@ static const char* detectCodecByVaDrm(FFVAData* vaData, FFCodecOptions* options, FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/dev/dri/"); if (dirp == nullptr) { + FF_DEBUG("opendir(/dev/dri/) failed: %s", strerror(errno)); return "opendir(/dev/dri/) failed"; } int drifd = dirfd(dirp); @@ -268,11 +271,13 @@ static const char* detectCodecByVaX11(FFVAData* vaData, FFCodecOptions* options, Display* x11Display = ffXOpenDisplay(nullptr); if (!x11Display) { + FF_DEBUG("XOpenDisplay() failed"); return "XOpenDisplay() failed"; } VADisplay display = ffvaGetDisplay(x11Display); if (!display) { + FF_DEBUG("vaGetDisplay() failed"); ffXCloseDisplay(x11Display); return "vaGetDisplay() failed"; } @@ -380,14 +385,18 @@ static const char* detectCodecByVdpau(FFCodecOptions* options, FFlist* result) { Display* x11Display = ffXOpenDisplay(nullptr); if (!x11Display) { + FF_DEBUG("XOpenDisplay() failed"); return "XOpenDisplay() failed"; } VdpDevice device = VDP_INVALID_HANDLE; VdpGetProcAddress* ffvdp_get_proc_address = nullptr; - if (ffvdp_device_create_x11(x11Display, ffXDefaultScreen(x11Display), &device, &ffvdp_get_proc_address) != VDP_STATUS_OK || + VdpStatus ffvdp_device_create_x11_status = ffvdp_device_create_x11(x11Display, ffXDefaultScreen(x11Display), &device, &ffvdp_get_proc_address); + if (ffvdp_device_create_x11_status != VDP_STATUS_OK || device == VDP_INVALID_HANDLE || ffvdp_get_proc_address == nullptr) { + FF_DEBUG("vdp_device_create_x11() failed: status=%d, device=%p, getProcAddress=%p", + ffvdp_device_create_x11_status, (void*) device, (void*) ffvdp_get_proc_address); ffXCloseDisplay(x11Display); return "vdp_device_create_x11() failed"; } @@ -398,6 +407,7 @@ static const char* detectCodecByVdpau(FFCodecOptions* options, FFlist* result) { ffvdp_get_proc_address(device, VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES, (void**) &ffvdp_decoder_query_capabilities) != VDP_STATUS_OK || ffvdp_device_destroy == nullptr || ffvdp_decoder_query_capabilities == nullptr) { + FF_DEBUG("vdp_device_create_x11() did not provide VDP_FUNC_ID_DEVICE_DESTROY / VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES"); if (ffvdp_device_destroy) { ffvdp_device_destroy(device); } @@ -459,6 +469,7 @@ const char* ffDetectCodecNative(FFCodecOptions* options, FFlist* result /* list } #endif + FF_DEBUG("Neither libva nor libvdpau could initialize a display"); return "Both libva and libvdpau fail to initialize"; } diff --git a/src/detection/cpu/cpu_apple.c b/src/detection/cpu/cpu_apple.c index bce7d55b2..2071af1fa 100644 --- a/src/detection/cpu/cpu_apple.c +++ b/src/detection/cpu/cpu_apple.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/apple/smc_temps.h" #include "common/strutil.h" @@ -53,15 +54,18 @@ static const char* detectFrequency(FFCPUResult* cpu) { FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceNameMatching("pmgr")); if (!entryDevice) { + FF_DEBUG("IOServiceGetMatchingService() failed"); return "IOServiceGetMatchingService() failed"; } if (!IOObjectConformsTo(entryDevice, "AppleARMIODevice")) { + FF_DEBUG("\"pmgr\" should conform to \"AppleARMIODevice\""); return "\"pmgr\" should conform to \"AppleARMIODevice\""; } FF_CFTYPE_AUTO_RELEASE CFDataRef freqProperty = (CFDataRef) IORegistryEntryCreateCFProperty(entryDevice, CFSTR("voltage-states5-sram"), kCFAllocatorDefault, kNilOptions); if (!freqProperty || CFGetTypeID(freqProperty) != CFDataGetTypeID()) { + FF_DEBUG("\"voltage-states5-sram\" in \"pmgr\" is not found"); return "\"voltage-states5-sram\" in \"pmgr\" is not found"; } @@ -69,6 +73,7 @@ static const char* detectFrequency(FFCPUResult* cpu) { // voltage-states1-sram stores ecores' CFIndex propLength = CFDataGetLength(freqProperty); if (propLength == 0 || propLength % (CFIndex) (sizeof(uint32_t) * 2) != 0) { + FF_DEBUG("Invalid \"voltage-states5-sram\" length"); return "Invalid \"voltage-states5-sram\" length"; } @@ -106,6 +111,7 @@ static const char* detectFrequency(FFCPUResult* cpu) { static const char* detectCoreCount(FFCPUResult* cpu) { uint32_t nPerfLevels = (uint32_t) ffSysctlGetInt("hw.nperflevels", 0); if (nPerfLevels <= 0) { + FF_DEBUG("sysctl(hw.nperflevels) failed"); return "sysctl(hw.nperflevels) failed"; } @@ -124,7 +130,9 @@ static const char* detectCoreCount(FFCPUResult* cpu) { } const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { - if (ffSysctlGetString("machdep.cpu.brand_string", &cpu->name) != nullptr) { + const char* error = ffSysctlGetString("machdep.cpu.brand_string", &cpu->name); + if (error != nullptr) { + FF_DEBUG("sysctlbyname(machdep.cpu.brand_string) failed: %s", error); return "sysctlbyname(machdep.cpu.brand_string) failed"; } diff --git a/src/detection/cpu/cpu_bsd.c b/src/detection/cpu/cpu_bsd.c index 085b01498..d671d8b6a 100644 --- a/src/detection/cpu/cpu_bsd.c +++ b/src/detection/cpu/cpu_bsd.c @@ -1,7 +1,10 @@ #include "cpu.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/strutil.h" +#include +#include #include #if __has_include() #include @@ -13,6 +16,7 @@ static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { if (options->tempSensor.length > 0) { temp = ffSysctlGetInt(options->tempSensor.chars, -999999); if (temp == -999999) { + FF_DEBUG("sysctlbyname(%s) failed: %s", options->tempSensor.chars, strerror(errno)); return "ffSysctlGetInt(options->tempSensor) failed"; } } else { @@ -21,6 +25,7 @@ static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { // Thermal zone temperature temp = ffSysctlGetInt("hw.acpi.thermal.tz0.temperature", -999999); if (temp == -999999) { + FF_DEBUG("Neither sysctlbyname(dev.cpu.0.temperature) nor sysctlbyname(hw.acpi.thermal.tz0.temperature) is readable: %s", strerror(errno)); return "ffSysctlGetInt(\"dev.cpu.0.temperature\" or \"hw.acpi.thermal.tz0.temperature\") failed"; } } @@ -32,7 +37,9 @@ static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { } const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { - if (ffSysctlGetString("hw.model", &cpu->name) != nullptr) { + const char* modelError = ffSysctlGetString("hw.model", &cpu->name); + if (modelError != nullptr) { + FF_DEBUG("sysctlbyname(hw.model) failed: %s", modelError); return "sysctlbyname(hw.model) failed"; } diff --git a/src/detection/cpu/cpu_haiku.c b/src/detection/cpu/cpu_haiku.c index 5ca06a284..b7c10e4fb 100644 --- a/src/detection/cpu/cpu_haiku.c +++ b/src/detection/cpu/cpu_haiku.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include @@ -6,18 +7,23 @@ const char* ffDetectCPUImpl([[maybe_unused]] const FFCPUOptions* options, FFCPUResult* cpu) { system_info sysInfo; - if (get_system_info(&sysInfo) != B_OK) { + status_t status = get_system_info(&sysInfo); + if (status != B_OK) { + FF_DEBUG("get_system_info() failed: %d", (int) status); return "get_system_info() failed"; } uint32 topoNodeCount = 0; get_cpu_topology_info(nullptr, &topoNodeCount); if (topoNodeCount == 0) { + FF_DEBUG("get_cpu_topology_info(nullptr) failed"); return "get_cpu_topology_info(nullptr) failed"; } FF_AUTO_FREE cpu_topology_node_info* topology = malloc(sizeof(*topology) * topoNodeCount); - if (get_cpu_topology_info(topology, &topoNodeCount) != B_OK) { + status_t topoStatus = get_cpu_topology_info(topology, &topoNodeCount); + if (topoStatus != B_OK) { + FF_DEBUG("get_cpu_topology_info(topology) failed: %d", (int) topoStatus); return "get_cpu_topology_info(topology) failed"; } diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index c9756a3bf..31c233103 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "common/debug.h" #include "common/io.h" #include "common/processing.h" #include "common/properties.h" @@ -8,6 +9,7 @@ #include #include +#include #include #include #include @@ -831,11 +833,13 @@ bool ffCPUQualcommSnapdragonToName(FFstrbuf* name, char* compatibles) { static const char* detectPhysicalCores(FFCPUResult* cpu) { int dfd = open("/sys/devices/system/cpu/", O_RDONLY | O_DIRECTORY | O_CLOEXEC); if (dfd < 0) { + FF_DEBUG("open(/sys/devices/system/cpu/) failed: %s", strerror(errno)); return "open(\"/sys/devices/system/cpu/\") failed"; } FF_AUTO_CLOSE_DIR DIR* dir = fdopendir(dfd); if (!dir) { + FF_DEBUG("fdopendir(/sys/devices/system/cpu/) failed: %s", strerror(errno)); close(dfd); return "fdopendir(dfd) failed"; } diff --git a/src/detection/cpu/cpu_nbsd.c b/src/detection/cpu/cpu_nbsd.c index d5ccbf230..f6cfd4362 100644 --- a/src/detection/cpu/cpu_nbsd.c +++ b/src/detection/cpu/cpu_nbsd.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/io.h" @@ -8,6 +9,8 @@ #include #include #include +#include +#include static void freePropDict(prop_dictionary_t* pdict) { assert(pdict != nullptr); @@ -20,11 +23,13 @@ static void freePropDict(prop_dictionary_t* pdict) { static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { FF_AUTO_CLOSE_FD int fd = open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed: %s", strerror(errno)); return "open(_PATH_SYSMON, O_RDONLY | O_CLOEXEC) failed"; } [[gnu::cleanup(freePropDict)]] prop_dictionary_t root = nullptr; if (prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &root) < 0) { + FF_DEBUG("prop_dictionary_recv_ioctl(ENVSYS_GETDICTIONARY) failed: %s", strerror(errno)); return "prop_dictionary_recv_ioctl(ENVSYS_GETDICTIONARY) failed"; } @@ -33,6 +38,7 @@ static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { if (options->tempSensor.length > 0) { array = prop_dictionary_get(root, options->tempSensor.chars); if (!array) { + FF_DEBUG("No temp data found in specified sensor"); return "No temp data found in specified sensor"; } } else { @@ -47,21 +53,25 @@ static const char* detectCpuTemp(const FFCPUOptions* options, double* current) { array = prop_dictionary_get(root, "acpitz0"); // Thermal Zones } if (!array) { + FF_DEBUG("No temp data found in root dictionary"); return "No temp data found in root dictionary"; } } if (prop_array_count(array) != 2) { + FF_DEBUG("Unexpected `xtemp0` data"); return "Unexpected `xtemp0` data"; } prop_dictionary_t dict = prop_array_get(array, 0); if (prop_object_type(dict) != PROP_TYPE_DICTIONARY) { + FF_DEBUG("Unexpected `xtemp0[0]`"); return "Unexpected `xtemp0[0]`"; } int temp = 0; // in µK if (!prop_dictionary_get_int(dict, "cur-value", &temp)) { + FF_DEBUG("Failed to get temperature"); return "Failed to get temperature"; } diff --git a/src/detection/cpu/cpu_obsd.c b/src/detection/cpu/cpu_obsd.c index 5583fe59f..1d692bb32 100644 --- a/src/detection/cpu/cpu_obsd.c +++ b/src/detection/cpu/cpu_obsd.c @@ -1,7 +1,9 @@ #include "cpu.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/strutil.h" +#include #include #include #include @@ -19,6 +21,7 @@ static const char* detectCPUTemp(const FFCPUOptions* options, FFCPUResult* cpu) if (errno == ENXIO) { continue; } + FF_DEBUG("sysctl(sensordev) failed: %s", strerror(errno)); return "sysctl(sensordev) failed"; } @@ -37,6 +40,7 @@ static const char* detectCPUTemp(const FFCPUOptions* options, FFCPUResult* cpu) size_t slen = sizeof(struct sensor); if (sysctl(mib, 5, &sensor, &slen, nullptr, 0) < 0) { if (errno != ENOENT) { + FF_DEBUG("sysctl(sensor) failed: %s", strerror(errno)); return "sysctl(sensor) failed"; } continue; @@ -50,11 +54,14 @@ static const char* detectCPUTemp(const FFCPUOptions* options, FFCPUResult* cpu) } } + FF_DEBUG("No sensor for CPU temp found"); return "No sensor for CPU temp found"; } const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { - if (ffSysctlGetString(CTL_HW, HW_MODEL, &cpu->name)) { + const char* error = ffSysctlGetString(CTL_HW, HW_MODEL, &cpu->name); + if (error) { + FF_DEBUG("sysctl(hw.model) failed: %s", error); return "sysctl(hw.model) failed"; } diff --git a/src/detection/cpu/cpu_sunos.c b/src/detection/cpu/cpu_sunos.c index 43b92c371..cbe24160e 100644 --- a/src/detection/cpu/cpu_sunos.c +++ b/src/detection/cpu/cpu_sunos.c @@ -1,4 +1,5 @@ #include "cpu.h" +#include "common/debug.h" #include "common/processing.h" #include "common/strutil.h" #include @@ -31,6 +32,7 @@ static const char* detectCPUTempByKstat(const FFCPUOptions* options, kstat_ctl_t } } + FF_DEBUG("Failed to find CPU temperature using kstat"); return "Failed to find CPU temperature using kstat"; } @@ -50,6 +52,7 @@ static const char* detectCPUTempByIpmiTool(FFCPUResult* cpu) { } } + FF_DEBUG("ipmitool sdr list failed to find CPU temperature"); return "ipmitool sdr list failed to find CPU temperature"; } @@ -101,15 +104,18 @@ static inline uint16_t countTypeId(kstat_ctl_t* kc, const char* type) { const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) { [[gnu::cleanup(kstatFreeWrap)]] kstat_ctl_t* kc = kstat_open(); if (!kc) { + FF_DEBUG("kstat_open() failed"); return "kstat_open() failed"; } kstat_t* ks = kstat_lookup(kc, "cpu_info", -1, nullptr); if (!ks) { + FF_DEBUG("kstat_lookup() failed"); return "kstat_lookup() failed"; } if (kstat_read(kc, ks, nullptr) < 0) { + FF_DEBUG("kstat_read() failed"); return "kstat_read() failed"; } diff --git a/src/detection/cpucache/cpucache_apple.c b/src/detection/cpucache/cpucache_apple.c index 50aec0232..f1ed73bc3 100644 --- a/src/detection/cpucache/cpucache_apple.c +++ b/src/detection/cpucache/cpucache_apple.c @@ -1,4 +1,5 @@ #include "cpucache.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/strutil.h" @@ -6,6 +7,7 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result) { // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_system_capabilities#3901385 uint32_t nPerfLevels = (uint32_t) ffSysctlGetInt("hw.nperflevels", 0); if (nPerfLevels <= 0) { + FF_DEBUG("sysctl(hw.nperflevels) failed"); return "sysctl(hw.nperflevels) failed"; } diff --git a/src/detection/cpucache/cpucache_linux.c b/src/detection/cpucache/cpucache_linux.c index a55184955..ff0551cbe 100644 --- a/src/detection/cpucache/cpucache_linux.c +++ b/src/detection/cpucache/cpucache_linux.c @@ -1,11 +1,16 @@ #include "cpucache.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" +#include +#include + static const char* parseCpuCacheIndex(FFstrbuf* path, FFCPUCacheResult* result, FFstrbuf* buffer, FFstrbuf* added) { uint32_t baseLen = path->length; ffStrbufAppendS(path, "/level"); if (!ffReadFileBuffer(path->chars, buffer)) { + FF_DEBUG("Failed to read \"%s\"", path->chars); return "ffReadFileBuffer(\"/sys/devices/system/cpu/cpuX/cache/indexX/level\") == nullptr"; } @@ -17,6 +22,7 @@ static const char* parseCpuCacheIndex(FFstrbuf* path, FFCPUCacheResult* result, ffStrbufSubstrBefore(path, baseLen); ffStrbufAppendS(path, "/size"); if (!ffReadFileBuffer(path->chars, buffer)) { + FF_DEBUG("Failed to read \"%s\"", path->chars); return "ffReadFileBuffer(\"/sys/devices/system/cpu/cpuX/cache/indexX/size\") == nullptr"; } @@ -28,6 +34,7 @@ static const char* parseCpuCacheIndex(FFstrbuf* path, FFCPUCacheResult* result, ffStrbufSubstrBefore(path, baseLen); ffStrbufAppendS(path, "/type"); if (!ffReadFileBuffer(path->chars, buffer)) { + FF_DEBUG("Failed to read \"%s\"", path->chars); return "ffReadFileBuffer(\"/sys/devices/system/cpu/cpuX/cache/indexX/type\") == nullptr"; } ffStrbufTrimRightSpace(buffer); @@ -47,6 +54,7 @@ static const char* parseCpuCacheIndex(FFstrbuf* path, FFCPUCacheResult* result, cacheType = FF_CPU_CACHE_TYPE_TRACE; break; default: + FF_DEBUG("Unknown cache type \"%c\"", buffer->chars[0]); return "unknown cache type"; } @@ -62,6 +70,7 @@ static const char* parseCpuCacheIndex(FFstrbuf* path, FFCPUCacheResult* result, ffStrbufClear(buffer); ffStrbufAppendC(buffer, '['); if (!ffAppendFileBuffer(path->chars, buffer)) { + FF_DEBUG("Failed to read \"%s\"", path->chars); return "ffAppendFileBuffer(\"/sys/devices/system/cpu/cpuX/cache/indexX/shared_cpu_list\") == nullptr"; } ffStrbufTrimRightSpace(buffer); @@ -82,6 +91,7 @@ static const char* parseCpuCache(FFstrbuf* path, FFCPUCacheResult* result, FFstr uint32_t baseLen = path->length; FF_AUTO_CLOSE_DIR DIR* pathCacheDir = opendir(path->chars); if (!pathCacheDir) { + FF_DEBUG("opendir(\"%s\") failed: %s", path->chars, strerror(errno)); return "opendir(\"/sys/devices/system/cpu/cpuX/cache/\") == nullptr"; } @@ -108,6 +118,7 @@ const char* ffDetectCPUCache(FFCPUCacheResult* result) { uint32_t baseLen = path.length; FF_AUTO_CLOSE_DIR DIR* pathCpuDir = opendir(path.chars); if (!pathCpuDir) { + FF_DEBUG("opendir(\"%s\") failed: %s", path.chars, strerror(errno)); return "opendir(\"/sys/devices/system/cpu/\") == nullptr"; } diff --git a/src/detection/cpuusage/cpuusage_apple.c b/src/detection/cpuusage/cpuusage_apple.c index bdec58aa1..8081b8cfa 100644 --- a/src/detection/cpuusage/cpuusage_apple.c +++ b/src/detection/cpuusage/cpuusage_apple.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "common/debug.h" #include "detection/cpuusage/cpuusage.h" #include @@ -11,9 +12,11 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { mach_msg_type_number_t numCpuInfo; if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUs, &cpuInfo, &numCpuInfo) != KERN_SUCCESS) { + FF_DEBUG("host_processor_info() failed"); return "host_processor_info() failed"; } if (numCPUs * CPU_STATE_MAX != numCpuInfo) { + FF_DEBUG("Unexpected host_processor_info() result"); return "Unexpected host_processor_info() result"; } diff --git a/src/detection/cpuusage/cpuusage_bsd.c b/src/detection/cpuusage/cpuusage_bsd.c index d3c43345c..96fc977e4 100644 --- a/src/detection/cpuusage/cpuusage_bsd.c +++ b/src/detection/cpuusage/cpuusage_bsd.c @@ -1,10 +1,13 @@ #include "detection/cpuusage/cpuusage.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include #include #include #include +#include +#include #if __OpenBSD__ || __NetBSD__ #include @@ -19,10 +22,12 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { int ctls[] = { CTL_KERN, KERN_CP_TIME }; #endif if (sysctl(ctls, 2, nullptr, &neededLength, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_CPTIME}, 2, nullptr) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_CPTIME}, 2, nullptr) failed"; } #else if (sysctlbyname("kern.cp_times", nullptr, &neededLength, nullptr, 0) != 0) { + FF_DEBUG("sysctlbyname(kern.cp_times, nullptr) failed: %s", strerror(errno)); return "sysctlbyname(kern.cp_times, nullptr) failed"; } #endif @@ -34,10 +39,12 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { #if __OpenBSD__ || __NetBSD__ if (sysctl(ctls, 2, cpTimes, &neededLength, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_CPTIME}, 2, cpTimes) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_CPTIME}, 2, nullptr) failed"; } #else if (sysctlbyname("kern.cp_times", cpTimes, &neededLength, nullptr, 0) != 0) { + FF_DEBUG("sysctlbyname(kern.cp_times, cpTimes) failed: %s", strerror(errno)); return "sysctlbyname(kern.cp_times, cpTime) failed"; } #endif diff --git a/src/detection/cpuusage/cpuusage_haiku.c b/src/detection/cpuusage/cpuusage_haiku.c index 35fba5949..7893ecbae 100644 --- a/src/detection/cpuusage/cpuusage_haiku.c +++ b/src/detection/cpuusage/cpuusage_haiku.c @@ -1,5 +1,6 @@ #include "fastfetch.h" #include "detection/cpuusage/cpuusage.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include @@ -7,11 +8,13 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { system_info sysInfo; if (get_system_info(&sysInfo) != B_OK) { + FF_DEBUG("get_system_info() failed"); return "get_system_info() failed"; } FF_AUTO_FREE cpu_info* cpuInfo = malloc(sizeof(*cpuInfo) * sysInfo.cpu_count); if (get_cpu_info(0, sysInfo.cpu_count, cpuInfo) != B_OK) { + FF_DEBUG("get_cpu_info() failed"); return "get_cpu_info() failed"; } diff --git a/src/detection/cpuusage/cpuusage_linux.c b/src/detection/cpuusage/cpuusage_linux.c index e4711fff9..9f2bbda3f 100644 --- a/src/detection/cpuusage/cpuusage_linux.c +++ b/src/detection/cpuusage/cpuusage_linux.c @@ -1,5 +1,6 @@ #include "fastfetch.h" #include "detection/cpuusage/cpuusage.h" +#include "common/debug.h" #include "common/io.h" #include @@ -9,6 +10,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { char buf[PROC_FILE_BUFFSIZ]; ssize_t nRead = ffReadFileData("/proc/stat", ARRAY_SIZE(buf) - 1, buf); if (nRead < 0) { + FF_DEBUG("Reading \"/proc/stat\" failed: %s", strerror(errno)); #ifdef __ANDROID__ return "Accessing \"/proc/stat\" is restricted on Android O+"; #else @@ -20,6 +22,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { // Skip first line char* start = nullptr; if ((start = strchr(buf, '\n')) == nullptr) { + FF_DEBUG("skip first line failed"); return "skip first line failed"; } ++start; diff --git a/src/detection/cpuusage/cpuusage_sunos.c b/src/detection/cpuusage/cpuusage_sunos.c index a10f09ed7..48cdf8363 100644 --- a/src/detection/cpuusage/cpuusage_sunos.c +++ b/src/detection/cpuusage/cpuusage_sunos.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "common/debug.h" #include "detection/cpuusage/cpuusage.h" #include @@ -14,6 +15,7 @@ static inline void kstatFreeWrap(kstat_ctl_t** pkc) { const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { [[gnu::cleanup(kstatFreeWrap)]] kstat_ctl_t* kc = kstat_open(); if (!kc) { + FF_DEBUG("kstat_open() failed"); return "kstat_open() failed"; } diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index e93b604d9..6426a25b6 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -1,6 +1,7 @@ #include "de.h" #include "common/dbus.h" +#include "common/debug.h" #include "common/io.h" #include "common/library.h" #include "common/parsing.h" @@ -43,12 +44,14 @@ static const char* getGnomeByDbus([[maybe_unused]] FFstrbuf* result) { #ifdef FF_HAVE_DBUS FF_DBUS_AUTO_DESTROY_DATA FFDBusData dbus = {}; if (ffDBusLoadData(DBUS_BUS_SESSION, &dbus) != nullptr) { + FF_DEBUG("ffDBusLoadData() failed"); return "ffDBusLoadData() failed"; } ffDBusGetPropertyString(&dbus, "org.gnome.Shell", "/org/gnome/Shell", "org.gnome.Shell", "ShellVersion", result); return nullptr; #else // FF_HAVE_DBUS + FF_DEBUG("ffDBusLoadData() failed: dbus support not compiled in"); return "ffDBusLoadData() failed: dbus support not compiled in"; #endif // FF_HAVE_DBUS } @@ -103,6 +106,7 @@ static const char* getXfce4ByLib(FFstrbuf* result) { return nullptr; #else FF_UNUSED(result); + FF_DEBUG("dlopen is disabled"); return "dlopen is disabled"; #endif } @@ -164,6 +168,7 @@ static const char* getTrinity(FFstrbuf* result, [[maybe_unused]] FFDEOptions* op FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("tde-config", &path); if (error) { + FF_DEBUG("Failed to find tde-config path"); return "Failed to find tde-config path"; } @@ -180,6 +185,7 @@ static const char* getTrinity(FFstrbuf* result, [[maybe_unused]] FFDEOptions* op return nullptr; } + FF_DEBUG("All methods failed"); return "All methods failed"; } @@ -197,6 +203,7 @@ static const char* getCosmic(FFstrbuf* result, [[maybe_unused]] FFDEOptions* opt return nullptr; } + FF_DEBUG("All methods failed"); return "All methods failed"; } @@ -204,27 +211,32 @@ static const char* getEnlightenmentByDbus([[maybe_unused]] FFstrbuf* result) { #ifdef FF_HAVE_DBUS FF_DBUS_AUTO_DESTROY_DATA FFDBusData dbus = {}; if (ffDBusLoadData(DBUS_BUS_SESSION, &dbus) != nullptr) { + FF_DEBUG("ffDBusLoadData() failed"); return "ffDBusLoadData() failed"; } DBusMessage* reply = ffDBusGetMethodReply(&dbus, "org.enlightenment.wm.service", "/org/enlightenment/wm/RemoteObject", "org.enlightenment.wm.Core", "Version", nullptr, nullptr); if (!reply) { + FF_DEBUG("ffDBusGetMethodReply() failed"); return "ffDBusGetMethodReply() failed"; } DBusMessageIter rootIterator; if (!dbus.lib->ffdbus_message_iter_init(reply, &rootIterator)) { dbus.lib->ffdbus_message_unref(reply); + FF_DEBUG("dbus_message_iter_init() failed"); return "dbus_message_iter_init() failed"; } if (!ffDBusGetString(&dbus, &rootIterator, result)) { dbus.lib->ffdbus_message_unref(reply); + FF_DEBUG("ffDBusGetString() failed"); return "ffDBusGetString() failed"; } dbus.lib->ffdbus_message_unref(reply); return nullptr; #else // FF_HAVE_DBUS + FF_DEBUG("ffDBusLoadData() failed: dbus support not compiled in"); return "ffDBusLoadData() failed: dbus support not compiled in"; #endif // FF_HAVE_DBUS } @@ -241,6 +253,7 @@ static void getEnlightenment(FFstrbuf* result, [[maybe_unused]] FFDEOptions* opt } const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options) { if (!instance.config.general.detectVersion) { + FF_DEBUG("Disabled by config"); return "Disabled by config"; } @@ -270,6 +283,7 @@ const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOpti } else if (ffStrbufEqualS(deName, FF_DE_PRETTY_ENLIGHTENMENT)) { getEnlightenment(result, options); } else { + FF_DEBUG("Unsupported DE"); return "Unsupported DE"; } return nullptr; diff --git a/src/detection/disk/disk_bsd.c b/src/detection/disk/disk_bsd.c index aaa69b294..5807c1d28 100644 --- a/src/detection/disk/disk_bsd.c +++ b/src/detection/disk/disk_bsd.c @@ -1,7 +1,9 @@ #include "disk.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include "common/strutil.h" +#include #include #include #include @@ -28,16 +30,19 @@ static const char* detectFsLabel(struct statfs* fs, FFDisk* disk) { static struct gclass* cLabels; if (!cLabels) { if (geomTree.lg_ident) { + FF_DEBUG("Previous geom_gettree() failed"); return "Previous geom_gettree() failed"; } if (geom_gettree(&geomTree) < 0) { + FF_DEBUG("geom_gettree() failed"); geomTree.lg_ident = (void*) (intptr_t) -1; return "geom_gettree() failed"; } for (cLabels = geomTree.lg_class.lh_first; cLabels && !ffStrEquals(cLabels->lg_name, "LABEL"); cLabels = cLabels->lg_class.le_next); if (!cLabels) { + FF_DEBUG("Class LABEL is not found"); return "Class LABEL is not found"; } } @@ -129,11 +134,13 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { #ifndef __NetBSD__ int size = getfsstat(nullptr, 0, MNT_WAIT); if (size <= 0) { + FF_DEBUG("getfsstat(nullptr, 0, MNT_WAIT) failed: %s", strerror(errno)); return "getfsstat(nullptr, 0, MNT_WAIT) failed"; } #else int size = getvfsstat(nullptr, 0, ST_WAIT); if (size <= 0) { + FF_DEBUG("getvfsstat(nullptr, 0, ST_WAIT) failed: %s", strerror(errno)); return "getvfsstat(nullptr, 0, ST_WAIT) failed"; } #endif @@ -141,10 +148,12 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { FF_AUTO_FREE struct statfs* buf = malloc(sizeof(*buf) * (unsigned) size); #ifndef __NetBSD__ if (getfsstat(buf, (int) (sizeof(*buf) * (unsigned) size), MNT_NOWAIT) <= 0) { + FF_DEBUG("getfsstat(buf, size, MNT_NOWAIT) failed: %s", strerror(errno)); return "getfsstat(buf, size, MNT_NOWAIT) failed"; } #else if (getvfsstat(buf, sizeof(*buf) * (unsigned) size, ST_NOWAIT) <= 0) { + FF_DEBUG("getvfsstat(buf, size, ST_NOWAIT) failed: %s", strerror(errno)); return "getvfsstat(buf, size, ST_NOWAIT) failed"; } #endif diff --git a/src/detection/disk/disk_linux.c b/src/detection/disk/disk_linux.c index bb1a69512..d413f6e22 100644 --- a/src/detection/disk/disk_linux.c +++ b/src/detection/disk/disk_linux.c @@ -1,5 +1,6 @@ #include "disk.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -285,6 +286,7 @@ static void detectStats(FFDisk* disk) { const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks) { FILE* mountsFile = setmntent("/proc/mounts", "r"); if (mountsFile == nullptr) { + FF_DEBUG("setmntent(\"/proc/mounts\", \"r\") failed: %s", strerror(errno)); return "setmntent(\"/proc/mounts\", \"r\") == nullptr"; } diff --git a/src/detection/diskio/diskio_apple.c b/src/detection/diskio/diskio_apple.c index c389cb2c4..2cb2b9cb6 100644 --- a/src/detection/diskio/diskio_apple.c +++ b/src/detection/diskio/diskio_apple.c @@ -1,4 +1,5 @@ #include "diskio.h" +#include "common/debug.h" #include "common/apple/cf_helpers.h" #include @@ -11,6 +12,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = 0; if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOBlockStorageDriverClass), &iterator) != KERN_SUCCESS) { + FF_DEBUG("IOServiceGetMatchingServices() failed"); return "IOServiceGetMatchingServices() failed"; } diff --git a/src/detection/diskio/diskio_bsd.c b/src/detection/diskio/diskio_bsd.c index 495d1a95a..c47503fb1 100644 --- a/src/detection/diskio/diskio_bsd.c +++ b/src/detection/diskio/diskio_bsd.c @@ -2,6 +2,7 @@ #if __has_include() + #include "common/debug.h" #include "common/strutil.h" #include @@ -11,18 +12,24 @@ #include #include + #include + #include + const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { [[gnu::cleanup(geom_deletetree)]] struct gmesh geomTree = {}; if (geom_gettree(&geomTree) < 0) { + FF_DEBUG("geom_gettree() failed: %s", strerror(errno)); return "geom_gettree() failed"; } if (geom_stats_open() < 0) { + FF_DEBUG("geom_stats_open() failed: %s", strerror(errno)); return "geom_stats_open() failed"; } void* snap = geom_stats_snapshot_get(); if (!snap) { + FF_DEBUG("geom_stats_snapshot_get() returned null"); return "geom_stats_snapshot_get() failed"; } @@ -74,11 +81,15 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { #else + #include "common/debug.h" + #include #include + #include const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { if (checkversion() < 0) { + FF_DEBUG("checkversion() failed: %s", strerror(errno)); return "checkversion() failed"; } @@ -86,6 +97,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { .dinfo = (struct devinfo*) calloc(1, sizeof(struct devinfo)), }; if (getdevs(&stats) < 0) { + FF_DEBUG("getdevs() failed: %s", strerror(errno)); return "getdevs() failed"; } diff --git a/src/detection/diskio/diskio_linux.c b/src/detection/diskio/diskio_linux.c index 327e75b6d..6a07e75bc 100644 --- a/src/detection/diskio/diskio_linux.c +++ b/src/detection/diskio/diskio_linux.c @@ -1,4 +1,5 @@ #include "diskio.h" +#include "common/debug.h" #include "common/io.h" #include "common/properties.h" #include "common/strutil.h" @@ -56,10 +57,12 @@ static const char* parseDiskIOCounters(int dfd, const char* devName, FFlist* res char sysBlockStat[PROC_FILE_BUFFSIZ]; ssize_t fileSize = ffReadFileDataRelative(dfd, "stat", ARRAY_SIZE(sysBlockStat) - 1, sysBlockStat); if (fileSize <= 0) { + FF_DEBUG("failed to read stat file"); return "failed to read stat file"; } sysBlockStat[fileSize] = '\0'; if (sscanf(sysBlockStat, "%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u%" PRIu64 "%*u", &nRead, §orRead, &nWritten, §orWritten) <= 0) { + FF_DEBUG("invalid stat file format"); return "invalid stat file format"; } } @@ -78,6 +81,7 @@ static const char* parseDiskIOCounters(int dfd, const char* devName, FFlist* res const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { FF_AUTO_CLOSE_DIR DIR* sysBlockDirp = opendir("/sys/block/"); if (sysBlockDirp == nullptr) { + FF_DEBUG("opendir(\"/sys/block/\") failed: %s", strerror(errno)); return "opendir(\"/sys/block/\") == nullptr"; } diff --git a/src/detection/diskio/diskio_nbsd.c b/src/detection/diskio/diskio_nbsd.c index c8835bf06..22eba546a 100644 --- a/src/detection/diskio/diskio_nbsd.c +++ b/src/detection/diskio/diskio_nbsd.c @@ -1,8 +1,12 @@ #include "diskio.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" #include "common/mallocHelper.h" +#include +#include + #include #include @@ -10,6 +14,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { int mib[] = { CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl) }; size_t len; if (sysctl(mib, ARRAY_SIZE(mib), nullptr, &len, nullptr, 0) < 0) { + FF_DEBUG("sysctl({HW_IOSTATS}, nullptr) failed: %s", strerror(errno)); return "sysctl({HW_IOSTATS}, nullptr) failed"; } uint32_t nDrive = (uint32_t) (len / sizeof(struct io_sysctl)); @@ -17,6 +22,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { FF_AUTO_FREE struct io_sysctl* stats = malloc(len); if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, nullptr, 0) < 0) { + FF_DEBUG("sysctl({HW_IOSTATS}, stats) failed: %s", strerror(errno)); return "sysctl({HW_IOSTATS}, stats) failed"; } diff --git a/src/detection/diskio/diskio_obsd.c b/src/detection/diskio/diskio_obsd.c index c367dcb98..e3d539a37 100644 --- a/src/detection/diskio/diskio_obsd.c +++ b/src/detection/diskio/diskio_obsd.c @@ -1,7 +1,9 @@ #include "diskio.h" +#include "common/debug.h" #include "common/strutil.h" #include "common/mallocHelper.h" +#include #include #include @@ -9,6 +11,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { int mib[] = { CTL_HW, HW_DISKSTATS }; size_t len; if (sysctl(mib, ARRAY_SIZE(mib), nullptr, &len, nullptr, 0) < 0) { + FF_DEBUG("sysctl({HW_DISKSTATS}, nullptr) failed: %s", strerror(errno)); return "sysctl({HW_DISKSTATS}, nullptr) failed"; } uint32_t nDrive = (uint32_t) (len / sizeof(struct diskstats)); @@ -16,6 +19,7 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { FF_AUTO_FREE struct diskstats* stats = malloc(len); if (sysctl(mib, ARRAY_SIZE(mib), stats, &len, nullptr, 0) < 0) { + FF_DEBUG("sysctl({HW_DISKSTATS}, stats) failed: %s", strerror(errno)); return "sysctl({HW_DISKSTATS}, stats) failed"; } diff --git a/src/detection/diskio/diskio_sunos.c b/src/detection/diskio/diskio_sunos.c index c79e3daea..d21744e18 100644 --- a/src/detection/diskio/diskio_sunos.c +++ b/src/detection/diskio/diskio_sunos.c @@ -1,4 +1,5 @@ #include "diskio.h" +#include "common/debug.h" #include "common/strutil.h" #include @@ -12,6 +13,7 @@ static inline void kstatFreeWrap(kstat_ctl_t** pkc) { const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options) { [[gnu::cleanup(kstatFreeWrap)]] kstat_ctl_t* kc = kstat_open(); if (!kc) { + FF_DEBUG("kstat_open() failed"); return "kstat_open() failed"; } diff --git a/src/detection/gamepad/gamepad_linux.c b/src/detection/gamepad/gamepad_linux.c index 2c2e10587..83f670070 100644 --- a/src/detection/gamepad/gamepad_linux.c +++ b/src/detection/gamepad/gamepad_linux.c @@ -1,4 +1,5 @@ #include "gamepad.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -65,6 +66,7 @@ static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path) { const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/input/"); if (dirp == nullptr) { + FF_DEBUG("opendir(\"/sys/class/input/\") failed: %s", strerror(errno)); return "opendir(\"/sys/class/input/\") == nullptr"; } diff --git a/src/detection/gpu/gpu_android.c b/src/detection/gpu/gpu_android.c index f25756b4c..2bae2dc7e 100644 --- a/src/detection/gpu/gpu_android.c +++ b/src/detection/gpu/gpu_android.c @@ -1,4 +1,5 @@ #include "gpu.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -51,5 +52,6 @@ double ffGPUDetectTempFromTZ(void) { const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) { FF_UNUSED(options, gpus); + FF_DEBUG("No permission. Fallbacks to Vulkan, OpenCL or OpenGL instead"); return "No permission. Fallbacks to Vulkan, OpenCL or OpenGL instead"; } diff --git a/src/detection/gpu/gpu_apple.c b/src/detection/gpu/gpu_apple.c index f3775bc5a..bc4b5119f 100644 --- a/src/detection/gpu/gpu_apple.c +++ b/src/detection/gpu/gpu_apple.c @@ -1,6 +1,7 @@ #include "gpu.h" #include "common/apple/cf_helpers.h" #include "common/apple/smc_temps.h" +#include "common/debug.h" #include @@ -58,21 +59,25 @@ static const char* detectFrequency(FFGPUResult* gpu) { FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceNameMatching("pmgr")); if (!entryDevice) { + FF_DEBUG("IOServiceGetMatchingServices() failed"); return "IOServiceGetMatchingServices() failed"; } if (!IOObjectConformsTo(entryDevice, "AppleARMIODevice")) { + FF_DEBUG("\"pmgr\" should conform to \"AppleARMIODevice\""); return "\"pmgr\" should conform to \"AppleARMIODevice\""; } FF_CFTYPE_AUTO_RELEASE CFDataRef freqProperty = (CFDataRef) IORegistryEntryCreateCFProperty(entryDevice, CFSTR("voltage-states9-sram"), kCFAllocatorDefault, kNilOptions); if (!freqProperty || CFGetTypeID(freqProperty) != CFDataGetTypeID()) { + FF_DEBUG("\"voltage-states9-sram\" in \"pmgr\" is not found"); return "\"voltage-states9-sram\" in \"pmgr\" is not found"; } // voltage-states9-sram stores supported pairs of gpu from the lowest to the highest CFIndex propLength = CFDataGetLength(freqProperty); if (propLength == 0 || propLength % (CFIndex) (sizeof(uint32_t) * 2) != 0) { + FF_DEBUG("Invalid \"voltage-states9-sram\" length"); return "Invalid \"voltage-states9-sram\" length"; } @@ -101,6 +106,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) { CFMutableDictionaryRef matches = IOServiceMatching(kIOAcceleratorClassName); CFDictionaryAddValue(matches, CFSTR("IOMatchCategory"), CFSTR(kIOAcceleratorClassName)); if (IOServiceGetMatchingServices(MACH_PORT_NULL, matches, &iterator) != kIOReturnSuccess) { + FF_DEBUG("IOServiceGetMatchingServices() failed"); return "IOServiceGetMatchingServices() failed"; } } diff --git a/src/detection/gpu/gpu_bsd.c b/src/detection/gpu/gpu_bsd.c index 64e1a74ec..8be6416b3 100644 --- a/src/detection/gpu/gpu_bsd.c +++ b/src/detection/gpu/gpu_bsd.c @@ -1,8 +1,10 @@ #include "gpu.h" #include "gpu_driver_specific.h" +#include "common/debug.h" #include "common/io.h" +#include #include #include #if __has_include() @@ -14,6 +16,7 @@ static const char* detectByPci(const FFGPUOptions* options, FFlist* gpus) { FF_AUTO_CLOSE_FD int fd = open("/dev/pci", O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(\"/dev/pci\") failed: %s", strerror(errno)); return "open(\"/dev/pci\", O_RDONLY | O_CLOEXEC, 0) failed"; } @@ -31,10 +34,12 @@ static const char* detectByPci(const FFGPUOptions* options, FFlist* gpus) { }; if (ioctl(fd, PCIOCGETCONF, &pcio) < 0) { + FF_DEBUG("ioctl(PCIOCGETCONF) failed: %s", strerror(errno)); return "ioctl(fd, PCIOCGETCONF, &pc) failed"; } if (pcio.status == PCI_GETCONF_ERROR) { + FF_DEBUG("ioctl(fd, PCIOCGETCONF, &pc) returned error"); return "ioctl(fd, PCIOCGETCONF, &pc) returned error"; } diff --git a/src/detection/gpu/gpu_haiku.c b/src/detection/gpu/gpu_haiku.c index 6d2bf7d3f..7ea91c3b4 100644 --- a/src/detection/gpu/gpu_haiku.c +++ b/src/detection/gpu/gpu_haiku.c @@ -1,11 +1,16 @@ #include "gpu.h" +#include "common/debug.h" #include "common/io.h" +#include +#include + #include const char* ffDetectGPUImpl([[maybe_unused]] const FFGPUOptions* options, FFlist* gpus) { FF_AUTO_CLOSE_FD int pokefd = open(POKE_DEVICE_FULLNAME, O_RDWR | O_CLOEXEC); if (pokefd < 0) { + FF_DEBUG("open(%s) failed: %s", POKE_DEVICE_FULLNAME, strerror(errno)); return "open(POKE_DEVICE_FULLNAME) failed"; } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index d812e08b7..a594f7455 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -1,4 +1,5 @@ #include "detection/gpu/gpu.h" +#include "common/debug.h" #include "common/io.h" #include "common/FFstrbuf.h" #include "common/strutil.h" @@ -57,6 +58,7 @@ static bool detectDriverFromSysfs(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* sprintf(path, "/sys/class/drm/%s/device/drm", drmCardKey); FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path); if (!dirp) { + FF_DEBUG("opendir(%s) failed: %s", path, strerror(errno)); return "Failed to open `/sys/class/drm/{drmCardKey}/device/drm`"; } @@ -68,6 +70,7 @@ static bool detectDriverFromSysfs(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* return nullptr; } } + FF_DEBUG("Failed to find render device"); return "Failed to find render device"; } @@ -214,6 +217,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, ffStrbufAppendS(buffer, drmKey); FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(%s) failed: %s", buffer->chars, strerror(errno)); return "Failed to open drm device"; } @@ -222,6 +226,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, } else if (ffStrbufEqualS(&gpu->driver, "i915")) { return ffDrmDetectI915(gpu, fd); } + FF_DEBUG("Unknown Intel GPU driver"); return "Unknown Intel GPU driver"; } @@ -257,6 +262,7 @@ static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey ffStrbufAppendS(buffer, drmKey); FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC); if (fd < 0) { + FF_DEBUG("open(%s) failed: %s", buffer->chars, strerror(errno)); return "Failed to open drm device"; } @@ -336,6 +342,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf uint32_t vendorId, deviceId, subVendorId, subDeviceId; uint8_t classId, subclassId; if (sscanf(buffer->chars + strlen("pci:"), "v%8" SCNx32 "d%8" SCNx32 "sv%8" SCNx32 "sd%8" SCNx32 "bc%2" SCNx8 "sc%2" SCNx8, &vendorId, &deviceId, &subVendorId, &subDeviceId, &classId, &subclassId) != 6) { + FF_DEBUG("Failed to parse pci modalias"); return "Failed to parse pci modalias"; } @@ -348,6 +355,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf if (drmKey) { ssize_t pathLength = readlink(deviceDir->chars, pciPath, ARRAY_SIZE(pciPath) - 1); if (pathLength <= 0) { + FF_DEBUG("readlink(%s) failed: %s", deviceDir->chars, strerror(errno)); return "Unable to get PCI device path"; } pciPath[pathLength] = '\0'; @@ -365,6 +373,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf uint32_t pciDomain, pciBus, pciDevice, pciFunc; if (sscanf(pPciPath, "%" SCNx32 ":%" SCNx32 ":%" SCNx32 ".%" SCNx32, &pciDomain, &pciBus, &pciDevice, &pciFunc) != 4) { + FF_DEBUG("Invalid PCI device path"); return "Invalid PCI device path"; } @@ -517,6 +526,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf static const char* detectOf(FFlist* gpus, FFstrbuf* buffer, FFstrbuf* drmDir, const char* drmKey) { char compatible[256]; // vendor,model-name if (sscanf(buffer->chars + strlen("of:"), "NgpuT%*[^C]C%255[^C]", compatible) != 1) { + FF_DEBUG("Failed to parse of modalias or not a GPU device"); return "Failed to parse of modalias or not a GPU device"; } @@ -573,6 +583,7 @@ static const char* drmDetectGPUs(const FFGPUOptions* options, FFlist* gpus) { FF_AUTO_CLOSE_DIR DIR* dir = opendir(drmDir.chars); if (dir == nullptr) { + FF_DEBUG("opendir(%s) failed: %s", drmDir.chars, strerror(errno)); return "Failed to open `/sys/class/drm/`"; } @@ -612,6 +623,7 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pciDirPath); if (dirp == nullptr) { + FF_DEBUG("opendir(%s) failed: %s", pciDirPath, strerror(errno)); return "Failed to open `/sys/bus/pci/devices/`"; } diff --git a/src/detection/gpu/gpu_nbsd.c b/src/detection/gpu/gpu_nbsd.c index e3d04c14e..5dd2713a7 100644 --- a/src/detection/gpu/gpu_nbsd.c +++ b/src/detection/gpu/gpu_nbsd.c @@ -1,4 +1,5 @@ #include "gpu.h" +#include "common/debug.h" #include "common/io.h" #include @@ -37,6 +38,7 @@ const char* ffDetectGPUImpl([[maybe_unused]] const FFGPUOptions* options, FFlist if (errno == ENOENT) { break; // No more /dev/pciN devices } + FF_DEBUG("open(\"%s\", O_RDONLY | O_CLOEXEC) failed: %s", pciDevPath, strerror(errno)); return "open(\"/dev/pciN\", O_RDONLY | O_CLOEXEC) failed"; } diff --git a/src/detection/gpu/gpu_obsd.c b/src/detection/gpu/gpu_obsd.c index 4dd2d8327..10722f108 100644 --- a/src/detection/gpu/gpu_obsd.c +++ b/src/detection/gpu/gpu_obsd.c @@ -1,6 +1,9 @@ #include "gpu.h" +#include "common/debug.h" #include "common/io.h" +#include +#include #include #include #include @@ -31,6 +34,7 @@ const char* detectByPci([[maybe_unused]] const FFGPUOptions* options, FFlist* gp char pciDevPath[] = "/dev/pci0"; FF_AUTO_CLOSE_FD int pcifd = open(pciDevPath, O_RDONLY | O_CLOEXEC); if (pcifd < 0) { + FF_DEBUG("open(\"%s\", O_RDONLY | O_CLOEXEC) failed: %s", pciDevPath, strerror(errno)); return "open(\"/dev/pci0\", O_RDONLY | O_CLOEXEC) failed"; } diff --git a/src/detection/gpu/gpu_sunos.c b/src/detection/gpu/gpu_sunos.c index fb9db7a29..c34471a59 100644 --- a/src/detection/gpu/gpu_sunos.c +++ b/src/detection/gpu/gpu_sunos.c @@ -1,4 +1,5 @@ #include "gpu.h" +#include "common/debug.h" #include "common/strutil.h" #include @@ -46,6 +47,7 @@ static int walkDevTree(di_node_t node, [[maybe_unused]] di_minor_t minor, FFlist const char* ffDetectGPUImpl([[maybe_unused]] const FFGPUOptions* options, FFlist* gpus) { di_node_t rootNode = di_init("/", DINFOCPYALL); if (rootNode == DI_NODE_NIL) { + FF_DEBUG("di_init() failed"); return "di_init() failed"; } di_walk_minor(rootNode, DDI_NT_DISPLAY, DI_WALK_CLDFIRST, gpus, (void*) walkDevTree); diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c index a855ba5a4..3e3f591e6 100644 --- a/src/detection/host/host_apple.c +++ b/src/detection/host/host_apple.c @@ -1,17 +1,20 @@ #include "host.h" -#include "common/sysctl.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" +#include "common/sysctl.h" #include const char* getProductNameWithIokit(FFstrbuf* result) { FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IORegistryEntryFromPath(MACH_PORT_NULL, "IODeviceTree:/product"); if (!registryEntry) { + FF_DEBUG("IORegistryEntryFromPath(IODeviceTree:/product) failed"); return "IOServiceGetMatchingService() failed"; } FF_CFTYPE_AUTO_RELEASE CFStringRef productName = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("product-name"), kCFAllocatorDefault, kNilOptions); if (!productName) { + FF_DEBUG("IORegistryEntryCreateCFProperty(product-name) failed"); return "IORegistryEntryCreateCFProperty() failed"; } @@ -21,6 +24,7 @@ const char* getProductNameWithIokit(FFstrbuf* result) { const char* getOthersByIokit(FFHostResult* host) { FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice")); if (!registryEntry) { + FF_DEBUG("IOServiceGetMatchingService(IOPlatformExpertDevice) failed"); return "IOServiceGetMatchingService() failed"; } diff --git a/src/detection/icons/icons_linux.c b/src/detection/icons/icons_linux.c index fb1b12621..b76dceb12 100644 --- a/src/detection/icons/icons_linux.c +++ b/src/detection/icons/icons_linux.c @@ -1,4 +1,5 @@ #include "icons.h" +#include "common/debug.h" #include "common/parsing.h" #include "detection/gtk_qt/gtk_qt.h" #include "detection/displayserver/displayserver.h" @@ -16,6 +17,7 @@ const char* ffDetectIcons(FFIconsResult* result) { const FFstrbuf* gtk4 = &ffDetectGTK4()->icons; if (plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) { + FF_DEBUG("No icons could be found"); return "No icons could be found"; } diff --git a/src/detection/initsystem/initsystem_haiku.c b/src/detection/initsystem/initsystem_haiku.c index bdcb64d9a..4f3818df1 100644 --- a/src/detection/initsystem/initsystem_haiku.c +++ b/src/detection/initsystem/initsystem_haiku.c @@ -1,4 +1,5 @@ #include "initsystem.h" +#include "common/debug.h" #include "common/strutil.h" #include "common/haiku/version.h" #include "common/io.h" @@ -11,6 +12,7 @@ const char* ffDetectInitSystem(FFInitSystemResult* result) { // so we can't query be_roster for it. const char* path = "/boot/system/servers/launch_daemon"; if (!ffPathExists(path, FF_PATHTYPE_FILE)) { + FF_DEBUG("%s does not exist", path); return "launch_daemon is not found"; } diff --git a/src/detection/keyboard/keyboard_apple.c b/src/detection/keyboard/keyboard_apple.c index 63adcafd7..8dd299062 100644 --- a/src/detection/keyboard/keyboard_apple.c +++ b/src/detection/keyboard/keyboard_apple.c @@ -1,5 +1,6 @@ #include "keyboard.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include @@ -20,6 +21,7 @@ static void enumSet(IOHIDDeviceRef value, FFlist* results) { const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) { FF_CFTYPE_AUTO_RELEASE IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) { + FF_DEBUG("IOHIDManagerOpen() failed"); return "IOHIDManagerOpen() failed"; } diff --git a/src/detection/keyboard/keyboard_bsd.c b/src/detection/keyboard/keyboard_bsd.c index 46a703b57..b079a4605 100644 --- a/src/detection/keyboard/keyboard_bsd.c +++ b/src/detection/keyboard/keyboard_bsd.c @@ -1,6 +1,8 @@ #include "keyboard.h" +#include "common/debug.h" #include "common/io.h" +#include #include #include #include @@ -15,6 +17,7 @@ static const char* detectByIoctl(FFlist* devices) { keyboard_info_t kbdInfo; if (ioctl(STDIN_FILENO, KDGKBINFO, &kbdInfo) != 0) { + FF_DEBUG("ioctl(KDGKBINFO) failed: %s", strerror(errno)); return "ioctl(KDGKBINFO) failed"; } diff --git a/src/detection/keyboard/keyboard_haiku.cpp b/src/detection/keyboard/keyboard_haiku.cpp index 2063f059f..480f4070f 100644 --- a/src/detection/keyboard/keyboard_haiku.cpp +++ b/src/detection/keyboard/keyboard_haiku.cpp @@ -1,5 +1,6 @@ extern "C" { #include "keyboard.h" +#include "common/debug.h" } #include @@ -8,7 +9,9 @@ extern "C" { const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) { BList list; - if (get_input_devices(&list) != B_OK) { + status_t status = get_input_devices(&list); + if (status != B_OK) { + FF_DEBUG("get_input_devices() failed: %d", (int) status); return "get_input_devices() failed"; } diff --git a/src/detection/keyboard/keyboard_linux.c b/src/detection/keyboard/keyboard_linux.c index 539282ab8..efb0e80b0 100644 --- a/src/detection/keyboard/keyboard_linux.c +++ b/src/detection/keyboard/keyboard_linux.c @@ -1,4 +1,5 @@ #include "keyboard.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -9,6 +10,7 @@ const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */) { // This detects both wired and Bluetooth keyboards uniformly. FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate(); if (!ffAppendFileBuffer("/proc/bus/input/devices", &content)) { + FF_DEBUG("ffAppendFileBuffer(\"/proc/bus/input/devices\") failed"); return "ffAppendFileBuffer(\"/proc/bus/input/devices\") == nullptr"; } diff --git a/src/detection/libc/libc_android.c b/src/detection/libc/libc_android.c index 14f4ab1ba..ae4b31081 100644 --- a/src/detection/libc/libc_android.c +++ b/src/detection/libc/libc_android.c @@ -1,4 +1,5 @@ #include "libc.h" +#include "common/debug.h" #include "common/strutil.h" #include @@ -17,6 +18,7 @@ const char* ffDetectLibc(FFLibcResult* result) { ; return nullptr; #else + FF_DEBUG("Unknown Android libc"); return "Unknown Android libc"; #endif } diff --git a/src/detection/lm/lm_linux.c b/src/detection/lm/lm_linux.c index 2abfab97a..5a706ca0a 100644 --- a/src/detection/lm/lm_linux.c +++ b/src/detection/lm/lm_linux.c @@ -1,4 +1,5 @@ #include "lm.h" +#include "common/debug.h" #include "common/io.h" #include "common/mallocHelper.h" #include "common/properties.h" @@ -9,6 +10,7 @@ #include "common/dbus.h" #endif +#include #include #if __FreeBSD__ @@ -30,6 +32,7 @@ static const char* getGdmVersion(FFstrbuf* version) { if (error || version->length == 0) { error = ffProcessAppendStdOut(version, (char* const[]) { "gdm", "--version", nullptr }); if (error || version->length == 0) { + FF_DEBUG("Failed to get GDM version"); return "Failed to get GDM version"; } } @@ -69,6 +72,7 @@ static const char* getSddmVersion(FFstrbuf* version) { gzFile file = ffgzopen(FF_PATH_PKG_BASE "/share/man/man1/sddm.1.gz", "rb"); if (file == Z_NULL) { + FF_DEBUG("ffgzopen(\"/usr/share/man/man1/sddm.1.gz\", \"rb\") failed: %s", strerror(errno)); return "ffgzopen(\"/usr/share/man/man1/sddm.1.gz\", \"rb\") failed"; } @@ -78,12 +82,14 @@ static const char* getSddmVersion(FFstrbuf* version) { ffgzclose(file); if (size <= 0) { + FF_DEBUG("ffgzread(file, version->chars, version->length) failed"); return "ffgzread(file, version->chars, version->length) failed"; } version->length = (uint32_t) size; uint32_t index = ffStrbufFirstIndexS(version, ".TH "); if (index == version->length) { + FF_DEBUG(".TH is not found"); ffStrbufClear(version); return ".TH is not found"; } @@ -137,6 +143,7 @@ static const char* detectBySystemdDbus(FFLMResult* result) { // and requires no $XDG_SESSION_ID being available FF_DBUS_AUTO_DESTROY_DATA FFDBusData dbus = {}; if (ffDBusLoadData(DBUS_BUS_SYSTEM, &dbus) != nullptr) { + FF_DEBUG("Failed to load system DBus"); return "Failed to load system DBus"; } @@ -147,6 +154,7 @@ static const char* detectBySystemdDbus(FFLMResult* result) { "org.freedesktop.login1.Session", "Service", &result->service)) { + FF_DEBUG("Failed to get systemd session Service property"); return "Failed to get systemd session Service property"; } @@ -170,6 +178,7 @@ static const char* detectBySystemdPrivate(FFLMResult* result) { // This is actually buggy, and assumes current user is using DE // `sd_pid_get_session` can be a better option, but we need to find a pid to use if (!ffParsePropFile(path.chars, "DISPLAY=", &sessionId)) { + FF_DEBUG("Failed to get $XDG_SESSION_ID"); return "Failed to get $XDG_SESSION_ID"; } } @@ -255,11 +264,13 @@ const char* detectByProcesses(FFLMResult* result) { size_t length = 0; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, nullptr) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, nullptr) failed"; } FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length); if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed"; } @@ -277,12 +288,14 @@ const char* detectByProcesses(FFLMResult* result) { size_t length = 0; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, nullptr) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, nullptr) failed"; } FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length); request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed"; } @@ -297,6 +310,7 @@ const char* detectByProcesses(FFLMResult* result) { #elif __sun FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc"); if (procdir == nullptr) { + FF_DEBUG("opendir(\"/proc\") failed: %s", strerror(errno)); return "opendir(\"/proc\") failed"; } @@ -331,6 +345,7 @@ const char* detectByProcesses(FFLMResult* result) { #elif __linux__ || __GNU__ FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc"); if (procdir == nullptr) { + FF_DEBUG("opendir(\"/proc\") failed: %s", strerror(errno)); return "opendir(\"/proc\") failed"; } @@ -384,12 +399,14 @@ const char* detectByProcesses(FFLMResult* result) { size_t size = 0; if (sysctl(request, ARRAY_SIZE(request), nullptr, &size, nullptr, 0) != 0) { + FF_DEBUG("sysctl(KERN_PROC_UID, nullptr) failed: %s", strerror(errno)); return "sysctl(KERN_PROC_UID, nullptr) failed"; } FF_AUTO_FREE struct kinfo_proc2* procs = malloc(size); if (sysctl(request, ARRAY_SIZE(request), procs, &size, nullptr, 0) != 0) { + FF_DEBUG("sysctl(KERN_PROC_UID, procs) failed: %s", strerror(errno)); return "sysctl(KERN_PROC_UID, procs) failed"; } @@ -403,6 +420,7 @@ const char* detectByProcesses(FFLMResult* result) { #endif if (result->service.length == 0) { + FF_DEBUG("Failed to detect login manager by processes"); return "Failed to detect login manager by processes"; } diff --git a/src/detection/loadavg/loadavg_bsd.c b/src/detection/loadavg/loadavg_bsd.c index 7ef95ed77..925376f4f 100644 --- a/src/detection/loadavg/loadavg_bsd.c +++ b/src/detection/loadavg/loadavg_bsd.c @@ -1,5 +1,8 @@ #include "detection/loadavg/loadavg.h" +#include "common/debug.h" +#include +#include #include #if __FreeBSD__ || __OpenBSD__ || __NetBSD__ @@ -14,6 +17,7 @@ const char* ffDetectLoadavg(double result[3]) { struct loadavg load; size_t size = sizeof(load); if (sysctl((int[]) { CTL_VM, VM_LOADAVG }, 2, &load, &size, nullptr, 0) < 0) { + FF_DEBUG("sysctl({CTL_VM, VM_LOADAVG}) failed: %s", strerror(errno)); return "sysctl({CTL_VM, VM_LOADAVG}) failed"; } for (int i = 0; i < 3; i++) { diff --git a/src/detection/loadavg/loadavg_linux.c b/src/detection/loadavg/loadavg_linux.c index fb27551b2..d231c43b1 100644 --- a/src/detection/loadavg/loadavg_linux.c +++ b/src/detection/loadavg/loadavg_linux.c @@ -1,6 +1,9 @@ #include "detection/loadavg/loadavg.h" +#include "common/debug.h" #include "common/io.h" +#include +#include #include const char* ffDetectLoadavg(double result[3]) { @@ -22,6 +25,7 @@ const char* ffDetectLoadavg(double result[3]) { // getloadavg requires higher ANDROID_API version struct sysinfo si; if (sysinfo(&si) < 0) { + FF_DEBUG("both /proc/loadavg and sysinfo() failed: %s", strerror(errno)); return "both /proc/loadavg and sysinfo() failed"; } diff --git a/src/detection/locale/locale_linux.c b/src/detection/locale/locale_linux.c index ab630a7a3..81618ae6b 100644 --- a/src/detection/locale/locale_linux.c +++ b/src/detection/locale/locale_linux.c @@ -1,4 +1,5 @@ #include "detection/locale/locale.h" +#include "common/debug.h" #include @@ -18,5 +19,6 @@ const char* ffDetectLocale(FFstrbuf* result) { return nullptr; } + FF_DEBUG("LC_ALL, LANG and setlocale(LC_TIME, nullptr) are all empty"); return "Failed to detect locale"; } diff --git a/src/detection/localip/localip_linux.c b/src/detection/localip/localip_linux.c index 203543c67..dd00c50fd 100644 --- a/src/detection/localip/localip_linux.c +++ b/src/detection/localip/localip_linux.c @@ -280,7 +280,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results) { struct ifaddrs* ifAddrStruct = nullptr; if (getifaddrs(&ifAddrStruct) < 0) { - FF_DEBUG("getifaddrs() failed"); + FF_DEBUG("getifaddrs() failed: %s", strerror(errno)); return "getifaddrs(&ifAddrStruct) failed"; } diff --git a/src/detection/media/media_android.c b/src/detection/media/media_android.c index 994bb0b46..6efa3790e 100644 --- a/src/detection/media/media_android.c +++ b/src/detection/media/media_android.c @@ -488,6 +488,8 @@ static const char* androidResolveCodes(FFMediaAndroidCodes* codes) { || codes->getPackageName == FF_DEX_STATIC_INT_UNRESOLVED || codes->getMetadata == FF_DEX_STATIC_INT_UNRESOLVED || codes->getPlaybackState == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("Unresolved transaction codes: getSessions=%d, getPackageName=%d, getMetadata=%d, getPlaybackState=%d", + (int) codes->getSessions, (int) codes->getPackageName, (int) codes->getMetadata, (int) codes->getPlaybackState); return "The session service does not declare every method this module calls"; } return nullptr; @@ -637,6 +639,7 @@ static const char* androidReadMetadataEntry(FFMediaAndroidReader* reader, size_t static const char* androidReadMetadataBundle(FFMediaAndroidReader* reader, FFMediaResult* result, const FFBinderReply* reply, FFMediaAndroidCover* cover) { int32_t bundleLength = 0; if (!androidReadI32(reader, &bundleLength) || bundleLength <= 0) { + FF_DEBUG("The metadata bundle length is %d, which cannot hold a bundle", (int) bundleLength); return "The metadata bundle is empty"; } const size_t bundleEnd = reader->position + (size_t) bundleLength; @@ -646,10 +649,12 @@ static const char* androidReadMetadataBundle(FFMediaAndroidReader* reader, FFMed int32_t magic = 0; if (!androidReadI32(reader, &magic) || (uint32_t) magic != FF_MEDIA_ANDROID_BUNDLE_MAGIC) { + FF_DEBUG("The metadata magic is 0x%08x instead of 0x%08x", (unsigned) magic, FF_MEDIA_ANDROID_BUNDLE_MAGIC); return "The metadata is not a bundle"; } int32_t count = 0; if (!androidReadI32(reader, &count)) { + FF_DEBUG("The metadata bundle is truncated before its entry count"); return "The metadata bundle has no entry count"; } @@ -951,6 +956,7 @@ static const char* androidDetectMediaSession(FFMediaResult* media, bool saveCove } if (tokenCount == 0) { + FF_DEBUG("The media_session service returned no session tokens"); return "No active media session"; } diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c index 443ef2062..365b45e96 100644 --- a/src/detection/memory/memory_apple.c +++ b/src/detection/memory/memory_apple.c @@ -1,6 +1,7 @@ #include "memory.h" #include "common/debug.h" +#include #include #include #include @@ -11,10 +12,12 @@ const char* ffDetectMemory(FFMemoryResult* ram) { #if FF_APPLE_MEMSIZE_USABLE if (sysctlbyname("hw.memsize_usable", &ram->bytesTotal, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctlbyname(\"hw.memsize_usable\") failed: %s", strerror(errno)); return "Failed to read hw.memsize_usable"; } #else if (sysctl((int[]) { CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl(HW_MEMSIZE) failed: %s", strerror(errno)); return "Failed to read hw.memsize"; } #endif @@ -22,6 +25,7 @@ const char* ffDetectMemory(FFMemoryResult* ram) { mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; vm_statistics64_data_t vmstat; if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS) { + FF_DEBUG("host_statistics64() failed"); return "Failed to read host_statistics64"; } diff --git a/src/detection/memory/memory_bsd.c b/src/detection/memory/memory_bsd.c index 1985dfcd6..2a5e92731 100644 --- a/src/detection/memory/memory_bsd.c +++ b/src/detection/memory/memory_bsd.c @@ -1,9 +1,14 @@ #include "memory.h" +#include "common/debug.h" #include "common/sysctl.h" +#include +#include + const char* ffDetectMemory(FFMemoryResult* ram) { size_t length = sizeof(ram->bytesTotal); if (sysctl((int[]) { CTL_HW, HW_PHYSMEM }, 2, &ram->bytesTotal, &length, nullptr, 0)) { + FF_DEBUG("sysctl(hw.physmem) failed: %s", strerror(errno)); return "Failed to read hw.physmem"; } diff --git a/src/detection/memory/memory_haiku.c b/src/detection/memory/memory_haiku.c index bf5407047..705cb4316 100644 --- a/src/detection/memory/memory_haiku.c +++ b/src/detection/memory/memory_haiku.c @@ -1,10 +1,13 @@ #include "memory.h" +#include "common/debug.h" #include const char* ffDetectMemory(FFMemoryResult* ram) { system_info info; - if (get_system_info(&info) != B_OK) { + status_t status = get_system_info(&info); + if (status != B_OK) { + FF_DEBUG("get_system_info() failed: %d", (int) status); return "Error getting system info"; } diff --git a/src/detection/memory/memory_linux.c b/src/detection/memory/memory_linux.c index 0a2ebd3fb..b525aef04 100644 --- a/src/detection/memory/memory_linux.c +++ b/src/detection/memory/memory_linux.c @@ -1,10 +1,12 @@ #include "memory.h" +#include "common/debug.h" #include "common/io.h" const char* ffDetectMemory(FFMemoryResult* ram) { char buf[PROC_FILE_BUFFSIZ]; ssize_t nRead = ffReadFileData("/proc/meminfo", ARRAY_SIZE(buf) - 1, buf); if (nRead < 0) { + FF_DEBUG("ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf) failed: %s", strerror(errno)); return "ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf)"; } buf[nRead] = '\0'; @@ -21,6 +23,7 @@ const char* ffDetectMemory(FFMemoryResult* ram) { if ((token = memmem(buf, (size_t) nRead, "MemTotal:", strlen("MemTotal:"))) != nullptr) { memTotal = (uint64_t) strtoull(token + strlen("MemTotal:"), nullptr, 10); } else { + FF_DEBUG("MemTotal not found in /proc/meminfo"); return "MemTotal not found in /proc/meminfo"; } diff --git a/src/detection/memory/memory_nbsd.c b/src/detection/memory/memory_nbsd.c index fe43e7058..feef3437f 100644 --- a/src/detection/memory/memory_nbsd.c +++ b/src/detection/memory/memory_nbsd.c @@ -1,6 +1,9 @@ #include "memory.h" +#include "common/debug.h" #include "common/sysctl.h" +#include +#include #include #include @@ -8,6 +11,7 @@ const char* ffDetectMemory(FFMemoryResult* ram) { struct uvmexp_sysctl buf; size_t length = sizeof(buf); if (sysctl((int[]) { CTL_VM, VM_UVMEXP2 }, 2, &buf, &length, nullptr, 0) < 0) { + FF_DEBUG("sysctl(CTL_VM, VM_UVMEXP2) failed: %s", strerror(errno)); return "sysctl(CTL_VM, VM_UVMEXP2) failed"; } diff --git a/src/detection/memory/memory_obsd.c b/src/detection/memory/memory_obsd.c index 87b7953e6..b831ae793 100644 --- a/src/detection/memory/memory_obsd.c +++ b/src/detection/memory/memory_obsd.c @@ -1,6 +1,9 @@ #include "memory.h" +#include "common/debug.h" #include "common/sysctl.h" +#include +#include #include #include @@ -8,6 +11,7 @@ const char* ffDetectMemory(FFMemoryResult* ram) { struct uvmexp buf; size_t length = sizeof(buf); if (sysctl((int[]) { CTL_VM, VM_UVMEXP }, 2, &buf, &length, nullptr, 0) < 0) { + FF_DEBUG("sysctl(CTL_VM, VM_UVMEXP) failed: %s", strerror(errno)); return "sysctl(CTL_VM, VM_UVMEXP) failed"; } diff --git a/src/detection/mouse/mouse_apple.c b/src/detection/mouse/mouse_apple.c index 7f0b96cd0..1413d3140 100644 --- a/src/detection/mouse/mouse_apple.c +++ b/src/detection/mouse/mouse_apple.c @@ -1,5 +1,6 @@ #include "mouse.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include @@ -20,6 +21,7 @@ static void enumSet(IOHIDDeviceRef value, FFlist* results) { const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { FF_CFTYPE_AUTO_RELEASE IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess) { + FF_DEBUG("IOHIDManagerOpen() failed"); return "IOHIDManagerOpen() failed"; } diff --git a/src/detection/mouse/mouse_haiku.cpp b/src/detection/mouse/mouse_haiku.cpp index 70a4533c3..bb7033fb2 100644 --- a/src/detection/mouse/mouse_haiku.cpp +++ b/src/detection/mouse/mouse_haiku.cpp @@ -1,5 +1,6 @@ extern "C" { #include "mouse.h" +#include "common/debug.h" } #include @@ -8,7 +9,9 @@ extern "C" { const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { BList list; - if (get_input_devices(&list) != B_OK) { + status_t inputDevicesStatus = get_input_devices(&list); + if (inputDevicesStatus != B_OK) { + FF_DEBUG("get_input_devices() failed: status_t 0x%08x", (uint32_t) inputDevicesStatus); return "get_input_devices() failed"; } diff --git a/src/detection/mouse/mouse_linux.c b/src/detection/mouse/mouse_linux.c index 4c66fc513..ddcc39812 100644 --- a/src/detection/mouse/mouse_linux.c +++ b/src/detection/mouse/mouse_linux.c @@ -1,10 +1,12 @@ #include "mouse.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/input/"); if (dirp == nullptr) { + FF_DEBUG("opendir(\"/sys/class/input/\") failed: %s", strerror(errno)); return "opendir(\"/sys/class/input/\") == nullptr"; } diff --git a/src/detection/netio/netio_apple.c b/src/detection/netio/netio_apple.c index 1ab2c5774..530aee820 100644 --- a/src/detection/netio/netio_apple.c +++ b/src/detection/netio/netio_apple.c @@ -1,8 +1,10 @@ #include "netio.h" +#include "common/debug.h" #include "common/netif.h" #include "common/mallocHelper.h" +#include #include #include #include @@ -12,6 +14,7 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) { size_t bufSize = 0; if (sysctl(mib, ARRAY_SIZE(mib), nullptr, &bufSize, 0, 0) < 0) { + FF_DEBUG("sysctl(mib, ARRAY_SIZE(mib), nullptr, &bufSize, 0, 0) failed: %s", strerror(errno)); return "sysctl(mib, ARRAY_SIZE(mib), nullptr, &bufSize, 0, 0) failed"; } @@ -19,6 +22,7 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) { FF_AUTO_FREE struct ifmibdata* buf = (struct ifmibdata*) malloc(bufSize); if (sysctl(mib, ARRAY_SIZE(mib), buf, &bufSize, 0, 0) < 0) { + FF_DEBUG("sysctl(mib, ARRAY_SIZE(mib), buf, &bufSize, 0, 0) failed: %s", strerror(errno)); return "sysctl(mib, ARRAY_SIZE(mib), buf, &bufSize, 0, 0) failed"; } diff --git a/src/detection/netio/netio_bsd.c b/src/detection/netio/netio_bsd.c index 2641dd249..1c938e713 100644 --- a/src/detection/netio/netio_bsd.c +++ b/src/detection/netio/netio_bsd.c @@ -1,8 +1,10 @@ #include "netio.h" +#include "common/debug.h" #include "common/netif.h" #include "common/mallocHelper.h" +#include #include #include #include @@ -15,11 +17,13 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) { size_t bufSize = 0; if (sysctl((int[]) { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, (options->defaultRouteOnly ? (int) defaultRouteIfIndex : 0) }, 6, nullptr, &bufSize, 0, 0) < 0) { + FF_DEBUG("sysctl({ CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, ifIndex }, 6, nullptr, &bufSize, 0, 0) failed: %s", strerror(errno)); return "sysctl({ CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, ifIndex }, 6, nullptr, &bufSize, 0, 0) failed"; } FF_AUTO_FREE struct if_msghdr* buf = (struct if_msghdr*) malloc(bufSize); if (sysctl((int[]) { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, (options->defaultRouteOnly ? (int) defaultRouteIfIndex : 0) }, 6, buf, &bufSize, 0, 0) < 0) { + FF_DEBUG("sysctl({ CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, ifIndex }, 6, buf, &bufSize, 0, 0) failed: %s", strerror(errno)); return "sysctl({ CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, ifIndex }, 6, buf, &bufSize, 0, 0) failed"; } diff --git a/src/detection/netio/netio_linux.c b/src/detection/netio/netio_linux.c index 4e5c8d61b..2daf23bd0 100644 --- a/src/detection/netio/netio_linux.c +++ b/src/detection/netio/netio_linux.c @@ -1,5 +1,6 @@ #include "netio.h" +#include "common/debug.h" #include "common/io.h" #include "common/netif.h" #include "common/strutil.h" @@ -58,6 +59,7 @@ static void getData(FFstrbuf* buffer, const char* ifName, bool isDefaultRoute, i const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/net"); if (!dirp) { + FF_DEBUG("opendir(\"/sys/class/net\") failed: %s", strerror(errno)); return "opendir(\"/sys/class/net\") == nullptr"; } diff --git a/src/detection/netio/netio_sunos.c b/src/detection/netio/netio_sunos.c index 2b9a02038..df580646b 100644 --- a/src/detection/netio/netio_sunos.c +++ b/src/detection/netio/netio_sunos.c @@ -1,4 +1,5 @@ #include "netio.h" +#include "common/debug.h" #include "common/netif.h" #include "common/strutil.h" @@ -14,6 +15,7 @@ static inline void kstatFreeWrap(kstat_ctl_t** pkc) { const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options) { [[gnu::cleanup(kstatFreeWrap)]] kstat_ctl_t* kc = kstat_open(); if (!kc) { + FF_DEBUG("kstat_open() failed"); return "kstat_open() failed"; } diff --git a/src/detection/opengl/opengl_apple.c b/src/detection/opengl/opengl_apple.c index d29ae284a..0f994175d 100644 --- a/src/detection/opengl/opengl_apple.c +++ b/src/detection/opengl/opengl_apple.c @@ -1,6 +1,7 @@ #include "fastfetch.h" #include "opengl.h" +#include "common/debug.h" #define GL_SILENCE_DEPRECATION #include @@ -9,7 +10,9 @@ void ffOpenGLHandleResult(FFOpenGLResult* result, typeof(&glGetString) ffglGetString); static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj context) { - if (CGLSetCurrentContext(context) != kCGLNoError) { + CGLError setContextError = CGLSetCurrentContext(context); + if (setContextError != kCGLNoError) { + FF_DEBUG("CGLSetCurrentContext() failed: CGLError %d", (int) setContextError); return "CGLSetCurrentContext() failed"; } @@ -25,7 +28,9 @@ static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj contex static const char* cglHandlePixelFormat(FFOpenGLResult* result, CGLPixelFormatObj pixelFormat) { CGLContextObj context; - if (CGLCreateContext(pixelFormat, nullptr, &context) != kCGLNoError) { + CGLError createContextError = CGLCreateContext(pixelFormat, nullptr, &context); + if (createContextError != kCGLNoError) { + FF_DEBUG("CGLCreateContext() failed: CGLError %d", (int) createContextError); return "CGLCreateContext() failed"; } @@ -41,7 +46,9 @@ const char* cglDetectOpenGL(FFOpenGLResult* result) { }; GLint num; - if (CGLChoosePixelFormat(attrs, &pixelFormat, &num) != kCGLNoError) { + CGLError choosePixelFormatError = CGLChoosePixelFormat(attrs, &pixelFormat, &num); + if (choosePixelFormatError != kCGLNoError) { + FF_DEBUG("CGLChoosePixelFormat() failed: CGLError %d", (int) choosePixelFormatError); return "CGLChoosePixelFormat() failed"; } @@ -61,6 +68,7 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) { return "fastfetch was compiled without egl support"; #endif } else { + FF_DEBUG("Unsupported OpenGL library requested: %d", (int) options->library); return "Unsupported OpenGL library"; } } diff --git a/src/detection/opengl/opengl_haiku.cpp b/src/detection/opengl/opengl_haiku.cpp index 47d55500e..4fd47707f 100644 --- a/src/detection/opengl/opengl_haiku.cpp +++ b/src/detection/opengl/opengl_haiku.cpp @@ -2,6 +2,7 @@ extern "C" { #include "opengl.h" +#include "common/debug.h" #include "common/io.h" #if FF_HAVE_EGL const char* ffOpenGLDetectByEGL(FFOpenGLResult* result); @@ -16,6 +17,7 @@ static const char* oglDetectOpenGL(FFOpenGLResult* result) { BGLView glView(BRect(), "ff_ogl_view", B_FOLLOW_NONE, B_WILL_DRAW, BGL_RGB); auto ffglGetString = (decltype(&glGetString)) glView.GetGLProcAddress("glGetString"); if (!ffglGetString) { + FF_DEBUG("glView.GetGLProcAddress(glGetString) returned null"); return "glView.GetGLProcAddress() failed"; } ffOpenGLHandleResult(result, ffglGetString); @@ -33,6 +35,7 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) { return "fastfetch was compiled without egl support"; #endif } else { + FF_DEBUG("Unsupported OpenGL library requested: %d", (int) options->library); return "Unsupported OpenGL library"; } } diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index d63843b90..f21a3b6e0 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -1,5 +1,6 @@ #include "fastfetch.h" #include "opengl.h" +#include "common/debug.h" #include "common/io.h" #include @@ -50,6 +51,7 @@ typedef struct GLXData { static const char* glxHandleContext(FFOpenGLResult* result, GLXData* data) { if (data->ffglXMakeCurrent(data->display, data->glxPixmap, data->context) != True) { + FF_DEBUG("glXMakeCurrent() returned False"); return "glXMakeCurrent returned False"; } ffOpenGLHandleResult(result, data->ffglGetString); @@ -67,6 +69,7 @@ static const char* glxHandleContext(FFOpenGLResult* result, GLXData* data) { static const char* glxHandleGLXPixmap(FFOpenGLResult* result, GLXData* data) { data->context = data->ffglXCreateContext(data->display, data->visualInfo, nullptr, True); if (data->context == nullptr) { + FF_DEBUG("glXCreateContext() returned nullptr"); return "glXCreateContext returned nullptr"; } @@ -78,6 +81,7 @@ static const char* glxHandleGLXPixmap(FFOpenGLResult* result, GLXData* data) { static const char* glxHandlePixmap(FFOpenGLResult* result, GLXData* data) { data->glxPixmap = data->ffglXCreateGLXPixmap(data->display, data->visualInfo, data->pixmap); if (data->glxPixmap == None) { + FF_DEBUG("glXCreateGLXPixmap() returned None"); return "glXCreateGLXPixmap returned None"; } @@ -89,6 +93,7 @@ static const char* glxHandlePixmap(FFOpenGLResult* result, GLXData* data) { static const char* glxHandleVisualInfo(FFOpenGLResult* result, GLXData* data) { data->pixmap = data->ffXCreatePixmap(data->display, DefaultRootWindow(data->display), FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT, (unsigned int) data->visualInfo->depth); if (data->pixmap == None) { + FF_DEBUG("XCreatePixmap() returned None"); return "XCreatePixmap returned None"; } @@ -100,6 +105,7 @@ static const char* glxHandleVisualInfo(FFOpenGLResult* result, GLXData* data) { static const char* glxHandleDisplay(FFOpenGLResult* result, GLXData* data) { data->visualInfo = data->ffglXChooseVisual(data->display, DefaultScreen(data->display), (int[]) { None }); if (data->visualInfo == nullptr) { + FF_DEBUG("glXChooseVisual() returned nullptr"); return "glXChooseVisual returned nullptr"; } @@ -111,11 +117,13 @@ static const char* glxHandleDisplay(FFOpenGLResult* result, GLXData* data) { static const char* glxHandleData(FFOpenGLResult* result, GLXData* data) { data->ffglGetString = (typeof(data->ffglGetString)) data->ffglXGetProcAddress((const GLubyte*) "glGetString"); if (data->ffglGetString == nullptr) { + FF_DEBUG("glXGetProcAddress(glGetString) returned nullptr"); return "glXGetProcAddress(glGetString) returned nullptr"; } data->display = data->ffXOpenDisplay(nullptr); if (data->display == nullptr) { + FF_DEBUG("XOpenDisplay() returned nullptr"); return "XOpenDisplay returned nullptr"; } diff --git a/src/detection/physicaldisk/physicaldisk_apple.c b/src/detection/physicaldisk/physicaldisk_apple.c index 47098c944..789ab624d 100644 --- a/src/detection/physicaldisk/physicaldisk_apple.c +++ b/src/detection/physicaldisk/physicaldisk_apple.c @@ -1,5 +1,6 @@ #include "physicaldisk.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" #include #include @@ -25,11 +26,13 @@ static const char* detectSsdTemp(io_service_t entryPhysical, double* temp) { [[gnu::cleanup(wrapIoDestroyPlugInInterface)]] IOCFPlugInInterface** pluginInf = nullptr; int32_t score; if (IOCreatePlugInInterfaceForService(entryPhysical, kIONVMeSMARTUserClientTypeID, kIOCFPlugInInterfaceID, &pluginInf, &score) != kIOReturnSuccess) { + FF_DEBUG("IOCreatePlugInInterfaceForService(kIONVMeSMARTUserClientTypeID) failed"); return "IOCreatePlugInInterfaceForService() failed"; } IONVMeSMARTInterface** smartInf = nullptr; if ((*pluginInf)->QueryInterface(pluginInf, CFUUIDGetUUIDBytes(kIONVMeSMARTInterfaceID), (LPVOID) &smartInf) != kIOReturnSuccess) { + FF_DEBUG("QueryInterface(kIONVMeSMARTInterfaceID) failed"); return "QueryInterface() failed"; } @@ -44,6 +47,7 @@ static const char* detectSsdTemp(io_service_t entryPhysical, double* temp) { (*pluginInf)->Release(smartInf); return error; #else + FF_DEBUG("SSD temperature detection needs macOS 10.15 or newer"); return "No support for old MacOS version"; #endif } @@ -51,6 +55,7 @@ static const char* detectSsdTemp(io_service_t entryPhysical, double* temp) { const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) { FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = 0; if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOBlockStorageDriverClass), &iterator) != KERN_SUCCESS) { + FF_DEBUG("IOServiceGetMatchingServices(kIOBlockStorageDriverClass) failed"); return "IOServiceGetMatchingServices() failed"; } diff --git a/src/detection/physicaldisk/physicaldisk_bsd.c b/src/detection/physicaldisk/physicaldisk_bsd.c index d17905388..5d59fd9d9 100644 --- a/src/detection/physicaldisk/physicaldisk_bsd.c +++ b/src/detection/physicaldisk/physicaldisk_bsd.c @@ -2,6 +2,7 @@ #if __has_include() + #include "common/debug.h" #include "common/strutil.h" #include @@ -14,10 +15,12 @@ const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) { struct gmesh geomTree; if (geom_gettree(&geomTree) < 0) { + FF_DEBUG("geom_gettree() failed"); return "geom_gettree() failed"; } if (geom_stats_open() < 0) { + FF_DEBUG("geom_stats_open() failed"); return "geom_stats_open() failed"; } diff --git a/src/detection/physicaldisk/physicaldisk_haiku.c b/src/detection/physicaldisk/physicaldisk_haiku.c index d2b83fed2..ab5599658 100644 --- a/src/detection/physicaldisk/physicaldisk_haiku.c +++ b/src/detection/physicaldisk/physicaldisk_haiku.c @@ -1,5 +1,6 @@ #include "physicaldisk.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -11,6 +12,7 @@ static const char* searchRawDeviceFile(FFstrbuf* path, const char* diskType, FFlist* result, FFPhysicalDiskOptions* options) { FF_AUTO_CLOSE_DIR DIR* dir = opendir(path->chars); if (!dir) { + FF_DEBUG("opendir(\"%s\") failed: %s", path->chars, strerror(errno)); return "detectDiskType: opendir() failed"; } uint32_t baseLen = path->length; @@ -83,6 +85,7 @@ static const char* searchRawDeviceFile(FFstrbuf* path, const char* diskType, FFl const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) { FF_AUTO_CLOSE_DIR DIR* dir = opendir("/dev/disk"); if (!dir) { + FF_DEBUG("opendir(\"/dev/disk\") failed: %s", strerror(errno)); return "opendir(/dev/disk) failed"; } diff --git a/src/detection/physicaldisk/physicaldisk_linux.c b/src/detection/physicaldisk/physicaldisk_linux.c index 525e391bf..7a9fd5f79 100644 --- a/src/detection/physicaldisk/physicaldisk_linux.c +++ b/src/detection/physicaldisk/physicaldisk_linux.c @@ -1,4 +1,5 @@ #include "physicaldisk.h" +#include "common/debug.h" #include "common/io.h" #include "common/properties.h" #include "common/strutil.h" @@ -178,6 +179,7 @@ static void parsePhysicalDisk(int dfd, const char* devName, FFPhysicalDiskOption const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) { FF_AUTO_CLOSE_DIR DIR* sysBlockDirp = opendir("/sys/block/"); if (sysBlockDirp == nullptr) { + FF_DEBUG("opendir(\"/sys/block/\") failed: %s", strerror(errno)); return "opendir(\"/sys/block/\") == nullptr"; } diff --git a/src/detection/physicaldisk/physicaldisk_sunos.c b/src/detection/physicaldisk/physicaldisk_sunos.c index b65fba000..9ac2a30ef 100644 --- a/src/detection/physicaldisk/physicaldisk_sunos.c +++ b/src/detection/physicaldisk/physicaldisk_sunos.c @@ -1,4 +1,5 @@ #include "physicaldisk.h" +#include "common/debug.h" #include "common/strutil.h" #include "sys/scsi/generic/inquiry.h" @@ -98,6 +99,7 @@ static int walkDevTree(di_node_t node, di_minor_t minor, struct FFWalkTreeBundle const char* ffDetectPhysicalDisk(FFlist* result, FFPhysicalDiskOptions* options) { di_node_t rootNode = di_init("/", DINFOCPYALL); if (rootNode == DI_NODE_NIL) { + FF_DEBUG("di_init() failed"); return "di_init() failed"; } di_walk_minor(rootNode, DDI_NT_BLOCK, DI_WALK_CLDFIRST, &(struct FFWalkTreeBundle) { options, result }, (void*) walkDevTree); diff --git a/src/detection/physicalmemory/physicalmemory_linux.c b/src/detection/physicalmemory/physicalmemory_linux.c index c3e3fae96..6abd1021b 100644 --- a/src/detection/physicalmemory/physicalmemory_linux.c +++ b/src/detection/physicalmemory/physicalmemory_linux.c @@ -1,4 +1,5 @@ #include "physicalmemory.h" +#include "common/debug.h" #include "common/endian.h" #include "common/smbios.h" @@ -68,11 +69,13 @@ static_assert(offsetof(FFSmbiosMemoryDevice, RcdRevisionNumber) == 0x62, const char* ffDetectPhysicalMemory(FFPhysicalMemoryOptions* options, FFlist* result) { const FFSmbiosHeaderTable* smbiosTable = ffGetSmbiosHeaderTable(); if (!smbiosTable) { + FF_DEBUG("Failed to get SMBIOS data"); return "Failed to get SMBIOS data"; } const FFSmbiosMemoryDevice* data = (const FFSmbiosMemoryDevice*) (*smbiosTable)[FF_SMBIOS_TYPE_MEMORY_DEVICE]; if (!data) { + FF_DEBUG("Memory device is not found in SMBIOS data"); return "Memory device is not found in SMBIOS data"; } diff --git a/src/detection/poweradapter/poweradapter_linux.c b/src/detection/poweradapter/poweradapter_linux.c index fd0abcc1d..4a3375dc2 100644 --- a/src/detection/poweradapter/poweradapter_linux.c +++ b/src/detection/poweradapter/poweradapter_linux.c @@ -1,10 +1,12 @@ #include "poweradapter.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" #include #include #include +#include static void parsePowerAdapter(int dfd, const char* id, FFlist* results) { FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate(); @@ -72,6 +74,7 @@ static void parsePowerAdapter(int dfd, const char* id, FFlist* results) { const char* ffDetectPowerAdapter(FFlist* results) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/power_supply/"); if (dirp == nullptr) { + FF_DEBUG("opendir(\"/sys/class/power_supply/\") failed: %s", strerror(errno)); return "opendir(\"/sys/class/power_supply/\") == nullptr"; } diff --git a/src/detection/processes/processes_apple.c b/src/detection/processes/processes_apple.c index 727aeac02..5cbc32d65 100644 --- a/src/detection/processes/processes_apple.c +++ b/src/detection/processes/processes_apple.c @@ -1,6 +1,10 @@ #include "processes.h" +#include "common/debug.h" #include "common/mallocHelper.h" +#include +#include + #include #import @@ -9,6 +13,7 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu size_t length; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL, nullptr}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL, nullptr}) failed"; } @@ -17,6 +22,7 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu FF_AUTO_FREE struct kinfo_proc* processes = malloc(length); if (sysctl(request, ARRAY_SIZE(request), processes, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL, processes}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL, processes}) failed"; } diff --git a/src/detection/processes/processes_bsd.c b/src/detection/processes/processes_bsd.c index 32ee53736..1f70eea37 100644 --- a/src/detection/processes/processes_bsd.c +++ b/src/detection/processes/processes_bsd.c @@ -1,6 +1,9 @@ #include "processes.h" +#include "common/debug.h" #include "common/mallocHelper.h" +#include +#include #include #include #include @@ -9,6 +12,7 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu int request[] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC }; size_t length; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed"; } @@ -16,6 +20,7 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu length += length / 8 + sizeof(struct kinfo_proc); FF_AUTO_FREE struct kinfo_proc* procs = malloc(length); if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed"; } diff --git a/src/detection/processes/processes_haiku.c b/src/detection/processes/processes_haiku.c index feecc34e5..3f0496a2b 100644 --- a/src/detection/processes/processes_haiku.c +++ b/src/detection/processes/processes_haiku.c @@ -1,10 +1,13 @@ #include "processes.h" +#include "common/debug.h" #include const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResult* result) { system_info info; - if (get_system_info(&info) != B_OK) { + status_t status = get_system_info(&info); + if (status != B_OK) { + FF_DEBUG("Error getting system info: %d", (int) status); return "Error getting system info"; } diff --git a/src/detection/processes/processes_linux.c b/src/detection/processes/processes_linux.c index 68f819481..650ab6c75 100644 --- a/src/detection/processes/processes_linux.c +++ b/src/detection/processes/processes_linux.c @@ -1,14 +1,18 @@ #include "processes.h" +#include "common/debug.h" #include "common/io.h" #include "common/memrchr.h" #include "common/strutil.h" +#include + #define PF_KTHREAD 0x00200000 // defined in kernel include/linux/sched.h const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResult* result) { FF_AUTO_CLOSE_DIR DIR* dir = opendir("/proc"); if (dir == nullptr) { + FF_DEBUG("opendir(/proc) failed: %s", strerror(errno)); return "opendir(\"/proc\") failed"; } diff --git a/src/detection/processes/processes_nbsd.c b/src/detection/processes/processes_nbsd.c index cb91db096..7a7bc5e4d 100644 --- a/src/detection/processes/processes_nbsd.c +++ b/src/detection/processes/processes_nbsd.c @@ -1,6 +1,9 @@ #include "processes.h" +#include "common/debug.h" #include "common/mallocHelper.h" +#include +#include #include const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResult* result) { @@ -8,11 +11,13 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu size_t length = 0; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, nullptr}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, nullptr}) failed"; } FF_AUTO_FREE struct kinfo_proc2* procs = malloc(length); if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, procs}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, procs}) failed"; } diff --git a/src/detection/processes/processes_obsd.c b/src/detection/processes/processes_obsd.c index e07d45b1b..37fb9ab6f 100644 --- a/src/detection/processes/processes_obsd.c +++ b/src/detection/processes/processes_obsd.c @@ -1,7 +1,10 @@ #include "processes.h" +#include "common/debug.h" #include "common/mallocHelper.h" +#include +#include #include #include @@ -10,12 +13,14 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu size_t length = 0; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, nullptr) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, nullptr) failed"; } FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length); request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, procs) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, procs) failed"; } diff --git a/src/detection/processes/processes_sunos.c b/src/detection/processes/processes_sunos.c index a815390bb..e50419fa9 100644 --- a/src/detection/processes/processes_sunos.c +++ b/src/detection/processes/processes_sunos.c @@ -1,5 +1,6 @@ #include "processes.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -8,6 +9,7 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResult* result) { FF_AUTO_CLOSE_DIR DIR* dir = opendir("/proc"); if (dir == nullptr) { + FF_DEBUG("opendir(\"/proc\") failed: %s", strerror(errno)); return "opendir(\"/proc\") failed"; } diff --git a/src/detection/sound/sound_android.c b/src/detection/sound/sound_android.c index 78517f020..afa27ec6f 100644 --- a/src/detection/sound/sound_android.c +++ b/src/detection/sound/sound_android.c @@ -259,6 +259,7 @@ static const char* soundAndroidResolveCodes(FFSoundAndroidCodes* codes) { return error; } if (soundAndroidCodesIncomplete(codes)) { + FF_DEBUG("The audio service does not declare every method this module calls"); return "The audio service does not declare every method this module calls"; } return nullptr; @@ -271,6 +272,7 @@ static const char* soundAndroidResolveCodes(FFSoundAndroidCodes* codes) { // release build compiles out -- hence the attribute. static const char* soundAndroidCallInt(FFBinder* binder, uint32_t handle, [[maybe_unused]] const char* transactionField, int32_t transaction, bool hasArgument, int32_t argument, int32_t* result) { if (transaction == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("The audio service does not declare that method"); return "The audio service does not declare that method"; } @@ -374,6 +376,7 @@ static bool soundAndroidReadString16(const uint8_t* data, size_t size, size_t of // is taken from it. static const char* soundAndroidCallBtName(FFBinder* binder, uint32_t handle, int32_t transaction, FFstrbuf* result) { if (transaction == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("The audio service does not declare getBtActiveDeviceName"); return "The audio service does not declare getBtActiveDeviceName"; } @@ -397,6 +400,7 @@ static const char* soundAndroidCallBtName(FFBinder* binder, uint32_t handle, int return "The audio service raised an exception"; } if (!soundAndroidReadString16(reply.data, reply.size, sizeof(int32_t), result)) { + FF_DEBUG("The audio service answered a truncated device name"); return "The audio service answered a truncated device name"; } FF_DEBUG("\"%s\" is transaction %d and answered \"%s\"", FF_SOUND_ANDROID_GET_BT_ACTIVE_DEVICE_NAME, transaction, @@ -573,6 +577,7 @@ static const char* detectNative(FFSoundOptions* options, FFlist* devices) { } if (name == nullptr) { + FF_DEBUG("The audio service selected no output device"); return "The audio service selected no output device"; } diff --git a/src/detection/sound/sound_apple.c b/src/detection/sound/sound_apple.c index 36ebb2a8b..37f71e415 100644 --- a/src/detection/sound/sound_apple.c +++ b/src/detection/sound/sound_apple.c @@ -1,5 +1,6 @@ #include "sound.h" #include "common/apple/cf_helpers.h" +#include "common/debug.h" #include #include @@ -11,7 +12,9 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices /* List of FFSoundDevice */) { AudioDeviceID mainDeviceId; UInt32 dataSize = sizeof(mainDeviceId); - if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress) { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain }, 0, nullptr, &dataSize, &mainDeviceId) != kAudioHardwareNoError) { + OSStatus defaultOutputStatus = AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress) { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain }, 0, nullptr, &dataSize, &mainDeviceId); + if (defaultOutputStatus != kAudioHardwareNoError) { + FF_DEBUG("AudioObjectGetPropertyData(kAudioHardwarePropertyDefaultOutputDevice) failed: OSStatus %d", (int) defaultOutputStatus); return "AudioObjectGetPropertyData(kAudioHardwarePropertyDefaultOutputDevice) failed"; } @@ -21,7 +24,9 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices /* List of FF dataSize = sizeof(mainDeviceId); } else { dataSize = sizeof(deviceIds); - if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress) { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain }, 0, nullptr, &dataSize, &deviceIds) != kAudioHardwareNoError) { + OSStatus deviceListStatus = AudioObjectGetPropertyData(kAudioObjectSystemObject, &(AudioObjectPropertyAddress) { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain }, 0, nullptr, &dataSize, &deviceIds); + if (deviceListStatus != kAudioHardwareNoError) { + FF_DEBUG("AudioObjectGetPropertyData(kAudioHardwarePropertyDevices) failed: OSStatus %d", (int) deviceListStatus); return "AudioObjectGetPropertyData(kAudioHardwarePropertyDevices) failed"; } } diff --git a/src/detection/sound/sound_bsd.c b/src/detection/sound/sound_bsd.c index 118b33b09..b5e5a373e 100644 --- a/src/detection/sound/sound_bsd.c +++ b/src/detection/sound/sound_bsd.c @@ -1,4 +1,5 @@ #include "sound.h" +#include "common/debug.h" #include "common/io.h" #include "common/sysctl.h" @@ -10,6 +11,7 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { #ifndef __NetBSD__ int defaultDev = ffSysctlGetInt("hw.snd.default_unit", -1); if (defaultDev == -1) { + FF_DEBUG("sysctl(hw.snd.default_unit) failed"); return "sysctl(hw.snd.default_unit) failed"; } #else @@ -18,10 +20,12 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { char mixerp[12]; ssize_t plen = readlink("/dev/mixer", mixerp, ARRAY_SIZE(mixerp)); if (plen < 6) { + FF_DEBUG("readlink(/dev/mixer) failed: %s", strerror(errno)); return "readlink(/dev/mixer) failed"; } defaultDev = mixerp[plen - 1] - '0'; if (defaultDev < 0 || defaultDev > 9) { + FF_DEBUG("Invalid mixer device"); return "Invalid mixer device"; } } @@ -45,6 +49,7 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { if (idev == 0) { if (ioctl(fd, SNDCTL_SYSINFO, &info) != 0) { + FF_DEBUG("ioctl(SNDCTL_SYSINFO) failed: %s", strerror(errno)); return "ioctl(SNDCTL_SYSINFO) failed"; } } diff --git a/src/detection/sound/sound_linux.c b/src/detection/sound/sound_linux.c index a615ee983..600975349 100644 --- a/src/detection/sound/sound_linux.c +++ b/src/detection/sound/sound_linux.c @@ -686,6 +686,7 @@ static bool recvFrame(FFSoundPulseConn* conn) { static const char* recvReply(FFSoundPulseConn* conn, uint32_t tag, FFSoundPulseReader* reader) { while (true) { if (!recvFrame(conn)) { + FF_DEBUG("Failed to read the pulseaudio reply to tag %u", tag); return "Failed to read a pulseaudio reply"; } @@ -695,6 +696,7 @@ static const char* recvReply(FFSoundPulseConn* conn, uint32_t tag, FFSoundPulseR // Both the command and the tag are tagged u32s, so they must be read as // values. Reading four raw bytes here would swallow the 'L' of the tag. if (!readU32Value(&frame, &command) || !readU32Value(&frame, &replyTag)) { + FF_DEBUG("Malformed pulseaudio reply to tag %u: %u payload bytes", tag, frame.length); return "Malformed pulseaudio reply"; } @@ -707,15 +709,18 @@ static const char* recvReply(FFSoundPulseConn* conn, uint32_t tag, FFSoundPulseR if (command == FF_SOUND_PA_COMMAND_ERROR) { uint32_t error = 0; if (!readU32Value(&frame, &error)) { + FF_DEBUG("Malformed pulseaudio error reply to tag %u: %u payload bytes", tag, frame.length); return "Malformed pulseaudio error reply"; } FF_DEBUG("The pulseaudio server returned the error %u", error); if (error == FF_SOUND_PA_ERROR_ACCESS) { + FF_DEBUG("The pulseaudio server denied access to the AUTH request"); return "Access to the pulseaudio server was denied"; } if (error == FF_SOUND_PA_ERROR_VERSION) { + FF_DEBUG("The pulseaudio server rejected our protocol version %u", FF_SOUND_PA_VERSION); return "The pulseaudio server is too old"; } @@ -723,6 +728,7 @@ static const char* recvReply(FFSoundPulseConn* conn, uint32_t tag, FFSoundPulseR } if (command != FF_SOUND_PA_COMMAND_REPLY) { + FF_DEBUG("Unexpected pulseaudio command %u in the reply to tag %u", command, tag); return "Unexpected pulseaudio reply"; } @@ -748,6 +754,7 @@ static const char* handshake(FFSoundPulseConn* conn, FFstrbuf* serverName, FFstr putTagArbitrary(&payload, cookie, sizeof(cookie)); if (!sendFrame(conn, &payload, true)) { + FF_DEBUG("Failed to send the pulseaudio AUTH request (tag %u)", tag); return "Failed to send the pulseaudio AUTH request"; } @@ -783,6 +790,7 @@ static const char* handshake(FFSoundPulseConn* conn, FFstrbuf* serverName, FFstr } if (!sendFrame(conn, &payload, false)) { + FF_DEBUG("Failed to send the pulseaudio SET_CLIENT_NAME request (tag %u)", tag); return "Failed to send the pulseaudio SET_CLIENT_NAME request"; } @@ -800,6 +808,7 @@ static const char* handshake(FFSoundPulseConn* conn, FFstrbuf* serverName, FFstr putTagU32(&payload, tag); if (!sendFrame(conn, &payload, false)) { + FF_DEBUG("Failed to send the pulseaudio GET_SERVER_INFO request (tag %u)", tag); return "Failed to send the pulseaudio GET_SERVER_INFO request"; } @@ -1038,6 +1047,7 @@ static const char* fetchSinkList(FFSoundPulseConn* conn, const FFSoundOptions* o putTagU32(&payload, tag); if (!sendFrame(conn, &payload, false)) { + FF_DEBUG("Failed to send the pulseaudio GET_SINK_INFO_LIST request (tag %u)", tag); return "Failed to send the pulseaudio GET_SINK_INFO_LIST request"; } @@ -1052,6 +1062,7 @@ static const char* fetchSinkList(FFSoundPulseConn* conn, const FFSoundOptions* o while (!reader.error && !readerEof(&reader)) { FFSoundPulseSinkInfo sink = {}; if (!readSinkInfo(&reader, conn, defaultSinkName, &sink)) { + FF_DEBUG("Failed to parse a pulseaudio sink at payload offset %u of %u", reader.offset, reader.length); return "Failed to parse the pulseaudio sink list"; } @@ -1067,6 +1078,7 @@ static const char* fetchSinkList(FFSoundPulseConn* conn, const FFSoundOptions* o } if (reader.error) { + FF_DEBUG("The pulseaudio sink list ended at payload offset %u of %u", reader.offset, reader.length); return "Failed to parse the pulseaudio sink list"; } @@ -1125,6 +1137,8 @@ ffDetectSound } if (conn.fd < 0) { + FF_DEBUG("Failed to connect to the pulseaudio server on %s", + defaultSocketPath.length > 0 ? defaultSocketPath.chars : "no known socket path"); ffStrbufDestroy(&conn.frame); return "Failed to connect to the pulseaudio server"; } diff --git a/src/detection/sound/sound_nbsd.c b/src/detection/sound/sound_nbsd.c index f52ba2cfe..b67689828 100644 --- a/src/detection/sound/sound_nbsd.c +++ b/src/detection/sound/sound_nbsd.c @@ -1,4 +1,5 @@ #include "sound.h" +#include "common/debug.h" #include "common/io.h" #include @@ -13,10 +14,12 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { char audiop[12]; ssize_t plen = readlink("/dev/audio", audiop, ARRAY_SIZE(audiop)); if (plen < (ssize_t) strlen("audioN")) { + FF_DEBUG("readlink(/dev/audio) failed"); return "readlink(/dev/audio) failed"; } defaultDev = audiop[plen - 1] - '0'; if (defaultDev < 0 || defaultDev > 9) { + FF_DEBUG("Invalid audio device"); return "Invalid audio device"; } } diff --git a/src/detection/sound/sound_obsd.c b/src/detection/sound/sound_obsd.c index e2c4238b5..4dccec835 100644 --- a/src/detection/sound/sound_obsd.c +++ b/src/detection/sound/sound_obsd.c @@ -1,4 +1,5 @@ #include "sound.h" +#include "common/debug.h" #include "common/strutil.h" #include @@ -59,15 +60,18 @@ static void enumerate_props(FFSoundDeviceBundle* bundle, struct sioctl_desc* des const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { [[gnu::cleanup(close_hdl)]] struct sioctl_hdl* hdl = sioctl_open(SIO_DEVANY, SIOCTL_READ, 0); if (!hdl) { + FF_DEBUG("sio_open() failed"); return "sio_open() failed"; } FFSoundDeviceBundle bundle = {}; if (sioctl_ondesc(hdl, (void*) enumerate_props, &bundle) == 0) { + FF_DEBUG("sioctl_ondesc() failed"); return "sioctl_ondesc() failed"; } if (bundle.iLevel != bundle.iMute || bundle.iLevel == 0) { + FF_DEBUG("Unexpected sioctl_ondesc() result"); return "Unexpected sioctl_ondesc() result"; } diff --git a/src/detection/sound/sound_sunos.c b/src/detection/sound/sound_sunos.c index 3f5e2219e..98492173d 100644 --- a/src/detection/sound/sound_sunos.c +++ b/src/detection/sound/sound_sunos.c @@ -1,4 +1,5 @@ #include "sound.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -17,10 +18,12 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { char mixerp[12]; ssize_t plen = readlink("/dev/audio", mixerp, ARRAY_SIZE(mixerp)); if (plen < 6) { + FF_DEBUG("readlink(/dev/audio) failed"); return "readlink(/dev/audio) failed"; } defaultDev = mixerp[plen - 1] - '0'; if (defaultDev < 0 || defaultDev > 9) { + FF_DEBUG("Invalid mixer device"); return "Invalid mixer device"; } } @@ -46,6 +49,7 @@ const char* ffDetectSound(FFSoundOptions* options, FFlist* devices) { if (idev == 0) { if (ioctl(fd, SNDCTL_SYSINFO, &info) != 0) { + FF_DEBUG("ioctl(SNDCTL_SYSINFO) failed: %s", strerror(errno)); return "ioctl(SNDCTL_SYSINFO) failed"; } if (ffAppendFDBuffer(fd, &sndstat)) { diff --git a/src/detection/swap/swap_apple.c b/src/detection/swap/swap_apple.c index 3c457c0ec..b1fd8abd3 100644 --- a/src/detection/swap/swap_apple.c +++ b/src/detection/swap/swap_apple.c @@ -1,12 +1,17 @@ #include "swap.h" +#include "common/debug.h" #include "common/sysctl.h" + +#include +#include #include const char* ffDetectSwap(FFlist* result) { struct xsw_usage xsw; size_t size = sizeof(xsw); if (sysctl((int[]) { CTL_VM, VM_SWAPUSAGE }, 2, &xsw, &size, nullptr, 0) != 0) { + FF_DEBUG("sysctl(vm.swapusage) failed: %s", strerror(errno)); return "Failed to read vm.swapusage"; } diff --git a/src/detection/swap/swap_bsd.c b/src/detection/swap/swap_bsd.c index 8674e76a8..eab6f5cfb 100644 --- a/src/detection/swap/swap_bsd.c +++ b/src/detection/swap/swap_bsd.c @@ -1,6 +1,9 @@ #include "swap.h" +#include "common/debug.h" #include "common/sysctl.h" +#include +#include #include #include #include @@ -26,6 +29,7 @@ const char* ffDetectSwap(FFlist* result) { struct xswdev xsws[32]; size_t size = sizeof(xsws); if (sysctlbyname("vm.swap_info_array", xsws, &size, nullptr, 0) < 0) { + FF_DEBUG("sysctlbyname(\"vm.swap_info_array\") failed: %s", strerror(errno)); return "sysctlbyname(\"vm.swap_info_array\") failed"; } @@ -37,6 +41,7 @@ const char* ffDetectSwap(FFlist* result) { } if (xsws->xsw_version != XSWDEV_VERSION) { + FF_DEBUG("xswdev version mismatch"); return "xswdev version mismatch"; } @@ -53,6 +58,7 @@ const char* ffDetectSwap(FFlist* result) { int mib[16]; size_t mibsize = ARRAY_SIZE(mib); if (sysctlnametomib("vm.swap_info", mib, &mibsize) < 0) { + FF_DEBUG("sysctlnametomib(\"vm.swap_info\") failed: %s", strerror(errno)); return "sysctlnametomib(\"vm.swap_info\") failed"; } @@ -66,6 +72,7 @@ const char* ffDetectSwap(FFlist* result) { break; } if (xsw.xsw_version != XSWDEV_VERSION) { + FF_DEBUG("xswdev version mismatch"); return "xswdev version mismatch"; } diff --git a/src/detection/swap/swap_haiku.c b/src/detection/swap/swap_haiku.c index f4b031a95..10f3fccff 100644 --- a/src/detection/swap/swap_haiku.c +++ b/src/detection/swap/swap_haiku.c @@ -1,11 +1,14 @@ #include "swap.h" +#include "common/debug.h" #include #include const char* ffDetectSwap(FFlist* result) { system_info info; - if (get_system_info(&info) != B_OK) { + status_t status = get_system_info(&info); + if (status != B_OK) { + FF_DEBUG("get_system_info() failed: %d", (int) status); return "Error getting system info"; } diff --git a/src/detection/swap/swap_linux.c b/src/detection/swap/swap_linux.c index 5d456626c..a49418184 100644 --- a/src/detection/swap/swap_linux.c +++ b/src/detection/swap/swap_linux.c @@ -1,5 +1,6 @@ #include "swap.h" +#include "common/debug.h" #include "common/io.h" #include "common/mallocHelper.h" @@ -11,6 +12,7 @@ static const char* detectByProcMeminfo(FFlist* result) { char buf[PROC_FILE_BUFFSIZ]; ssize_t nRead = ffReadFileData("/proc/meminfo", ARRAY_SIZE(buf) - 1, buf); if (nRead < 0) { + FF_DEBUG("ffReadFileData(\"/proc/meminfo\") failed"); return "ffReadFileData(\"/proc/meminfo\", ARRAY_SIZE(buf)-1, buf)"; } buf[nRead] = '\0'; @@ -39,6 +41,7 @@ static const char* detectByProcSwaps(FFlist* result) { char buf[PROC_FILE_BUFFSIZ]; ssize_t nRead = ffReadFileData("/proc/swaps", ARRAY_SIZE(buf) - 1, buf); if (nRead <= 0) { + FF_DEBUG("ffReadFileData(\"/proc/swaps\") failed"); return "ffReadFileData(\"/proc/swaps\", ARRAY_SIZE(buf)-1, buf) failed"; } buf[nRead] = '\0'; @@ -50,6 +53,7 @@ static const char* detectByProcSwaps(FFlist* result) { uint64_t total, used; char name[256]; if (sscanf(line, "%255s %*[^\t]%" SCNu64 "%" SCNu64, name, &total, &used) != 3) { + FF_DEBUG("Invalid /proc/swaps format found"); return "Invalid /proc/swaps format found"; } diff --git a/src/detection/swap/swap_obsd.c b/src/detection/swap/swap_obsd.c index 9c2c98c9e..75750ab11 100644 --- a/src/detection/swap/swap_obsd.c +++ b/src/detection/swap/swap_obsd.c @@ -1,7 +1,10 @@ #include "swap.h" +#include "common/debug.h" #include "common/FFlist.h" #include "common/mallocHelper.h" +#include +#include #include #include #include @@ -10,6 +13,7 @@ const char* ffDetectSwap(FFlist* result) { int nswap = swapctl(SWAP_NSWAP, 0, 0); if (nswap < 0) { + FF_DEBUG("swapctl(SWAP_NSWAP) failed: %s", strerror(errno)); return "swapctl(SWAP_NSWAP) failed"; } if (nswap == 0) { @@ -19,6 +23,7 @@ const char* ffDetectSwap(FFlist* result) { FF_AUTO_FREE struct swapent* swdev = malloc((uint32_t) nswap * sizeof(*swdev)); if (swapctl(SWAP_STATS, swdev, nswap) < 0) { + FF_DEBUG("swapctl(SWAP_STATS) failed: %s", strerror(errno)); return "swapctl(SWAP_STATS) failed"; } diff --git a/src/detection/swap/swap_sunos.c b/src/detection/swap/swap_sunos.c index 24a2df139..3c48291ae 100644 --- a/src/detection/swap/swap_sunos.c +++ b/src/detection/swap/swap_sunos.c @@ -1,4 +1,7 @@ #include "swap.h" +#include "common/debug.h" +#include +#include #include #include #include @@ -17,6 +20,7 @@ const char* ffDetectSwap(FFlist* result) { int size = swapctl(SC_LIST, table); if (size < 0) { + FF_DEBUG("swapctl() failed: %s", strerror(errno)); return "swapctl() failed"; } diff --git a/src/detection/theme/theme_linux.c b/src/detection/theme/theme_linux.c index 6f2bc2117..b3684c8b8 100644 --- a/src/detection/theme/theme_linux.c +++ b/src/detection/theme/theme_linux.c @@ -1,4 +1,5 @@ #include "theme.h" +#include "common/debug.h" #include "common/parsing.h" #include "detection/gtk_qt/gtk_qt.h" #include "detection/displayserver/displayserver.h" @@ -16,6 +17,7 @@ const char* ffDetectTheme(FFThemeResult* result) { const FFstrbuf* gtk4 = &ffDetectGTK4()->theme; if (plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) { + FF_DEBUG("No themes found"); return "No themes found"; } diff --git a/src/detection/top/top_apple.c b/src/detection/top/top_apple.c index 5d5c9208e..3e5cc5ba1 100644 --- a/src/detection/top/top_apple.c +++ b/src/detection/top/top_apple.c @@ -1,13 +1,16 @@ #include "top.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include +#include #include #include const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) { int npids = proc_listallpids(nullptr, 0); if (npids <= 0) { + FF_DEBUG("proc_listallpids(nullptr, 0) failed: %s", strerror(errno)); return "proc_listallpids(nullptr, 0) failed"; } // `proc_listallpids` returns the number of pids, but it wants the size of the buffer in bytes: @@ -15,10 +18,12 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) { const int pidCapacity = npids + npids / 8 + 1; FF_AUTO_FREE pid_t* pids = malloc((size_t) pidCapacity * sizeof(pid_t)); if (pids == nullptr) { + FF_DEBUG("malloc(%zu) for %d pids failed", (size_t) pidCapacity * sizeof(pid_t), pidCapacity); return "malloc() failed"; } npids = proc_listallpids(pids, pidCapacity * (int) sizeof(pid_t)); if (npids <= 0) { + FF_DEBUG("proc_listallpids(pids, %d) failed: %s", pidCapacity * (int) sizeof(pid_t), strerror(errno)); return "proc_listallpids(pids, bufferSize) failed"; } diff --git a/src/detection/top/top_bsd.c b/src/detection/top/top_bsd.c index 959b7f3d7..60684cb1d 100644 --- a/src/detection/top/top_bsd.c +++ b/src/detection/top/top_bsd.c @@ -1,6 +1,10 @@ #include "top.h" +#include "common/debug.h" #include "common/mallocHelper.h" +#include +#include + #include #include #include @@ -11,6 +15,7 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, [[maybe_unused]] FFTopTyp size_t length; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}, nullptr) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed"; } @@ -18,6 +23,7 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, [[maybe_unused]] FFTopTyp length += length / 8 + sizeof(struct kinfo_proc); FF_AUTO_FREE struct kinfo_proc* processes = malloc(length); if (sysctl(request, ARRAY_SIZE(request), processes, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}, processes) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_PROC}) failed"; } uint32_t count = (uint32_t) (length / sizeof(struct kinfo_proc)); diff --git a/src/detection/top/top_nbsd.c b/src/detection/top/top_nbsd.c index c5d79d65c..0a64903cf 100644 --- a/src/detection/top/top_nbsd.c +++ b/src/detection/top/top_nbsd.c @@ -1,16 +1,19 @@ #include "top.h" +#include "common/debug.h" #include "common/mallocHelper.h" #include #include #include #include +#include const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) { int request[] = { CTL_KERN, KERN_PROC2, KERN_PROC_ALL, -1, sizeof(struct kinfo_proc2), INT_MAX }; size_t length; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, nullptr}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, nullptr}) failed"; } @@ -19,6 +22,7 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) { FF_AUTO_FREE struct kinfo_proc2* processes = malloc(length); if (sysctl(request, ARRAY_SIZE(request), processes, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, processes}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC2, KERN_PROC_ALL, processes}) failed"; } uint32_t count = (uint32_t) (length / sizeof(struct kinfo_proc2)); diff --git a/src/detection/top/top_obsd.c b/src/detection/top/top_obsd.c index 30861f873..b178f927c 100644 --- a/src/detection/top/top_obsd.c +++ b/src/detection/top/top_obsd.c @@ -1,7 +1,10 @@ #include "top.h" +#include "common/debug.h" #include "common/mallocHelper.h" +#include +#include #include #include // DEV_BSIZE #include @@ -11,12 +14,14 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) { size_t length = 0; if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, nullptr) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, nullptr) failed"; } FF_AUTO_FREE struct kinfo_proc* processes = (struct kinfo_proc*) malloc(length); request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch if (sysctl(request, ARRAY_SIZE(request), processes, &length, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, processes) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, processes) failed"; } diff --git a/src/detection/top/top_sunos.c b/src/detection/top/top_sunos.c index 0054ae79a..7722d9a90 100644 --- a/src/detection/top/top_sunos.c +++ b/src/detection/top/top_sunos.c @@ -1,15 +1,19 @@ #include "top.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" +#include #include +#include #include #include // DEV_BSIZE const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) { FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/proc"); if (!dirp) { + FF_DEBUG("opendir(\"/proc\") failed: %s", strerror(errno)); return "opendir(\"/proc\") failed"; } diff --git a/src/detection/tpm/tpm_apple.c b/src/detection/tpm/tpm_apple.c index b97ecf05b..774e13b0d 100644 --- a/src/detection/tpm/tpm_apple.c +++ b/src/detection/tpm/tpm_apple.c @@ -1,4 +1,5 @@ #include "tpm.h" +#include "common/debug.h" #ifndef __aarch64__ #include "common/apple/cf_helpers.h" @@ -26,5 +27,6 @@ const char* ffDetectTPM(FFTPMResult* result) { #endif + FF_DEBUG("Neither Apple T2 nor Apple Silicon Security was reported by IOKit"); return "No Apple Security hardware detected"; } diff --git a/src/detection/tpm/tpm_bsd.c b/src/detection/tpm/tpm_bsd.c index 1df25fb47..380cb3917 100644 --- a/src/detection/tpm/tpm_bsd.c +++ b/src/detection/tpm/tpm_bsd.c @@ -1,12 +1,15 @@ #include "tpm.h" +#include "common/debug.h" #include "common/sysctl.h" #include "common/kmod.h" const char* ffDetectTPM(FFTPMResult* result) { if (ffSysctlGetString("dev.tpmcrb.0.%desc", &result->description) != nullptr) { if (!ffKmodLoaded("tpm")) { + FF_DEBUG("`tpm` kernel module is not loaded"); return "`tpm` kernel module is not loaded"; } + FF_DEBUG("TPM device is not found"); return "TPM device is not found"; } diff --git a/src/detection/tpm/tpm_linux.c b/src/detection/tpm/tpm_linux.c index 7a54f27f8..e34a3d5ba 100644 --- a/src/detection/tpm/tpm_linux.c +++ b/src/detection/tpm/tpm_linux.c @@ -1,11 +1,14 @@ #include "tpm.h" +#include "common/debug.h" #include "common/io.h" const char* ffDetectTPM(FFTPMResult* result) { if (!ffPathExists("/sys/class/tpm/tpm0/", FF_PATHTYPE_DIRECTORY)) { if (!ffPathExists("/sys/class/tpm/", FF_PATHTYPE_DIRECTORY)) { + FF_DEBUG("/sys/class/tpm/ does not exist, the kernel has no TPM support"); return "TPM is not supported by kernel"; } + FF_DEBUG("/sys/class/tpm/ exists but /sys/class/tpm/tpm0/ does not"); return "TPM device is not found"; } diff --git a/src/detection/uptime/uptime_bsd.c b/src/detection/uptime/uptime_bsd.c index 00d052b37..80892a383 100644 --- a/src/detection/uptime/uptime_bsd.c +++ b/src/detection/uptime/uptime_bsd.c @@ -1,6 +1,9 @@ #include "uptime.h" +#include "common/debug.h" #include "common/time.h" +#include +#include #include #include @@ -13,6 +16,7 @@ const char* ffDetectUptime(FFUptimeResult* result) { size_t bootTimeSize = sizeof(bootTime); if (sysctl( (int[]) { CTL_KERN, KERN_BOOTTIME }, 2, &bootTime, &bootTimeSize, nullptr, 0) != 0) { + FF_DEBUG("sysctl({CTL_KERN, KERN_BOOTTIME}) failed: %s", strerror(errno)); return "sysctl({CTL_KERN, KERN_BOOTTIME}) failed"; } diff --git a/src/detection/uptime/uptime_linux.c b/src/detection/uptime/uptime_linux.c index 9ac709416..1f9888417 100644 --- a/src/detection/uptime/uptime_linux.c +++ b/src/detection/uptime/uptime_linux.c @@ -1,8 +1,11 @@ #include "uptime.h" +#include "common/debug.h" #include "common/time.h" #include "common/io.h" +#include #include +#include const char* ffDetectUptime(FFUptimeResult* result) { #ifndef __ANDROID__ // cat: /proc/uptime: Permission denied @@ -26,6 +29,7 @@ const char* ffDetectUptime(FFUptimeResult* result) { #ifndef __GNU__ struct timespec uptime; if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0) { + FF_DEBUG("clock_gettime(CLOCK_BOOTTIME) failed: %s", strerror(errno)); return "clock_gettime(CLOCK_BOOTTIME) failed"; } @@ -33,6 +37,7 @@ const char* ffDetectUptime(FFUptimeResult* result) { result->bootTime = ffTimeGetNow() - result->uptime; return nullptr; #else + FF_DEBUG("read(/proc/uptime) failed"); return "read(/proc/uptime) failed"; #endif } diff --git a/src/detection/users/users_linux.c b/src/detection/users/users_linux.c index a5f31d2a0..e304b29cb 100644 --- a/src/detection/users/users_linux.c +++ b/src/detection/users/users_linux.c @@ -1,8 +1,10 @@ +#include "common/debug.h" #include "common/io.h" #include "common/properties.h" #include "fastfetch.h" #include "users.h" +#include #include #if FF_HAVE_UTMPX @@ -102,6 +104,7 @@ const char* detectBySystemd(FFUsersOptions* options, FFlist* users) { const uint32_t pathUsersBaseLen = pathUsers.length; FF_AUTO_CLOSE_DIR DIR* dirp = opendir(pathUsers.chars); if (!dirp) { + FF_DEBUG("opendir(\"%s\") failed: %s", pathUsers.chars, strerror(errno)); return "opendir(\"/run/systemd/users/\") failed"; } diff --git a/src/detection/users/users_obsd.c b/src/detection/users/users_obsd.c index a9b03072c..d74a71bb5 100644 --- a/src/detection/users/users_obsd.c +++ b/src/detection/users/users_obsd.c @@ -1,12 +1,17 @@ #include "fastfetch.h" #include "users.h" +#include "common/debug.h" #include "common/io.h" +#include +#include + #include const char* ffDetectUsers([[maybe_unused]] FFUsersOptions* options, FFlist* users) { FF_AUTO_CLOSE_FILE FILE* fp = fopen(_PATH_UTMP, "r"); if (!fp) { + FF_DEBUG("fopen(\"%s\", \"r\") failed: %s", _PATH_UTMP, strerror(errno)); return "fopen(_PATH_UTMP, r) failed"; } diff --git a/src/detection/wallpaper/wallpaper_android.c b/src/detection/wallpaper/wallpaper_android.c index 163d76130..ee16dc003 100644 --- a/src/detection/wallpaper/wallpaper_android.c +++ b/src/detection/wallpaper/wallpaper_android.c @@ -6,6 +6,8 @@ #include "common/io.h" #include "detection/displayserver/displayserver.h" +#include +#include #include // Android keeps the wallpaper as a file per user, in a directory no app can enter: @@ -124,13 +126,14 @@ static const char* getWallpaperFile(FFBinder* binder, uint32_t handle, const cha char path[64]; const int pathLength = snprintf(path, sizeof(path), "/proc/self/fd/%d", (int) fd); if (pathLength <= 0 || (size_t) pathLength >= sizeof(path)) { + FF_DEBUG("Failed to build the /proc path of the wallpaper descriptor"); return "Failed to build the /proc path of the wallpaper descriptor"; } char target[512]; const ssize_t length = readlink(path, target, sizeof(target) - 1); if (length <= 0) { - FF_DEBUG("readlink(%s) failed", path); + FF_DEBUG("readlink(%s) failed: %s", path, strerror(errno)); return "Failed to resolve the wallpaper path"; } target[length] = '\0'; @@ -155,6 +158,7 @@ const char* ffDetectWallpaper(FFstrbuf* result) { char package[FF_WALLPAPER_ANDROID_PACKAGE_SIZE]; if (!ffAndroidGetOwnPackage(package, sizeof(package))) { + FF_DEBUG("Cannot determine the package name of this process"); return "Cannot determine the package name of this process"; } @@ -170,6 +174,7 @@ const char* ffDetectWallpaper(FFstrbuf* result) { return error; } if (transaction == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("The wallpaper service does not declare getWallpaper"); return "The wallpaper service does not declare getWallpaper"; } diff --git a/src/detection/wallpaper/wallpaper_haiku.cpp b/src/detection/wallpaper/wallpaper_haiku.cpp index ee17f16a0..4b17d5c0e 100644 --- a/src/detection/wallpaper/wallpaper_haiku.cpp +++ b/src/detection/wallpaper/wallpaper_haiku.cpp @@ -1,5 +1,6 @@ extern "C" { #include "wallpaper.h" +#include "common/debug.h" #include "common/mallocHelper.h" } @@ -18,6 +19,7 @@ const char* ffDetectWallpaper(FFstrbuf* result) { BString path; if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK) { + FF_DEBUG("find_directory(B_DESKTOP_DIRECTORY) failed"); return "find_directory(B_DESKTOP_DIRECTORY) failed"; } @@ -46,6 +48,7 @@ const char* ffDetectWallpaper(FFstrbuf* result) { } if (path.Length() < 1) { + FF_DEBUG("Failed to detect the current wallpaper path"); return "Failed to detect the current wallpaper path"; } diff --git a/src/detection/wallpaper/wallpaper_linux.c b/src/detection/wallpaper/wallpaper_linux.c index b63f93ab1..85bf3287f 100644 --- a/src/detection/wallpaper/wallpaper_linux.c +++ b/src/detection/wallpaper/wallpaper_linux.c @@ -1,4 +1,5 @@ #include "wallpaper.h" +#include "common/debug.h" #include "common/io.h" #include "common/settings.h" #include "detection/displayserver/displayserver.h" @@ -39,16 +40,19 @@ static const char* detectCosmicComp(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate(); if (!ffReadFileBuffer(path.chars, &output)) { + FF_DEBUG("Failed to read \"%s\"", path.chars); return "Failed to read COSMIC wallpaper config"; } const char* sourceStart = strstr(output.chars, "source:"); if (sourceStart == nullptr) { + FF_DEBUG("The COSMIC wallpaper config does not contain \"source:\""); return "COSMIC wallpaper config doesn't contain source"; } const char* pathStart = strstr(sourceStart, "Path("); if (pathStart == nullptr) { + FF_DEBUG("The COSMIC wallpaper source does not contain \"Path(\""); return "COSMIC wallpaper source is not a Path value"; } @@ -58,6 +62,7 @@ static const char* detectCosmicComp(FFstrbuf* result) { } if (*pathStart != '\'' && *pathStart != '"') { + FF_DEBUG("The COSMIC wallpaper Path does not start with a quote"); return "COSMIC wallpaper Path format is invalid"; } @@ -65,6 +70,7 @@ static const char* detectCosmicComp(FFstrbuf* result) { ++pathStart; const char* pathEnd = strchr(pathStart, quote); if (pathEnd == nullptr || pathEnd == pathStart) { + FF_DEBUG("The COSMIC wallpaper path is empty"); return "COSMIC wallpaper path is empty"; } @@ -99,6 +105,7 @@ ffDetectWallpaper } if (!wallpaper) { + FF_DEBUG("Neither GTK nor Qt reported a wallpaper path"); return "Failed to detect the current wallpaper path"; } diff --git a/src/detection/wifi/wifi_android.c b/src/detection/wifi/wifi_android.c index cbb4d37e1..120f9b531 100644 --- a/src/detection/wifi/wifi_android.c +++ b/src/detection/wifi/wifi_android.c @@ -851,6 +851,7 @@ static const char* resolveCodes(FFWifiAndroidCodes* codes) { return error; } if (codes->getConnectionInfo == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("The Wifi service does not declare getConnectionInfo"); return "The Wifi service does not declare getConnectionInfo"; } return nullptr; @@ -863,6 +864,7 @@ static const char* resolveCodes(FFWifiAndroidCodes* codes) { // build compiles out -- hence the attribute. static const char* callIntMethod(FFBinder* binder, uint32_t handle, [[maybe_unused]] const char* transactionField, int32_t transaction, int32_t* result) { if (transaction == FF_DEX_STATIC_INT_UNRESOLVED) { + FF_DEBUG("The Wifi service does not declare that method"); return "The Wifi service does not declare that method"; } @@ -906,6 +908,7 @@ static const char* callIntMethod(FFBinder* binder, uint32_t handle, [[maybe_unus static const char* detectWithBinder(FFlist* result) { char package[FF_WIFI_ANDROID_PACKAGE_SIZE]; if (!ffAndroidGetOwnPackage(package, sizeof(package))) { + FF_DEBUG("Cannot determine the package name of this process"); return "Cannot determine the package name of this process"; } @@ -983,6 +986,7 @@ static const char* detectWithBinder(FFlist* result) { // Nothing was found to report on at all. That is a device without a Wi-Fi interface rather than // one with a Wi-Fi that is off, which has a state to print by now. if (!connection.upKnown && !connection.connected) { + FF_DEBUG("No Wi-Fi interface is present"); return "No Wi-Fi interface is present"; } diff --git a/src/detection/wifi/wifi_bsd.c b/src/detection/wifi/wifi_bsd.c index 4b55d0257..67af7f5c7 100644 --- a/src/detection/wifi/wifi_bsd.c +++ b/src/detection/wifi/wifi_bsd.c @@ -1,4 +1,5 @@ #include "wifi.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" @@ -11,11 +12,13 @@ const char* ffDetectWifi(FFlist* result) { struct if_nameindex* infs = if_nameindex(); if (!infs) { + FF_DEBUG("if_nameindex() failed: %s", strerror(errno)); return "if_nameindex() failed"; } FF_AUTO_CLOSE_FD int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { + FF_DEBUG("socket() failed: %s", strerror(errno)); if_freenameindex(infs); return "socket() failed"; } diff --git a/src/detection/wifi/wifi_nbsd.c b/src/detection/wifi/wifi_nbsd.c index e2b083679..f423be03e 100644 --- a/src/detection/wifi/wifi_nbsd.c +++ b/src/detection/wifi/wifi_nbsd.c @@ -1,7 +1,11 @@ #include "wifi.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" +#include +#include + #define COMPAT_FREEBSD_NET80211 1 #include #include @@ -21,11 +25,13 @@ const char* ffDetectWifi(FFlist* result) { struct if_nameindex* infs = if_nameindex(); if (!infs) { + FF_DEBUG("if_nameindex() failed: %s", strerror(errno)); return "if_nameindex() failed"; } FF_AUTO_CLOSE_FD int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { + FF_DEBUG("socket(AF_INET, SOCK_DGRAM) failed: %s", strerror(errno)); if_freenameindex(infs); return "socket() failed"; } diff --git a/src/detection/wifi/wifi_obsd.c b/src/detection/wifi/wifi_obsd.c index a9817c051..7cb946b52 100644 --- a/src/detection/wifi/wifi_obsd.c +++ b/src/detection/wifi/wifi_obsd.c @@ -1,4 +1,5 @@ #include "wifi.h" +#include "common/debug.h" #include "common/io.h" #include @@ -11,11 +12,13 @@ const char* ffDetectWifi(FFlist* result) { struct if_nameindex* infs = if_nameindex(); if (!infs) { + FF_DEBUG("if_nameindex() failed: %s", strerror(errno)); return "if_nameindex() failed"; } FF_AUTO_CLOSE_FD int sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { + FF_DEBUG("socket() failed: %s", strerror(errno)); if_freenameindex(infs); return "socket() failed"; } diff --git a/src/detection/wifi/wifi_sunos.c b/src/detection/wifi/wifi_sunos.c index 651705098..bddfe44e0 100644 --- a/src/detection/wifi/wifi_sunos.c +++ b/src/detection/wifi/wifi_sunos.c @@ -1,4 +1,5 @@ #include "wifi.h" +#include "common/debug.h" #include "common/io.h" #include "common/mallocHelper.h" @@ -82,6 +83,7 @@ const char* ffDetectWifi(FFlist* result) { FF_AUTO_FREE void* bufferMemory = malloc(MAX_BUF_LEN); if (!bufferMemory) { + FF_DEBUG("malloc(MAX_BUF_LEN) failed"); return "malloc() failed"; } wldp_t* buffer = (wldp_t*) bufferMemory; diff --git a/src/detection/wm/wm_linux.c b/src/detection/wm/wm_linux.c index b04bececa..b5468967e 100644 --- a/src/detection/wm/wm_linux.c +++ b/src/detection/wm/wm_linux.c @@ -8,6 +8,7 @@ #include "common/debug.h" const char* ffDetectWMPlugin([[maybe_unused]] FFstrbuf* pluginName) { + FF_DEBUG("Not supported on this platform"); return "Not supported on this platform"; } @@ -120,6 +121,7 @@ static const char* getSway(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("sway", &path); if (error) { + FF_DEBUG("Failed to find sway executable: %s", error); return "Failed to find sway executable path"; } @@ -133,6 +135,7 @@ static const char* getSway(FFstrbuf* result) { return extractSwayVersion(buffer.chars, buffer.length, result) ? "Failed to parse sway version output" : nullptr; } + FF_DEBUG("Failed to run command `sway --version`"); return "Failed to run command `sway --version`"; } @@ -140,6 +143,7 @@ static const char* getLabwc(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("labwc", &path); if (error) { + FF_DEBUG("Failed to find labwc executable: %s", error); return "Failed to find labwc executable path"; } @@ -154,6 +158,7 @@ static const char* getLabwc(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `labwc --version`"); return "Failed to run command `labwc --version`"; } @@ -165,6 +170,7 @@ static const char* getNiri(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `niri --version`"); return "Failed to run command `niri --version`"; } @@ -176,6 +182,7 @@ static const char* getUmbriel(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `umbriel --version`"); return "Failed to run command `umbriel --version`"; } @@ -183,6 +190,7 @@ static const char* getWeston(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("weston", &path); if (error) { + FF_DEBUG("Failed to find weston executable: %s", error); return "Failed to find weston executable path"; } @@ -192,12 +200,14 @@ static const char* getWeston(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `weston --version`"); return "Failed to run command `weston --version`"; } #ifdef __linux__ static const char* getWslg(FFstrbuf* result) { if (!ffAppendFileBuffer("/mnt/wslg/versions.txt", result)) { + FF_DEBUG("Failed to read /mnt/wslg/versions.txt"); return "Failed to read /mnt/wslg/versions.txt"; } @@ -211,6 +221,7 @@ static const char* getWslg(FFstrbuf* result) { ffStrbufTrimLeft(result, ' '); } else { ffStrbufClear(result); + FF_DEBUG("Failed to parse WSLg version from /mnt/wslg/versions.txt"); return "Failed to parse WSLg version from /mnt/wslg/versions.txt"; } @@ -235,6 +246,7 @@ static const char* getI3(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("i3", &path); if (error) { + FF_DEBUG("Failed to find i3 executable: %s", error); return "Failed to find i3 executable path"; } @@ -249,6 +261,7 @@ static const char* getI3(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `i3 --version`"); return "Failed to run command `i3 --version`"; } @@ -256,6 +269,7 @@ static const char* getCtwm(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("ctwm", &path); if (error) { + FF_DEBUG("Failed to find ctwm executable: %s", error); return "Failed to find ctwm executable path"; } @@ -270,6 +284,7 @@ static const char* getCtwm(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `ctwm --version`"); return "Failed to run command `ctwm --version`"; } @@ -277,6 +292,7 @@ static const char* getFvwm(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("fvwm", &path); if (error) { + FF_DEBUG("Failed to find fvwm executable: %s", error); return "Failed to find fvwm executable path"; } @@ -291,6 +307,7 @@ static const char* getFvwm(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `fvwm -version`"); return "Failed to run command `fvwm -version`"; } @@ -298,6 +315,7 @@ static const char* getOpenbox(FFstrbuf* result) { FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); const char* error = ffFindExecutableInPath("openbox", &path); if (error) { + FF_DEBUG("Failed to find openbox executable: %s", error); return "Failed to find openbox executable path"; } @@ -312,11 +330,13 @@ static const char* getOpenbox(FFstrbuf* result) { return nullptr; } + FF_DEBUG("Failed to run command `openbox --version`"); return "Failed to run command `openbox --version`"; } const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, [[maybe_unused]] FFWMOptions* options) { if (!wmName) { + FF_DEBUG("No WM detected"); return "No WM detected"; } @@ -370,5 +390,6 @@ const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, [[maybe_ return getOpenbox(result); } + FF_DEBUG("Unsupported WM: %s", wmName->chars); return "Unsupported WM"; }