Skip to content

Commit

Permalink
fix: Don't supress stderr anymore (#1822)
Browse files Browse the repository at this point in the history
### Problem description

Typing `--help` causes ImHex to exit without outputting anything.
Diagnostic messages from glib, ASan, other libraries that might have
something important to say, etc. are also suppressed.

### Implementation description

This effectively reverts 7c1e33d, which
was partially reverted only on Windows by code that was left commented
out in f114239.

Allowing other libraries to print to stderr may make the output ‘ugly’,
but lots of things print to stderr that are important for figuring out
why something is bugged, like ASan and glib.

### Additional things


![image](https://github.com/user-attachments/assets/fa6771e2-da2e-45ea-93cd-06c3f6bfd3bf)
  • Loading branch information
csnover authored Aug 9, 2024
1 parent 63c6028 commit 0263d35
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 20 deletions.
6 changes: 0 additions & 6 deletions main/gui/source/window/linux_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <wolv/utils/core.hpp>

#include <nlohmann/json.hpp>
#include <cstdio>
#include <sys/wait.h>
#include <unistd.h>

Expand Down Expand Up @@ -137,11 +136,6 @@ namespace hex {
setenv("LD_LIBRARY_PATH", hex::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true);
}

// Various libraries sadly directly print to stderr with no way to disable it
// We redirect stderr to /dev/null to prevent this
wolv::util::unused(freopen("/dev/null", "w", stderr));
setvbuf(stderr, nullptr, _IONBF, 0);

// Redirect stdout to log file if we're not running in a terminal
if (!isatty(STDOUT_FILENO)) {
log::impl::redirectToFile();
Expand Down
6 changes: 0 additions & 6 deletions main/gui/source/window/macos_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <hex/helpers/logger.hpp>
#include <hex/helpers/default_paths.hpp>

#include <cstdio>
#include <unistd.h>

#include <imgui_impl_glfw.h>
Expand Down Expand Up @@ -41,11 +40,6 @@ namespace hex {
setenv("LD_LIBRARY_PATH", hex::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true);
}

// Various libraries sadly directly print to stderr with no way to disable it
// We redirect stderr to /dev/null to prevent this
freopen("/dev/null", "w", stderr);
setvbuf(stderr, nullptr, _IONBF, 0);

// Redirect stdout to log file if we're not running in a terminal
if (!isatty(STDOUT_FILENO)) {
log::impl::redirectToFile();
Expand Down
8 changes: 0 additions & 8 deletions main/gui/source/window/win_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include <shellapi.h>
#include <timeapi.h>

#include <cstdio>

namespace hex {

template<typename T>
Expand Down Expand Up @@ -422,12 +420,6 @@ namespace hex {
reopenConsoleHandle(STD_INPUT_HANDLE, STDIN_FILENO, stdin);
reopenConsoleHandle(STD_OUTPUT_HANDLE, STDOUT_FILENO, stdout);

// Explicitly don't forward stderr because some libraries like to write to it
// with no way to disable it (e.g., libmagic)
/*
reopenConsoleHandle(STD_ERROR_HANDLE, STDERR_FILENO, stderr);
*/

// Enable ANSI colors in the console
log::impl::enableColorPrinting();
} else {
Expand Down

0 comments on commit 0263d35

Please sign in to comment.