When /dev/console is a disconnected /dev/ttyS0, TCGETS on /dev/console results in EIO (Even if TIOCCONS is called on a PTY)
A message that is not in the archive (sent off-list or not yet received): 8411114.T7Z3S40VBb.ref@nerdopolis2
A message that is not in the archive (sent off-list or not yet received): 8411114.T7Z3S40VBb@nerdopolis2
Greg KH
maintainerQuoted 58 lines · nerdopolis
Hi
Background:-------------------------------------------------------------------- This issue becomes evident on VT-less kernels. As when there is no
/dev/tty0device, the console defaults to being/dev/ttyS0instead. Although this can also be replicated if booting a standard kernel with 'console=ttyS0' and ensure nothing is plugged into/dev/ttyS0.This issue prevents systemd from logging to the console.
systemd when logging to/dev/console, long story short it callsisatty()on/dev/console, and when/dev/consoleis actually/dev/ttyS0, and nothing is connected to/dev/ttyS0,isatty()fails on/dev/consoledue to an input/output error, causing systemd to not log the console output, because it rejects/dev/consoleas not being a terminal.This is noticed on a VT-less system with Plymouth. Plymouth calls the TIOCCONS ioctl on a pty device it requests, to redirect console output, and in newer versions, it displays the console logs on its own without the assistance of a VT.
This part of it works, Plymouth is able to 'see' what gets written to
/dev/console, log output from processes that write to/dev/consoledirectly (for example 'echo hi >/dev/console") do appear in plymouth's/var/log/boot.log, it is just that systemd is not writing to/dev/consolebecauseisatty()fails to report/dev/consoleas a tty device.The alternate fix in for systemds https://github.com/systemd/systemd/pull/33690[1]
is believed to be that when TIOCCONS is called on a PTY, or another terminal device, that trying to call TCGETS on/dev/consoleshould no longer result in an error.Replicating the issue:---------------------------------------------------------
This program replicates it:
-------------------------------------------------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>int main(void)
{ int fd; if (getuid() != 0) { printf("Must be root\n"); return 1; } fd = open ("/dev/console", O_RDONLY); if (!isatty(fd)) { printf("err on /dev/console: %s\n", strerror(errno)); } return 0; }
Quoted 7 lines
-------------------------------------------------------------------------------
When the kernel console is
/dev/ttyS0and/dev/ttySOhas no device connected, it prints "err on/dev/console: Input/output error"When I strace it, the relevant line is:
ioctl(3</dev/console<char 5:1>>, TCGETS, 0x7f...)= -1 EIO (Input/output error)
Do you have a proposed kernel change for this that solves this for your tests here?
thanks,
greg k-h
Quoted 67 lines · EDT Greg KH
Quoted 58 lines · nerdopolis
Hi
Background:-------------------------------------------------------------------- This issue becomes evident on VT-less kernels. As when there is no
/dev/tty0device, the console defaults to being/dev/ttyS0instead. Although this can also be replicated if booting a standard kernel with 'console=ttyS0' and ensure nothing is plugged into/dev/ttyS0.This issue prevents systemd from logging to the console.
systemd when logging to/dev/console, long story short it callsisatty()on/dev/console, and when/dev/consoleis actually/dev/ttyS0, and nothing is connected to/dev/ttyS0,isatty()fails on/dev/consoledue to an input/output error, causing systemd to not log the console output, because it rejects/dev/consoleas not being a terminal.This is noticed on a VT-less system with Plymouth. Plymouth calls the TIOCCONS ioctl on a pty device it requests, to redirect console output, and in newer versions, it displays the console logs on its own without the assistance of a VT.
This part of it works, Plymouth is able to 'see' what gets written to
/dev/console, log output from processes that write to/dev/consoledirectly (for example 'echo hi >/dev/console") do appear in plymouth's/var/log/boot.log, it is just that systemd is not writing to/dev/consolebecauseisatty()fails to report/dev/consoleas a tty device.The alternate fix in for systemds https://github.com/systemd/systemd/pull/33690[1]
is believed to be that when TIOCCONS is called on a PTY, or another terminal device, that trying to call TCGETS on/dev/consoleshould no longer result in an error.Replicating the issue:---------------------------------------------------------
This program replicates it:
-------------------------------------------------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>int main(void)
{ int fd; if (getuid() != 0) { printf("Must be root\n"); return 1; } fd = open ("/dev/console", O_RDONLY); if (!isatty(fd)) { printf("err on /dev/console: %s\n", strerror(errno)); } return 0; }Quoted 7 lines
-------------------------------------------------------------------------------
When the kernel console is
/dev/ttyS0and/dev/ttySOhas no device connected, it prints "err on/dev/console: Input/output error"When I strace it, the relevant line is:
ioctl(3</dev/console<char 5:1>>, TCGETS, 0x7f...)= -1 EIO (Input/output error)
Quoted 7 lines
Do you have a proposed kernel change for this that solves this for your tests here?
thanks,
greg k-h
Hi
Sorry if this is a duplicate, I accidentally had rich text sending turned on, and did not realize until too late. Anyway, to answer the question, unfortunately I have been unable to come up with a fix on my own
Thanks
Quoted 73 lines · EDT nerdopolis
Quoted 72 lines · EDT Greg KH
Quoted 58 lines · nerdopolis
Hi
Background:-------------------------------------------------------------------- This issue becomes evident on VT-less kernels. As when there is no
/dev/tty0device, the console defaults to being/dev/ttyS0instead. Although this can also be replicated if booting a standard kernel with 'console=ttyS0' and ensure nothing is plugged into/dev/ttyS0.This issue prevents systemd from logging to the console.
systemd when logging to/dev/console, long story short it callsisatty()on/dev/console, and when/dev/consoleis actually/dev/ttyS0, and nothing is connected to/dev/ttyS0,isatty()fails on/dev/consoledue to an input/output error, causing systemd to not log the console output, because it rejects/dev/consoleas not being a terminal.This is noticed on a VT-less system with Plymouth. Plymouth calls the TIOCCONS ioctl on a pty device it requests, to redirect console output, and in newer versions, it displays the console logs on its own without the assistance of a VT.
This part of it works, Plymouth is able to 'see' what gets written to
/dev/console, log output from processes that write to/dev/consoledirectly (for example 'echo hi >/dev/console") do appear in plymouth's/var/log/boot.log, it is just that systemd is not writing to/dev/consolebecauseisatty()fails to report/dev/consoleas a tty device.The alternate fix in for systemds https://github.com/systemd/systemd/pull/33690[1]
is believed to be that when TIOCCONS is called on a PTY, or another terminal device, that trying to call TCGETS on/dev/consoleshould no longer result in an error.Replicating the issue:---------------------------------------------------------
This program replicates it:
-------------------------------------------------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>int main(void)
{ int fd; if (getuid() != 0) { printf("Must be root\n"); return 1; } fd = open ("/dev/console", O_RDONLY); if (!isatty(fd)) { printf("err on /dev/console: %s\n", strerror(errno)); } return 0; }Quoted 7 lines
-------------------------------------------------------------------------------
When the kernel console is
/dev/ttyS0and/dev/ttySOhas no device connected, it prints "err on/dev/console: Input/output error"When I strace it, the relevant line is:
ioctl(3</dev/console<char 5:1>>, TCGETS, 0x7f...)= -1 EIO (Input/output error)Do you have a proposed kernel change for this that solves this for your tests here?
thanks,
Quoted 8 lines
Quoted 2 lines
greg k-h
Hi
Sorry if this is a duplicate, I accidentally had rich text sending turned on, and did not realize until too late. Anyway, to answer the question, unfortunately I have been unable to come up with a fix on my own
Would the fix be to make /sys/class/tty/console/active report the terminal that TIOCCONS was called against? I am probably wrong there.
Quoted 2 lines
Thanks
Quoted 76 lines · EDT nerdopolis
Quoted 75 lines · EDT nerdopolis
Quoted 74 lines · EDT Greg KH
Quoted 58 lines · nerdopolis
Hi
Background:-------------------------------------------------------------------- This issue becomes evident on VT-less kernels. As when there is no
/dev/tty0device, the console defaults to being/dev/ttyS0instead. Although this can also be replicated if booting a standard kernel with 'console=ttyS0' and ensure nothing is plugged into/dev/ttyS0.This issue prevents systemd from logging to the console.
systemd when logging to/dev/console, long story short it callsisatty()on/dev/console, and when/dev/consoleis actually/dev/ttyS0, and nothing is connected to/dev/ttyS0,isatty()fails on/dev/consoledue to an input/output error, causing systemd to not log the console output, because it rejects/dev/consoleas not being a terminal.This is noticed on a VT-less system with Plymouth. Plymouth calls the TIOCCONS ioctl on a pty device it requests, to redirect console output, and in newer versions, it displays the console logs on its own without the assistance of a VT.
This part of it works, Plymouth is able to 'see' what gets written to
/dev/console, log output from processes that write to/dev/consoledirectly (for example 'echo hi >/dev/console") do appear in plymouth's/var/log/boot.log, it is just that systemd is not writing to/dev/consolebecauseisatty()fails to report/dev/consoleas a tty device.The alternate fix in for systemds https://github.com/systemd/systemd/pull/33690[1]
is believed to be that when TIOCCONS is called on a PTY, or another terminal device, that trying to call TCGETS on/dev/consoleshould no longer result in an error.Replicating the issue:---------------------------------------------------------
This program replicates it:
-------------------------------------------------------------------------------
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>int main(void)
{ int fd; if (getuid() != 0) { printf("Must be root\n"); return 1; } fd = open ("/dev/console", O_RDONLY); if (!isatty(fd)) { printf("err on /dev/console: %s\n", strerror(errno)); } return 0; }Quoted 7 lines
-------------------------------------------------------------------------------
When the kernel console is
/dev/ttyS0and/dev/ttySOhas no device connected, it prints "err on/dev/console: Input/output error"When I strace it, the relevant line is:
ioctl(3</dev/console<char 5:1>>, TCGETS, 0x7f...)= -1 EIO (Input/output error)Do you have a proposed kernel change for this that solves this for your tests here?
thanks,
greg k-h
Quoted 12 lines
Quoted 6 lines
Hi
Sorry if this is a duplicate, I accidentally had rich text sending turned on, and did not realize until too late. Anyway, to answer the question, unfortunately I have been unable to come up with a fix on my own
Would the fix be to make
/sys/class/tty/console/activereport the terminal that TIOCCONS was called against? I am probably wrong there.Quoted 2 lines
Thanks
Hi.
So I was doing some grepping, and throwing in printk's in places, and then I realized that the ttynull driver. Turning it on, as it was disabled by default in the base config I was using from Debian, and then booting with console=ttynull causes /dev/console to work when systemd logs to it, and then Plymouth when it calls TIOCCONS on its pty, the log messages makes it to the pty. (The proper systemd status messages are now working again on VT-less systems without the need for /dev/ttyS0 to be active)
So I think I found the solution.
I think the only thing I have to ask from here is if there is a way to enable the ttynull driver by default with a config option, so I don't have to boot with console=ttynull in all my command lines
Thanks
Thanks