agetty: fix stdin conversion to tty name [BZ#2326710]

This commit is contained in:
Karel Zak 2026-01-28 11:54:02 +01:00
commit ac7d4ef0e2

View file

@ -0,0 +1,39 @@
From 5bb099a5d86a26dcac5d32b1c75e6d9f84b298bf Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Mon, 24 Feb 2025 13:37:04 +0100
Subject: agetty: fix stdin conversion to tty name
Addresses: https://github.com/util-linux/util-linux/issues/3304
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit bd6c104f931329ce6fbc5a1250c8c80a1d8223ee)
(cherry picked from commit c69353a5e03779b4840f260ba52a7d2bb7b8943c)
---
term-utils/agetty.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index a3823137d..34a39a51b 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -928,11 +928,15 @@ static void parse_args(int argc, char **argv, struct options *op)
/* resolve the tty path in case it was provided as stdin */
if (strcmp(op->tty, "-") == 0) {
+ int fd;
+ const char *name = op->tty;
+
op->tty_is_stdin = 1;
- int fd = get_terminal_name(NULL, &op->tty, NULL);
- if (fd < 0) {
+ fd = get_terminal_name(NULL, &name, NULL);
+ if (fd >= 0)
+ op->tty = name; /* set real device name */
+ else
log_warn(_("could not get terminal name: %d"), fd);
- }
}
/* On virtual console remember the line which is used for */
--
2.52.0