greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.88k stars 475 forks source link

Memory block crash if swap disabled #285

Closed GladOSkar closed 4 years ago

GladOSkar commented 6 years ago

The memory block crashes when you click on it if swap is disabled.

I think the "click to switch between memory/swap" should be disabled if swap is disabled.

If i have time i may implement this, but i currently don't, so if somebody else is interested...

jheyens commented 6 years ago

What do you mean by "swap is disabled"?

I tried to reproduce, but the following changes did not result in a crashing memory block:

GladOSkar commented 6 years ago

@jheyens i just don't have a swap entry in my /etc/fstab. So it's a swapless system.

But i forgot about clickable = False, so that would be a temporary solution

ammgws commented 4 years ago

@GladOSkar This is quite old but how did the block crash? Do you mean it errored out like this: https://github.com/greshake/i3status-rust/blob/d1b0ff32995006461b1326c2ac5ed791847b3a47/src/blocks/memory.rs#L566 or did it cause a panic?

GladOSkar commented 4 years ago

Peek 2020-04-26 11-28

This is what happens when i click the memory block. I have not investigated further since it doesn't really bother me

ammgws commented 4 years ago

Oh wow that's pretty bad though. Does /proc/meminfo contain SwapTotal, SwapFree at all?

GladOSkar commented 4 years ago

Weirdly, it does and seems to be enabled:

$ cat /proc/meminfo | grep Swap 
SwapCached:            0 kB
SwapTotal:       8191996 kB
SwapFree:        8191996 kB

I had assumed the swap on my system was kinda broken/weird for a while already.

When i manually turn swap off:

$ sudo swapoff /dev/sda5 
$ cat /proc/meminfo | grep Swap
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB

In both cases, i3status-rust crashes.

ammgws commented 4 years ago

For the hell of it I changed the mem block to read from a file that I control, and set the Swap* values to your ones above, yet couldn't get it to crash :(

Are you able to get a backtrace out of it?

GladOSkar commented 4 years ago

Here's a strace of the crash in case that helps:

[pid 13542] <... read resumed> "[\n", 8192) = 2
[pid 13542] read(0, "{\"name\":\"memory\",\"button\":1,\"modifiers\":[],\"x\":1342,\"y\":2152,\"relative_x\":41,\"relative_y\":14,\"width"..., 8192) = 117
[pid 13542] write(2, "1", 1)            = 1
[pid 13542] write(2, "\n", 1)           = 1
[pid 13542] futex(0x5565204409b8, FUTEX_WAKE_PRIVATE, 1) = 1
[pid 13535] <... futex resumed> )       = 0
[pid 13542] read(0,  <unfinished ...>
[pid 13535] futex(0x556520440940, FUTEX_WAKE_PRIVATE, 1) = 0
[pid 13535] openat(AT_FDCWD, "/proc/meminfo", O_RDONLY|O_CLOEXEC) = 20
[pid 13535] read(20, "MemTotal:        8122068 kB\nMemFree:         2541044 kB\nMemAvailable:    4965504 kB\nBuffers:       "..., 8192) = 1391
[pid 13535] close(20)                   = 0
[pid 13535] write(2, "thread '", 8)     = 8
[pid 13535] write(2, "main", 4)         = 4
[pid 13535] write(2, "' panicked at '", 15) = 15
[pid 13535] write(2, "Unknown placeholder in format string: {Sup}", 43) = 43
[pid 13535] write(2, "', ", 3)          = 3
[pid 13535] write(2, "src/util.rs", 11) = 11
[pid 13535] write(2, ":", 1)            = 1
[pid 13535] write(2, "276", 3)          = 3
[pid 13535] write(2, ":", 1)            = 1
[pid 13535] write(2, "44", 2)           = 2
[pid 13535] write(2, "\n", 1)           = 1
[pid 13535] write(2, "note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.\n", 79) = 79
[pid 13535] futex(0x7f7c25882040, FUTEX_WAKE_PRIVATE, 2147483647) = 0
[pid 13535] close(4)                    = 0
[pid 13535] futex(0x55652045ffec, FUTEX_WAKE_PRIVATE, 1) = 1
[pid 13537] <... futex resumed> )       = 0
[pid 13537] futex(0x556520462210, FUTEX_WAKE_PRIVATE, 1) = 0
[pid 13535] close(18)                   = 0
[pid 13535] sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=8192}, NULL) = 0
[pid 13535] munmap(0x7f7c25978000, 8192) = 0
[pid 13535] exit_group(101 <unfinished ...>
[pid 13540] <... read resumed> <unfinished ...>) = ?
[pid 13542] <... read resumed> <unfinished ...>) = ?
[pid 13541] <... poll resumed> <unfinished ...>) = ?
[pid 13539] <... ppoll resumed> <unfinished ...>) = ?
[pid 13541] +++ exited with 101 +++
[pid 13538] <... futex resumed>)        = ?
[pid 13537] +++ exited with 101 +++
[pid 13538] +++ exited with 101 +++
[pid 13536] <... restart_syscall resumed>) = ?
[pid 13535] <... exit_group resumed>)   = ?
[pid 13539] +++ exited with 101 +++
[pid 13536] +++ exited with 101 +++
[pid 13540] +++ exited with 101 +++
[pid 13542] +++ exited with 101 +++
+++ exited with 101 +++
GladOSkar commented 4 years ago

Got a proper backtrace, here:

1
thread 'main' panicked at 'Unknown placeholder in format string: {Sup}', src/util.rs:276:44
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   6: std::panicking::begin_panic_fmt
             at src/libstd/panicking.rs:336
   7: i3status_rs::util::FormatTemplate::render::{{closure}}
   8: i3status_rs::util::FormatTemplate::render
   9: i3status_rs::blocks::memory::Memory::format_insert_values
  10: <i3status_rs::blocks::memory::Memory as i3status_rs::blocks::Block>::update
  11: <i3status_rs::blocks::memory::Memory as i3status_rs::blocks::Block>::click
  12: i3status_rs::main
  13: std::rt::lang_start::{{closure}}
  14: std::panicking::try::do_call
             at src/libstd/rt.rs:49
             at src/libstd/panicking.rs:293
  15: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  16: std::rt::lang_start_internal
             at src/libstd/panicking.rs:272
             at src/libstd/panic.rs:388
             at src/libstd/rt.rs:48
  17: main
  18: __libc_start_main
  19: _start
             at ../sysdeps/x86_64/start.S:120
ammgws commented 4 years ago

OK I was able to reproduce,

In your config, I take it you have:

format_swap = "{Sup}%"

rather than

format_swap = "{SUp}%"

?

ammgws commented 4 years ago

Ideally it should error out like this so you know why: image

Need to see why that's not the case for the memory block

ammgws commented 4 years ago

OK this is because the memory block uses render which panics: https://github.com/greshake/i3status-rust/blob/d1b0ff32995006461b1326c2ac5ed791847b3a47/src/util.rs#L305 where as all the other blocks use render_static_str which raises an error

ammgws commented 4 years ago

@GladOSkar Could you please try with #616?

GladOSkar commented 4 years ago

Works: Peek 2020-04-27 17-06

Thanks for figuring that out!

ammgws commented 4 years ago

Thanks!