]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: fix KDGKBMODE ifdef
authorKarel Zak <kzak@redhat.com>
Tue, 2 May 2023 09:36:49 +0000 (11:36 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 2 May 2023 09:56:49 +0000 (11:56 +0200)
* remove ifdef-else for KDGKBMODE

* always call KDGKBMODE for virtual console to get K_UNICODE status

* use KDGKBMODE as a fallback to detect serial line

Fixes: https://github.com/util-linux/util-linux/issues/2185
Suggested-by: Marcos Mello
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/sulogin.c

index e19a3b8b67031c8b04a2ae4e8a16ad94394f5c4a..98147509c369e59dd69dec39fe1bfe2c862c18a5 100644 (file)
@@ -108,7 +108,7 @@ static void tcinit(struct console *con)
        struct termios *tio = &con->tio;
        const int fd = con->fd;
 #if defined(TIOCGSERIAL)
-       struct serial_struct serinfo;
+       struct serial_struct serinfo = { .flags = 0 };
 #endif
 #ifdef USE_PLYMOUTH_SUPPORT
        struct termios lock;
@@ -132,18 +132,18 @@ static void tcinit(struct console *con)
        errno = 0;
 #endif
 
-#if defined(TIOCGSERIAL)
+#ifdef TIOCGSERIAL
        if (ioctl(fd, TIOCGSERIAL,  &serinfo) >= 0)
                con->flags |= CON_SERIAL;
        errno = 0;
-#else
-# if defined(KDGKBMODE)
-       if (ioctl(fd, KDGKBMODE, &mode) < 0)
+#endif
+
+#ifdef KDGKBMODE
+       if (!(con->flags & CON_SERIAL)
+           && ioctl(fd, KDGKBMODE, &mode) < 0)
                con->flags |= CON_SERIAL;
        errno = 0;
-# endif
 #endif
-
        if (tcgetattr(fd, tio) < 0) {
                int saveno = errno;
 #if defined(KDGKBMODE) || defined(TIOCGSERIAL)