All of lore.kernel.org
 help / color / mirror / Atom feed
From: nerdopolis <bluescreen_avenger@verizon.net>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [Resend/Correction] When /dev/console is a disconnected /dev/ttyS0, TCGETS on /dev/console results in EIO (Even if TIOCCONS is called on a PTY)
Date: Fri, 12 Jul 2024 13:15:48 -0400	[thread overview]
Message-ID: <3245549.5fSG56mABF@nerdopolis2> (raw)
In-Reply-To: 3245549.5fSG56mABF.ref@nerdopolis2

Hi

I am resending as I realized I sent in Rich Text instead of Plain Text.
I am sorry if any of you got this duplicate email

Background:--------------------------------------------------------------------
This issue becomes evident on VT-less kernels. As when there is no /dev/tty0
device, the console defaults to being /dev/ttyS0 instead. 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 calls isatty() on
/dev/console, and when /dev/console is actually /dev/ttyS0, and nothing is
connected to /dev/ttyS0, isatty() fails on /dev/console due to an input/output
error, causing systemd to not log the console output, because it rejects
/dev/console as 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/console directly
(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/console
because isatty() fails to report /dev/console as a tty device.


The alternate fix in for systemds https://github.com/systemd/systemd/pull/33690
is believed to be that when TIOCCONS is called on a PTY, or another terminal
device, that trying to call TCGETS on /dev/console should 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;
}

-------------------------------------------------------------------------------

When the kernel console is /dev/ttyS0 and /dev/ttySO has 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)


I have not been able to come up with a proposed fix

Thanks



           reply	other threads:[~2024-07-12 18:06 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <3245549.5fSG56mABF.ref@nerdopolis2>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3245549.5fSG56mABF@nerdopolis2 \
    --to=bluescreen_avenger@verizon.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.