mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-29 22:51:35 +02:00
Fixed: Ignore disks that fails in statvfs64() to avoid slowdowns and possible crashes.
This commit is contained in:
parent
8a07bc43b4
commit
dda9f2589f
@ -925,6 +925,7 @@ namespace Mem {
|
|||||||
|
|
||||||
//? Get disks stats
|
//? Get disks stats
|
||||||
if (show_disks) {
|
if (show_disks) {
|
||||||
|
static vector<string> ignore_list;
|
||||||
double uptime = system_uptime();
|
double uptime = system_uptime();
|
||||||
auto free_priv = Config::getB("disk_free_priv");
|
auto free_priv = Config::getB("disk_free_priv");
|
||||||
try {
|
try {
|
||||||
@ -997,7 +998,7 @@ namespace Mem {
|
|||||||
diskread >> dev >> mountpoint >> fstype;
|
diskread >> dev >> mountpoint >> fstype;
|
||||||
diskread.ignore(SSmax, '\n');
|
diskread.ignore(SSmax, '\n');
|
||||||
|
|
||||||
if (v_contains(found, mountpoint)) continue;
|
if (v_contains(ignore_list, mountpoint) or v_contains(found, mountpoint)) continue;
|
||||||
|
|
||||||
//? Match filter if not empty
|
//? Match filter if not empty
|
||||||
if (not filter.empty()) {
|
if (not filter.empty()) {
|
||||||
@ -1056,6 +1057,7 @@ namespace Mem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//? Remove disks no longer mounted or filtered out
|
//? Remove disks no longer mounted or filtered out
|
||||||
if (swap_disk and has_swap) found.push_back("swap");
|
if (swap_disk and has_swap) found.push_back("swap");
|
||||||
for (auto it = disks.begin(); it != disks.end();) {
|
for (auto it = disks.begin(); it != disks.end();) {
|
||||||
@ -1072,11 +1074,14 @@ namespace Mem {
|
|||||||
diskread.close();
|
diskread.close();
|
||||||
|
|
||||||
//? Get disk/partition stats
|
//? Get disk/partition stats
|
||||||
|
bool new_ignored = false;
|
||||||
for (auto& [mountpoint, disk] : disks) {
|
for (auto& [mountpoint, disk] : disks) {
|
||||||
if (std::error_code ec; not fs::exists(mountpoint, ec)) continue;
|
if (std::error_code ec; not fs::exists(mountpoint, ec) or v_contains(ignore_list, mountpoint)) continue;
|
||||||
struct statvfs64 vfs;
|
struct statvfs64 vfs;
|
||||||
if (statvfs64(mountpoint.c_str(), &vfs) < 0) {
|
if (statvfs64(mountpoint.c_str(), &vfs) < 0) {
|
||||||
Logger::warning("Failed to get disk/partition stats with statvfs() for: " + mountpoint);
|
Logger::warning("Failed to get disk/partition stats for mount \""+ mountpoint + "\" with statvfs64 error code: " + to_string(errno) + ". Ignoring...");
|
||||||
|
ignore_list.push_back(mountpoint);
|
||||||
|
new_ignored = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
disk.total = vfs.f_blocks * vfs.f_frsize;
|
disk.total = vfs.f_blocks * vfs.f_frsize;
|
||||||
@ -1086,6 +1091,16 @@ namespace Mem {
|
|||||||
disk.free_percent = 100 - disk.used_percent;
|
disk.free_percent = 100 - disk.used_percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//? Remove any problematic disks added to the ignore_list
|
||||||
|
if (new_ignored) {
|
||||||
|
for (auto it = disks.begin(); it != disks.end();) {
|
||||||
|
if (v_contains(ignore_list, it->first))
|
||||||
|
it = disks.erase(it);
|
||||||
|
else
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//? Setup disks order in UI and add swap if enabled
|
//? Setup disks order in UI and add swap if enabled
|
||||||
mem.disks_order.clear();
|
mem.disks_order.clear();
|
||||||
#ifdef SNAPPED
|
#ifdef SNAPPED
|
||||||
|
Loading…
Reference in New Issue
Block a user