summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-12-07 01:26:07 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-12-07 01:26:07 +0100
commit5d7ba9640c215c52fe5fe955fad18d7fe0ca293a (patch)
treedd709a41122ec89970279f9b7a8b368c89836ffa /Userland
parent829bf94de11206ea9dd59d144661f0314e4a0421 (diff)
downloadserenity-5d7ba9640c215c52fe5fe955fad18d7fe0ca293a.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/sh.cpp6
1 files changed, 6 insertions, 0 deletions
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 <string.h>
#include <unistd.h>
#include <fcntl.h>
+#include <termios.h>
#include <sys/mman.h>
#include <sys/utsname.h>
#include <AK/FileSystemPath.h>
@@ -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));