]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: use getttynam() if available
authorLudwig Nussel <ludwig.nussel@suse.de>
Thu, 21 Oct 2021 13:00:59 +0000 (15:00 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 25 Oct 2021 08:32:25 +0000 (10:32 +0200)
/etc/ttys seems to be a rather archaic concept that is not meant to
exist on Linux. Nevertheless it does. glibc has getttynam() which
correctly parses /etc/ttys. So let's give it a try before falling back
to the built in defaults. One can set the terminal type for a
specific tty using e.g.:

echo 'ttyS0 "" xterm' > /etc/ttys

[kzak@redhat.com: - improve configure.ac part
                  - log error on failed strdup()]

Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
term-utils/agetty.c

index 60e63592bd6be0e7379386f0a0095ca7ff0307ea..edd29cbb4311a3a832f8d0968d5be9ef77d573a1 100644 (file)
@@ -535,6 +535,7 @@ AC_CHECK_FUNCS([ \
        getrandom \
        getrlimit \
        getsgnam \
+       getttynam \
        inotify_init \
        jrand48 \
        lchown \
index d072d64d3a51e0c73e68e939e030c32f6e2b7c3a..55d3734613912dcc8f070343a38c20793bc2b8fe 100644 (file)
 # include <sys/param.h>
 #endif
 
+#ifdef HAVE_GETTTYNAM
+# include <ttyent.h>
+#endif
+
 #if defined(__FreeBSD_kernel__)
 # include <pty.h>
 # ifdef HAVE_UTMP_H
@@ -1160,6 +1164,18 @@ static void open_tty(char *tty, struct termios *tp, struct options *op)
        if (tcgetattr(STDIN_FILENO, tp) < 0)
                log_err(_("%s: failed to get terminal attributes: %m"), tty);
 
+#ifdef HAVE_GETTTYNAM
+       if (!op->term) {
+               struct ttyent *ent = getttynam(tty);
+               /* a bit nasty as it's never freed */
+               if (ent && ent->ty_type) {
+                       op->term = strdup(ent->ty_type);
+                       if (!op->term)
+                               log_err(_("failed to allocate memory: %m"));
+               }
+       }
+#endif
+
 #if defined (__s390__) || defined (__s390x__)
        if (!op->term) {
                /*