From df718b8ab8f0451d026c33d81c1c3cddbed04925 Mon Sep 17 00:00:00 2001
From: Andrew Eikum <aeikum@codeweavers.com>
Date: Tue, 17 Nov 2015 09:41:43 -0600
Subject: [PATCH] kernel32: Always uninitialize the terminal for the console
 shell process.

The terminal raw IO check and the console shell process check are used
separately to initialize the terminal in different ways. However, if
either check fails during uninitialization, then no uninitialization
will occur at all and modified terminfo settings will remain instead of
being restored. We should check each condition individually and
uninitialize each part as required.

Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 dlls/kernel32/console.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index 363e763472b..51d6e60798a 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -211,15 +211,18 @@ static BOOL put_console_into_raw_mode(int fd)
 static BOOL restore_console_mode(HANDLE hin)
 {
     int         fd;
-    BOOL        ret;
+    BOOL        ret = TRUE;
+
+    if (S_termios_raw)
+    {
+        if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
+        ret = tcsetattr(fd, TCSANOW, &S_termios) >= 0;
+        close(fd);
+    }
+
+    if (RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == KERNEL32_CONSOLE_SHELL)
+        TERM_Exit();
 
-    if (!S_termios_raw ||
-        RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != KERNEL32_CONSOLE_SHELL)
-        return TRUE;
-    if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
-    ret = tcsetattr(fd, TCSANOW, &S_termios) >= 0;
-    close(fd);
-    TERM_Exit();
     return ret;
 }
 
-- 
GitLab