Skip to content

Commit

Permalink
Merge pull request #428 from LinusDierheimer/dev
Browse files Browse the repository at this point in the history
Release: 1.10.3
  • Loading branch information
CarterLi authored Feb 25, 2023
2 parents 4f4860e + b19d8d6 commit 52eacd7
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 103 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 1.10.3
Bugfixes:
* Fix uninitialized variables (GPU, Windows)
* Fix compiling errors (Windows)

Improvements:
* Improve preformance (WmTheme amd Font, Windows and macOS)
* Enable nonblocking public-ip / weather detection (Android)

# 1.10.2

Bugfixes:
Expand Down
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url

project(fastfetch
VERSION 1.10.2
VERSION 1.10.3
LANGUAGES C
DESCRIPTION "Fast system information tool"
HOMEPAGE_URL "https://github.com/LinusDierheimer/fastfetch"
Expand Down Expand Up @@ -71,7 +71,7 @@ cmake_dependent_option(ENABLE_LIBCJSON "Enable libcjson" ON "LINUX OR WIN32" OFF
cmake_dependent_option(ENABLE_LIBNM "Enable libnm" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND AND NOT ANDROID" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
cmake_dependent_option(ENABLE_BUFFER "Enable stdout buffer" ON "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF)
cmake_dependent_option(USE_WIN_NTAPI "Allow using internal NTAPI" ON "WIN32" OFF)

Expand Down Expand Up @@ -117,7 +117,11 @@ if(NOT WIN32)
set(FASTFETCH_FLAGS_DEBUG "${FASTFETCH_FLAGS_DEBUG} -fsanitize=address -fsanitize=undefined")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -rdynamic")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
if(NOT WIN32)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -rdynamic")
endif()


if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
include(CheckIPOSupported)
Expand Down Expand Up @@ -519,6 +523,7 @@ elseif(WIN32)
src/detection/swap/swap_windows.cpp
src/detection/terminalfont/terminalfont_windows.c
src/detection/terminalshell/terminalshell_windows.cpp
src/detection/temps/temps_windows.cpp
src/detection/uptime/uptime_windows.c
src/detection/users/users_windows.c
src/detection/wifi/wifi_windows.c
Expand Down
34 changes: 13 additions & 21 deletions src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,42 +212,29 @@ void ffInitInstance(FFinstance* instance)
defaultConfig(instance);
}

#ifdef FF_HAVE_THREADS

FF_THREAD_ENTRY_DECL_WRAPPER(ffConnectDisplayServer, FFinstance*)

#if !(defined(__APPLE__) || defined(_WIN32))
#if defined(FF_HAVE_THREADS) && !(defined(__APPLE__) || defined(_WIN32) || defined(__ANDROID__))

#include "detection/gtk_qt/gtk_qt.h"

#define FF_DETECT_QT_GTK 1
#define FF_START_DETECTION_THREADS

FF_THREAD_ENTRY_DECL_WRAPPER(ffConnectDisplayServer, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectQt, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectGTK2, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectGTK3, FFinstance*)
FF_THREAD_ENTRY_DECL_WRAPPER(ffDetectGTK4, FFinstance*)

#endif //!(defined(__APPLE__) || defined(_WIN32))

#endif //FF_HAVE_THREADS

void startDetectionThreads(FFinstance* instance)
{
#ifdef FF_HAVE_THREADS
ffThreadDetach(ffThreadCreate(ffConnectDisplayServerThreadMain, instance));

#ifdef FF_DETECT_QT_GTK
ffThreadDetach(ffThreadCreate(ffDetectQtThreadMain, instance));
ffThreadDetach(ffThreadCreate(ffDetectGTK2ThreadMain, instance));
ffThreadDetach(ffThreadCreate(ffDetectGTK3ThreadMain, instance));
ffThreadDetach(ffThreadCreate(ffDetectGTK4ThreadMain, instance));
#endif

#else
FF_UNUSED(instance);
#endif
}

#endif //FF_HAVE_THREADS

static volatile bool ffDisableLinewrap = true;
static volatile bool ffHideCursor = true;

Expand All @@ -268,7 +255,7 @@ static void resetConsole()
BOOL WINAPI consoleHandler(DWORD signal)
{
FF_UNUSED(signal);
resetConsole();
resetConsole();
exit(0);
}
#else
Expand All @@ -282,8 +269,10 @@ static void exitSignalHandler(int signal)

void ffStart(FFinstance* instance)
{
if(instance->config.multithreading)
startDetectionThreads(instance);
#ifdef FF_START_DETECTION_THREADS
if(instance->config.multithreading)
startDetectionThreads(instance);
#endif

ffDisableLinewrap = instance->config.disableLinewrap && !instance->config.pipe;
ffHideCursor = instance->config.hideCursor && !instance->config.pipe;
Expand Down Expand Up @@ -450,6 +439,9 @@ void ffDestroyInstance(FFinstance* instance)
void ffListFeatures()
{
fputs(
#ifdef FF_HAVE_THREADS
"threads\n"
#endif
#ifdef FF_HAVE_LIBPCI
"libpci\n"
#endif
Expand Down
19 changes: 19 additions & 0 deletions src/common/io/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ static inline void ffUnsuppressIO(bool* suppressed)

void ffListFilesRecursively(const char* path);

static inline bool wrapClose(FFNativeFD* pfd)
{
assert(pfd);

#ifndef WIN32
if (*pfd < 0)
return false;
close(*pfd);
#else
// https://devblogs.microsoft.com/oldnewthing/20040302-00/?p=40443
if (*pfd == NULL || *pfd == INVALID_HANDLE_VALUE)
return false;
CloseHandle(*pfd);
#endif

return true;
}
#define FF_AUTO_CLOSE_FD __attribute__((__cleanup__(wrapClose)))

#endif // FF_INCLUDED_common_io_io
24 changes: 6 additions & 18 deletions src/common/io/io_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC;
int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;

int fd = open(fileName, openFlagsModes, openFlagsRights);
int FF_AUTO_CLOSE_FD fd = open(fileName, openFlagsModes, openFlagsRights);
if(fd == -1)
{
createSubfolders(fileName);
Expand All @@ -36,11 +36,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
return false;
}

bool ret = write(fd, data, dataSize) != -1;

close(fd);

return ret;
return write(fd, data, dataSize) > 0;
}

bool ffAppendFDBuffer(int fd, FFstrbuf* buffer)
Expand Down Expand Up @@ -77,28 +73,20 @@ bool ffAppendFDBuffer(int fd, FFstrbuf* buffer)

ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
{
int fd = open(fileName, O_RDONLY);
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY);
if(fd == -1)
return -1;

ssize_t readed = ffReadFDData(fd, dataSize, data);

close(fd);

return readed;
return ffReadFDData(fd, dataSize, data);
}

bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
{
int fd = open(fileName, O_RDONLY);
int FF_AUTO_CLOSE_FD fd = open(fileName, O_RDONLY);
if(fd == -1)
return false;

bool ret = ffAppendFDBuffer(fd, buffer);

close(fd);

return ret;
return ffAppendFDBuffer(fd, buffer);
}

bool ffPathExists(const char* path, FFPathType type)
Expand Down
28 changes: 7 additions & 21 deletions src/common/io/io_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

static void createSubfolders(const char* fileName)
{
FFstrbuf path;
FF_STRBUF_AUTO_DESTROY path;
ffStrbufInit(&path);

while(*fileName != '\0')
Expand All @@ -12,13 +12,11 @@ static void createSubfolders(const char* fileName)
CreateDirectoryA(path.chars, NULL);
++fileName;
}

ffStrbufDestroy(&path);
}

bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
{
HANDLE handle = CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE FF_AUTO_CLOSE_FD handle = CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(handle == INVALID_HANDLE_VALUE)
{
createSubfolders(fileName);
Expand All @@ -28,11 +26,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
}

DWORD written;
bool ret = !!WriteFile(handle, data, (DWORD)dataSize, &written, NULL);

CloseHandle(handle);

return ret;
return !!WriteFile(handle, data, (DWORD)dataSize, &written, NULL);
}

bool ffAppendFDBuffer(HANDLE handle, FFstrbuf* buffer)
Expand Down Expand Up @@ -69,28 +63,20 @@ bool ffAppendFDBuffer(HANDLE handle, FFstrbuf* buffer)

ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
{
HANDLE handle = CreateFileA(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE FF_AUTO_CLOSE_FD handle = CreateFileA(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(handle == INVALID_HANDLE_VALUE)
return -1;

ssize_t readed = ffReadFDData(handle, dataSize, data);

CloseHandle(handle);

return readed;
return ffReadFDData(handle, dataSize, data);
}

bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
{
HANDLE handle = CreateFileA(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE FF_AUTO_CLOSE_FD handle = CreateFileA(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(handle == INVALID_HANDLE_VALUE)
return false;

bool ret = ffAppendFDBuffer(handle, buffer);

CloseHandle(handle);

return ret;
return ffAppendFDBuffer(handle, buffer);
}

bool ffPathExists(const char* path, FFPathType type)
Expand Down
19 changes: 15 additions & 4 deletions src/common/processing_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,20 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])

//Parent
close(pipes[1]);
waitpid(childPid, NULL, 0);
bool ok = ffAppendFDBuffer(pipes[0], buffer);
close(pipes[0]);

return ok ? NULL : "ffAppendFDBuffer() failed";
int FF_AUTO_CLOSE_FD childPipeFd = pipes[0];
int status = -1;
if(waitpid(childPid, &status, 0) < 0)
return "waitpid(childPid, &status, 0) failed";

if (!WIFEXITED(status))
return "WIFEXITED(status) == false";

if(WEXITSTATUS(status) == 901)
return "WEXITSTATUS(status) == 901 ( execvp failed )";

if(!ffAppendFDBuffer(childPipeFd, buffer))
return "ffAppendFDBuffer(childPipeFd, buffer) failed";

return NULL;
}
4 changes: 4 additions & 0 deletions src/detection/cpu/cpu_windows.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cpu.h"
#include "detection/temps/temps_windows.h"
#include "util/windows/registry.h"
#include "util/mallocHelper.h"

Expand Down Expand Up @@ -46,4 +47,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)

ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);

if(instance->config.cpuTemp)
ffDetectSmbiosTemp(&cpu->temperature, NULL);
}
9 changes: 9 additions & 0 deletions src/detection/font/font_linux.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#include "common/font.h"
#include "detection/displayserver/displayserver.h"
#include "detection/gtk_qt/gtk_qt.h"
#include "font.h"

void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
{
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);

if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY) == 0)
{
ffStrbufAppendS(&result->error, "Font isn't supported in TTY");
return;
}

FFfont qt;
ffFontInitQt(&qt, ffDetectQt(instance)->font.chars);
ffStrbufAppend(&result->fonts[0], &qt.pretty);
Expand Down
2 changes: 1 addition & 1 deletion src/detection/gpu/gpu_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static const char* detectWithDxgi(FFlist* gpus)
continue;

FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
gpu->dedicated.total = gpu->dedicated.total = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;

ffStrbufInit(&gpu->vendor);
ffStrbufAppendS(&gpu->vendor, ffGetGPUVendorString(desc.VendorId));
Expand Down
25 changes: 25 additions & 0 deletions src/detection/temps/temps_windows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extern "C"
{
#include "temps_windows.h"
}
#include "util/windows/wmi.hpp"

extern "C"
const char* ffDetectSmbiosTemp(double* current, double* critical)
{
// Requires Administrator priviledges
// https://wutils.com/wmi/root/wmi/msacpi_thermalzonetemperature/#properties
FFWmiQuery query(L"SELECT CurrentTemperature, CriticalTripPoint FROM MSAcpi_ThermalZoneTemperature WHERE Active = TRUE", nullptr, FFWmiNamespace::WMI);
if(!query)
return "Query WMI service failed";

if(FFWmiRecord record = query.next())
{
if (current && record.getReal(L"CurrentTemperature", current)) // In tenth of degrees Kelvin
*current = *current / 10 - 273.15;
if (critical && record.getReal(L"CriticalTripPoint", critical)) // In tenth of degrees Kelvin
*critical = *critical / 10 - 273.15;
}

return "No WMI result returned";
}
8 changes: 8 additions & 0 deletions src/detection/temps/temps_windows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#ifndef FF_INCLUDED_detection_temps_windows
#define FF_INCLUDED_detection_temps_windows

const char* ffDetectSmbiosTemp(double* current, double* critical);

#endif
Loading

0 comments on commit 52eacd7

Please sign in to comment.