Bug 1655316 - journalctl: with mouse scroll wheel, default pager scrolls terminal window, not log
Summary: journalctl: with mouse scroll wheel, default pager scrolls terminal window, n...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 29
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-12-02 17:08 UTC by Steve
Modified: 2019-07-31 14:01 UTC (History)
6 users (show)

Fixed In Version: systemd-243-1.fc31
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-07-31 14:01:41 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Steve 2018-12-02 17:08:02 UTC
Description of problem:
By default, "journalctl" invokes a pager when viewing a log, and the default pager is "less".

The problem is that the mouse scroll wheel scrolls the terminal window instead of the log file itself.

Version-Release number of selected component (if applicable):
systemd-239-6.git9f3aed1.fc29.x86_64
less-530-2.fc29.x86_64

How reproducible:
Always.
Also occurs with F28.

Steps to Reproduce:
Case 1:

1. Open a terminal window.
2. $ echo foo # provide a visible reference point in the terminal window
3. $ journalctl -b
4. With the pointer in the terminal window, move the mouse scroll wheel in both directions.
5. Press "q" to quit.

Case 2:

6. $ journalctl -b --no-pager | less
7. With the pointer in the terminal window, move the mouse scroll wheel in both directions.
8. Press "q" to quit.

Case 3:

9. $ journalctl -b --no-pager | less -X
10. With the pointer in the terminal window, move the mouse scroll wheel in both directions.
11. Press "q" to quit.

Actual results:
In case 1 and case 3, the terminal window is scrolled.
In case 2, the log is scrolled.

Expected results:
Case 1 and case 2 have identical behavior.

Additional info:

The "-X" option is being passed to "less", according to the "journalctl" man page:

       $SYSTEMD_LESS
           Override the options passed to less (by default "FRSXMK").

Verify that no relevant environment variables are set with:

$ env | egrep '(LESS|PAGER)'
LESSOPEN=||/usr/bin/lesspipe.sh %s

Comment 1 Steve 2018-12-02 17:27:37 UTC
(In reply to Steve from comment #0)
...
> The "-X" option is being passed to "less", according to the "journalctl" man
> page:
> 
>        $SYSTEMD_LESS
>            Override the options passed to less (by default "FRSXMK").

Some of those "less" options might be justifiably used with "journalctl", but it would be better to set them overtly in the environment or a configuration file, instead of hard-coding them:

$ less -N systemd-238/src/shared/pager.c
...
     62 int pager_open(bool no_pager, bool jump_to_end) {
...
    106                 /* Initialize a good set of less options */
    107                 less_opts = getenv("SYSTEMD_LESS");
    108                 if (!less_opts)
    109                         less_opts = "FRSXMK";
    110                 if (jump_to_end)
    111                         less_opts = strjoina(less_opts, " +G");
...

Comment 2 Steve 2018-12-02 18:33:58 UTC
(In reply to Steve from comment #1)
...
> ... it would be better to set them overtly in the environment or a
> configuration file, instead of hard-coding them:
...

The default "less" options do not appear to be documented in any "systemd" config file:

$ grep -i less /etc/systemd/*.conf | grep -v GNU

Comment 3 Jan Synacek 2018-12-03 08:21:48 UTC
(In reply to Steve from comment #1)
> (In reply to Steve from comment #0)
> ...
> > The "-X" option is being passed to "less", according to the "journalctl" man
> > page:
> > 
> >        $SYSTEMD_LESS
> >            Override the options passed to less (by default "FRSXMK").
> 
> Some of those "less" options might be justifiably used with "journalctl",
> but it would be better to set them overtly in the environment or a
> configuration file, instead of hard-coding them:

So, you first show the environment variable where the options are set, and then say the options are hard-coded... SYSTEMD_LESS is *the* environment option to change the options. It's documented in systemctl(1) and journalctl(1).

Comment 4 Steve 2018-12-03 09:31:09 UTC
(In reply to Jan Synacek from comment #3)
...
> So, you first show the environment variable where the options are set, and
> then say the options are hard-coded... SYSTEMD_LESS is *the* environment
> option to change the options. It's documented in systemctl(1) and
> journalctl(1).

Good catch. I should have said that "it would be better to set them [the default "less" options] overtly in ... a configuration file" instead of in the code.

Subsequently, I remembered that the "systemd" convention is to document the defaults in a config file:

$ less /etc/systemd/journald.conf
...
# Entries in this file show the compile time defaults.
...

Anyway, is there any reason to set the "-X" "less" option?

For comparison, the "man" command doesn't set any "less" options:

$ strace -f -o x1.log man date
$ less x1.log
...
2323  execve("/usr/bin/less", ["less"], 0x55a5de9cf0b0 /* 57 vars */ <unfinished ...>
...

Comment 5 Steve 2018-12-03 09:56:39 UTC
(In reply to Steve from comment #4)
...
> For comparison, the "man" command doesn't set any "less" options:
...

Correcting myself. The options are passed in the environment. However, the "-X" option is not one of the options:

$ strace -f -v -o x2.log man date
$ less x2.log
...
3270  execve("/usr/bin/less", ["less"], [ ... "LESS=-ix8RmPm Manual page date(1"..., "MAN_PN=date(1)"] <unfinished ...>
...

The "-P" option might actually be a good addition to the "less" options passed by "journalctl":

less(1):

"The  -P  option  allows  you  to tailor the prompt to your preference. ..."

Comment 6 Jan Synacek 2018-12-03 10:02:10 UTC
(In reply to Steve from comment #4)
> Anyway, is there any reason to set the "-X" "less" option?

I don't know. I traced the original commit that added support for the external pager to https://github.com/systemd/systemd/commit/0736af98c6fae9c7d31e3dd17589421b7e883ef5, but no documentation about the less options can be found there. I guess the best course of action would be to ask on the systemd-devel mailing list.

Comment 7 Steve 2018-12-03 10:30:59 UTC
(In reply to Jan Synacek from comment #6)
> (In reply to Steve from comment #4)
> > Anyway, is there any reason to set the "-X" "less" option?
> 
> I don't know. I traced the original commit that added support for the
> external pager to
> https://github.com/systemd/systemd/commit/
> 0736af98c6fae9c7d31e3dd17589421b7e883ef5, but no documentation about the
> less options can be found there. I guess the best course of action would be
> to ask on the systemd-devel mailing list.

Thanks for posting that commit. The change to the "TODO" file provides a clue:

"- * systemctl auto-pager a la git"

git-config(1):

"When the LESS environment variable is unset, Git sets it to FRX ..."

So, the "-X" "less" option appears to have been *copied* from the git code ...

Comment 8 Steve 2018-12-03 11:40:14 UTC
For the record, this is a workaround for this bug:

$ SYSTEMD_LESS='FRSMK' journalctl -b # remove "-X" option, retain other options

Comment 9 Steve 2018-12-03 23:31:52 UTC
(In reply to Steve from comment #8)
> For the record, this is a workaround for this bug:
> 
> $ SYSTEMD_LESS='FRSMK' journalctl -b # remove "-X" option, retain other
> options

Here is a difference in behavior:

Scrolls the terminal window before displaying the log text:

$ journalctl -b -n 6

Blanks the terminal window before displaying the log text:

$ SYSTEMD_LESS='FRSMK' journalctl -b -n 6

The latter behavior is the same as that of the "man" command with a short man page:

$ man 7 intro # run in a full-screen terminal window

Comment 10 Zbigniew Jędrzejewski-Szmek 2019-07-21 10:33:51 UTC
The reason why 'X' is passed is that we want stuff like 'journalctl -n5' to print stuff to the console
just like 'tail -n5' would. If 'X' is removed from the options, less output is only visible when
less is running, and gone afterwards. We could try to be smart and add 'X' only in certain circumstances,
e.g. when '-n' is given and such, but this would be quite confusing, because the pager behaviour
would be substantially different based on some (seemingly unrelated) options. So sorry,
this isn't really a bug, but a limitation of less, or maybe even the terminal. Thinking about this
some more, it seems likely that it simply isn't possible to do "output to the console but scroll with
the mouse". Users may override this if they wish (as described in the comments above), but the current
default should stay.

https://github.com/systemd/systemd/pull/13126

Comment 11 Zbigniew Jędrzejewski-Szmek 2019-07-31 14:01:41 UTC
Docs were improved in the PR above, now in rawhide.


Note You need to log in before you can comment on or make changes to this bug.