]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: use get_terminal_default_type()
authorKarel Zak <kzak@redhat.com>
Mon, 29 May 2023 13:11:48 +0000 (15:11 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 29 May 2023 13:11:48 +0000 (15:11 +0200)
Let's reuse the way how agetty initializes $TERM.

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/sulogin.c

index 45a558d3eaf2adfda142d64b8d5570faf51d6a2b..b76698561cf67c3927f884109553bb1a36016c23 100644 (file)
@@ -270,23 +270,21 @@ static void tcfinal(struct console *con)
 {
        struct termios *tio = &con->tio;
        const int fd = con->fd;
+       char *term, *ttyname = NULL;
 
-       if (con->flags & CON_EIO)
-               return;
-       if ((con->flags & CON_SERIAL) == 0) {
-               xsetenv("TERM", "linux", 0);
-               return;
+       if (con->tty)
+               ttyname = strncmp(con->tty, "/dev/", 5) == 0 ?
+                                       con->tty + 5 : con->tty;
+
+       term = get_terminal_default_type(ttyname, con->flags & CON_SERIAL);
+       if (term) {
+               xsetenv("TERM", term, 0);
+               free(term);
        }
-       if (con->flags & CON_NOTTY) {
-               xsetenv("TERM", "dumb", 0);
+
+       if (!(con->flags & CON_SERIAL) || (con->flags & CON_NOTTY))
                return;
-       }
 
-#if defined (__s390__) || defined (__s390x__)
-       xsetenv("TERM", "dumb", 0);
-#else
-       xsetenv("TERM", "vt102", 0);
-#endif
        tio->c_iflag |= (IXON | IXOFF);
        tio->c_lflag |= (ICANON | ISIG | ECHO|ECHOE|ECHOK|ECHOKE);
        tio->c_oflag |= OPOST;