mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Suppress the output of drivers more efficently
This commit is contained in:
+18
-21
@@ -3,7 +3,6 @@
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define FF_IO_CACHE_VALUE_EXTENSION "ffcv"
|
||||
#define FF_IO_CACHE_SPLIT_EXTENSION "ffcs"
|
||||
@@ -463,33 +462,31 @@ bool ffGetFileContent(const char* fileName, FFstrbuf* buffer)
|
||||
return ffAppendFileContent(fileName, buffer);
|
||||
}
|
||||
|
||||
static volatile bool originalPipesSet = false;
|
||||
static volatile int originalStdout = -1;
|
||||
static volatile int originalStderr = -1;
|
||||
|
||||
void ffDisableOutput()
|
||||
// Not thread safe!
|
||||
void ffSuppressIO(bool suppress)
|
||||
{
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
static bool init = false;
|
||||
static int origOut = -1;
|
||||
static int origErr = -1;
|
||||
static int nullFile = -1;
|
||||
|
||||
if(!originalPipesSet)
|
||||
if(!init)
|
||||
{
|
||||
originalStdout = dup(STDOUT_FILENO);
|
||||
originalStderr = dup(STDERR_FILENO);
|
||||
originalPipesSet = true;
|
||||
if(!suppress)
|
||||
return;
|
||||
|
||||
origOut = dup(STDOUT_FILENO);
|
||||
origErr = dup(STDERR_FILENO);
|
||||
nullFile = open("/dev/null", O_WRONLY);
|
||||
init = true;
|
||||
}
|
||||
|
||||
int nullFile = open("/dev/null", O_WRONLY);
|
||||
dup2(nullFile, STDOUT_FILENO);
|
||||
dup2(nullFile, STDERR_FILENO);
|
||||
close(nullFile);
|
||||
}
|
||||
if(nullFile == -1)
|
||||
return;
|
||||
|
||||
void ffEnableOutput()
|
||||
{
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
dup2(originalStdout, STDOUT_FILENO);
|
||||
dup2(originalStderr, STDERR_FILENO);
|
||||
dup2(suppress ? nullFile : origOut, STDOUT_FILENO);
|
||||
dup2(suppress ? nullFile : origErr, STDERR_FILENO);
|
||||
}
|
||||
|
||||
+2
-2
@@ -328,8 +328,8 @@ bool ffGetFileContent(const char* fileName, FFstrbuf* buffer);
|
||||
bool ffWriteFDContent(int fd, const FFstrbuf* content);
|
||||
void ffWriteFileContent(const char* fileName, const FFstrbuf* buffer);
|
||||
|
||||
void ffDisableOutput();
|
||||
void ffEnableOutput();
|
||||
// Not thread safe!
|
||||
void ffSuppressIO(bool suppress);
|
||||
|
||||
// They return true if the file was found, independently if start was found
|
||||
// Buffers which already contain content are not overwritten
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
|
||||
|
||||
//Some drivers (nvdc) print messages to stdout
|
||||
//and thats the best way i found to disable that
|
||||
ffDisableOutput();
|
||||
ffSuppressIO(true);
|
||||
|
||||
const VkApplicationInfo applicationInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
@@ -51,7 +51,7 @@ static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
|
||||
if(ffvkCreateInstance(&instanceCreateInfo, NULL, &vkInstance) != VK_SUCCESS)
|
||||
{
|
||||
dlclose(vulkan);
|
||||
ffEnableOutput();
|
||||
ffSuppressIO(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
|
||||
{
|
||||
ffvkDestroyInstance(vkInstance, NULL);
|
||||
dlclose(vulkan);
|
||||
ffEnableOutput();
|
||||
ffSuppressIO(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
|
||||
free(physicalDevices);
|
||||
ffvkDestroyInstance(vkInstance, NULL);
|
||||
dlclose(vulkan);
|
||||
ffEnableOutput();
|
||||
ffSuppressIO(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
|
||||
free(physicalDevices);
|
||||
ffvkDestroyInstance(vkInstance, NULL);
|
||||
dlclose(vulkan);
|
||||
ffEnableOutput();
|
||||
ffSuppressIO(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user