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.
This commit is contained in:
Andreas Kling 2018-12-07 01:26:07 +01:00
parent 829bf94de1
commit 5d7ba9640c

View file

@ -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));