From 5d7ba9640c215c52fe5fe955fad18d7fe0ca293a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 7 Dec 2018 01:26:07 +0100 Subject: [PATCH] sh: Restore termios after a child process exits. This avoids the annoying situation that occurs when a spawned process messes with the termios and then doesn't exit cleanly. --- Userland/sh.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 2f79c93ffd..6e5884c2fa 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -291,6 +292,9 @@ static int runcmd(char* cmd) return 0; } + struct termios trm; + tcgetattr(0, &trm); + pid_t child = fork(); if (!child) { setpgid(0, 0); @@ -318,6 +322,8 @@ static int runcmd(char* cmd) // Is the terminal controlling pgrp really still the PGID of the dead process? tcsetpgrp(0, getpid()); + tcsetattr(0, TCSANOW, &trm); + if (WIFEXITED(wstatus)) { if (WEXITSTATUS(wstatus) != 0) printf("Exited with status %d\n", WEXITSTATUS(wstatus));