]> git.ipfire.org Git - thirdparty/systemd.git/commit
log: when writing a log message to a TTY always end line in CRNL 30183/head
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Nov 2023 09:50:47 +0000 (10:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 Nov 2023 10:09:24 +0000 (11:09 +0100)
commitd19ddf91fdaf2661a6fed2908a64f6ae9cd54c50
tree1103f77ec28f6d5b0629ca1cfb27434518a676ab
parent1b6983b3958b837592d8dc1916a891ba50b0bacd
log: when writing a log message to a TTY always end line in CRNL

This should make sure our log lines look nice even if the tty we are
connected to is in raw mode. Normally, it's the TTY's job to turn an NL
we output into a CRNL and interpret it accordingly. However, if the tty
is in "raw" mode it won't do that. Specifically, this is controlled by
the ONLCR flag on the TTY. A TTY might be in raw mode if our "ptyfwd"
logic is used for example, where a 2nd tty is bi-directionally connected
to the primary tty, and duplicate processing is not desired.

Hence, let's just write out the CR on our own. This will make sure that
whenever we output something subsequent output always continues on the
beginning of the next line again, regardless the mode the TTY is in. Of
course, if the TTY is *not* in raw mode, then the extra CR we now
generate is redundant, but it shouldn't hurt either, as it just moves
the cursor to the front of the line even though already is just there.

We only to that if we actually talk to a TTY though, since we don't want
the extra CRs if we are redirected to a pipe or file or so. We are not
on Windows after all.

Fixes: #30155
src/basic/log.c