Skip to content

Commit

Permalink
v1.0.11 Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aristocratos committed Sep 29, 2021
1 parent cd065cf commit a246c09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v1.0.11

* Changed: atomic_wait to use while loop instead of wait() because of rare stall when a signal handler is triggered while waiting

* Fixed: Get real / mountpoint when running inside snap

* Fixed: UTF8 set LANG and LC_ALL to empty before UTF8 search and fixed empty error msg on exit before signal handler init

* Changed: Init will continue with a warning if UTF-8 locale are detected and it fails to set the locale

## v1.0.10

* Added: Wait for terminal size properties to be available at start
Expand Down
29 changes: 15 additions & 14 deletions src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Global {
{"#801414", "██████╔╝ ██║ ╚██████╔╝██║ ╚═╝ ╚═╝"},
{"#000000", "╚═════╝ ╚═╝ ╚═════╝ ╚═╝"},
};
const string Version = "1.0.10";
const string Version = "1.0.11";

int coreCount;
string overlay;
Expand Down Expand Up @@ -712,29 +712,30 @@ int main(int argc, char **argv) {
}

//? Try to find and set a UTF-8 locale
if (std::setlocale(LC_ALL, "") != NULL and str_to_upper(s_replace((string)std::setlocale(LC_ALL, ""), "-", "")).ends_with("UTF8")) {
if (std::setlocale(LC_ALL, "") != NULL and not s_contains((string)std::setlocale(LC_ALL, ""), ";")
and str_to_upper(s_replace((string)std::setlocale(LC_ALL, ""), "-", "")).ends_with("UTF8")) {
Logger::debug("Using locale " + (string)std::setlocale(LC_ALL, ""));
}
else {
string found;
if (std::getenv("LANG") != NULL and str_to_upper(s_replace((string)std::getenv("LANG"), "-", "")).ends_with("UTF8")) {
found = std::getenv("LANG");
if (std::setlocale(LC_ALL, std::getenv("LANG")) == NULL)
Logger::warning("Failed to set locale " + (string)std::getenv("LANG") + " continuing anyway.");
}
if (found.empty() and std::getenv("LC_ALL") != NULL and str_to_upper(s_replace((string)std::getenv("LC_ALL"), "-", "")).ends_with("UTF8")) {
found = std::getenv("LC_ALL");
if (std::setlocale(LC_ALL, std::getenv("LC_ALL")) == NULL)
Logger::warning("Failed to set locale " + (string)std::getenv("LC_ALL") + " continuing anyway.");
bool set_failure = false;
for (const auto loc_env : array{"LANG", "LC_ALL"}) {
if (std::getenv(loc_env) != NULL and str_to_upper(s_replace((string)std::getenv(loc_env), "-", "")).ends_with("UTF8")) {
found = std::getenv(loc_env);
if (std::setlocale(LC_ALL, found.c_str()) == NULL) {
set_failure = true;
Logger::warning("Failed to set locale " + found + " continuing anyway.");
}
}
}
if (found.empty()) {
if (setenv("LC_ALL", "", 1) == 0 and setenv("LANG", "", 1) == 0) {
try {
if (const auto loc = std::locale("").name(); not loc.empty() and loc != "*") {
for (auto& l : ssplit(loc, ';')) {
if (str_to_upper(s_replace(l, "-", "")).ends_with("UTF8")) {
if (std::setlocale(LC_ALL, l.substr(l.find('=') + 1).c_str()) != NULL) {
found = l;
found = l.substr(l.find('=') + 1);
if (std::setlocale(LC_ALL, found.c_str()) != NULL) {
break;
}
}
Expand All @@ -751,7 +752,7 @@ int main(int argc, char **argv) {
Global::exit_error_msg = "No UTF-8 locale detected!\nUse --utf-force argument to force start if you're sure your terminal can handle it.";
clean_quit(1);
}
else
else if (not set_failure)
Logger::debug("Setting LC_ALL=" + found);
}

Expand Down
1 change: 0 additions & 1 deletion src/btop_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ namespace Tools {
atomic_lock::~atomic_lock() {
active_locks--;
this->atom.store(false);
atomic_notify(this->atom);
}

string readfile(const std::filesystem::path& path, const string& fallback) {
Expand Down
8 changes: 1 addition & 7 deletions src/btop_tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,9 @@ namespace Tools {
string hostname();
string username();

// #if __GNUC__ < 11
inline void atomic_wait(const atomic<bool>& atom, const bool old=true) noexcept { while (atom.load() == old) sleep_ms(1); }
inline void atomic_notify(const atomic<bool>& atom) noexcept { (void)atom; }
// #else
// inline void atomic_wait(const atomic<bool>& atom, const bool old=true) noexcept { if (atom == old) atom.wait(old); }
// inline void atomic_notify(const atomic<bool>& atom) noexcept { atom.notify_all(); }
// #endif

//* Waits for atomic<bool> to be false and sets it to true on construct, sets to false and notifies on destruct
//* Waits for atomic<bool> to be false and sets it to true on construct, sets to false on destruct
class atomic_lock {
atomic<bool>& atom;
bool not_true = false;
Expand Down

0 comments on commit a246c09

Please sign in to comment.