Re: How to handle concurrent access to /dev/ttyprintk ?

From: Petr Mladek
Date: Tue Apr 13 2021 - 10:33:28 EST


On Tue 2021-04-13 13:10:50, Samo Pogačnik wrote:
> Dne 13.04.2021 (tor) ob 11:41 +0200 je Petr Mladek napisal(a):
> > On Mon 2021-04-12 14:41:27, Samo Pogačnik wrote:
> > > Dne 12.04.2021 (pon) ob 19:39 +0900 je Tetsuo Handa napisal(a):
> > > > What is the intended usage of /dev/ttyprintk ?
> > > >
> > >
> > > The intended use of 'ttyprintk' is to redirect console to /dev/ttyprintk
> > > via the TIOCCONS ioctl. After successfull redirection, all console
> > > messages get "merged" with kernel messages and as such automatically
> > > processed
> > > (stored/transferred) by the syslog service for example.
> >
> > The same can be achieved by /dev/kmsg that was created by systemd
> > developers.
> >
> 'kmsg' and 'ttyprintk' are different types of drivers and as such rather
> complementary than exclusive. The 'ttyprintk' being a tty driver allows
> for a system wide automatic redirection of anything written to the
> console.

I might miss something. But how can one setup ttyprintk as the system
wide console? I do not see any code that would use ttyprintk
in struct console.

Or am I too focused on the printk/kernel-side of view?

> On the other hand 'kmsg' is probably better suited for a per process
> output redirection/injection of its output into kernel messages.

> Maybe i am wrong, but 'systemd' could also find 'ttyprintk' usefull?

/dev/kmsg allows both read and write from/to the kernel log buffer.

The write callback allows to pass a certain loglevel from the
user space in the format "<level>message"

The read callback passes a lot of meta information in the format
"<level>,<sequnum>,<timestamp>,<contflag>[,additional_values,
... ];<message text>\n"

IMHO, /dev/kmsg provides a super set of functionality
over /dev/ttyprintk. But I am not familiar with the tty layer
and all its use-cases.

To make it clear. I do not resist on removing ttyprintk by any means.
It was just an idea. I am not even sure if it is possible to obsolete
tty drivers.

Best Regards,
Petr