Skip to content

Commit

Permalink
sh: Restore termios after a child process exits.
Browse files Browse the repository at this point in the history
This avoids the annoying situation that occurs when a spawned process
messes with the termios and then doesn't exit cleanly.
  • Loading branch information
awesomekling committed Dec 7, 2018
1 parent 829bf94 commit 5d7ba96
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Userland/sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 5d7ba96

Please sign in to comment.