journalctl
is the systemd tool for viewing and tailing system logs. It's cool but has one infuriating bug: when you hit ^C,
it kills both journalctl and your pager.
less
has lots of useful behavior based on ^C
(such as to stop tailing a log), so this makes journalctl
practically
useless in my view :)
It sets the K
option on less
which has this effect, but then it also sends SIGTERM itself when journalctl
receives
SIGINT, so unsetting that K
is not effective, either.
You can use dumb-init
to rewrite SIGINT
to another signal, like SIGURG
(which by default does nothing) on its way
to journalctl, and then to rewrite SIGURG
back to SIGINT
before going to the pager.
root@whirlwind:~# ls -l /usr/local/bin/{dumb-init,dumb-pager,journalctl}
-rwxr-xr-x 1 root root 46400 Oct 10 14:19 /usr/local/bin/dumb-init
-rwxr-xr-x 1 root root 98 Nov 24 18:58 /usr/local/bin/dumb-pager
-rwxr-xr-x 1 root root 101 Nov 24 18:58 /usr/local/bin/journalctl
root@whirlwind:~# cat /usr/local/bin/journalctl
#!/bin/bash -eu
export PAGER=/usr/local/bin/dumb-pager
exec ./dumb-init --rewrite 2:23 -- /bin/journalctl $@
root@whirlwind:~# cat /usr/local/bin/dumb-pager
#!/bin/bash -eu
export LESS=$(sed 's/K//' <<< "$LESS")
exec ./dumb-init --rewrite 23:2 -- less $@
Now you can use journalctl
as usual, and it doesn't get in less
's way.
File this one under "unintended (ab)uses of dumb-init"...
Not sure if it's a bug or just an unexpected design decision for us. At least you can fix it even more easily.
journalctl
exposes the environment variableSYSTEMD_LESS
which lets you overwrite how it callsless
under the hood. SettingSYSTEMD_LESS=FRSXM
makesless
behave as "normal".If you do not want to set it on each call you can write
export SYSTEMD_LESS=FRSXM
into your.bashrc
, or.zshrc
file. Adapt to the shell you use!